Here, we will setup & run “Mercurial HG” locally in linux. First we install mercurial hg itself.
sudo apt-get install mercurial
Try out the mercuial to check if installation was success by :
The output should be something like this in your terminal.
Mercurial Distributed SCM (version 2.2.2) (see http://mercurial.selenic.com for more information) Copyright (C) 2005-2012 Matt Mackall and others This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
We will create a configuration files under ‘/usr/sw/mercurial’ directory(you can choose any directory) named : hgweb.config, hgweb.wsgi & hg-wsgi.conf
hgweb.config file will be like,
[web] allow_push=* push_ssl=false allow_archive=gz, zip, bz2 [collections] /usr/sw/mercurial/repo=/usr/sw/mercurial/repo
“/usr/sw/mercurial/repo=/usr/sw/mercurial/repo” tells mercurial where all our repository will be located.
Our hgweb.wsgi file should contain,
# Path to repo or hgweb config to serve (see 'hg help hgweb') config = "/usr/sw/mercurial/hgweb.config" # enable demandloading to reduce startup time from mercurial import demandimport; demandimport.enable() from mercurial.hgweb import hgweb application = hgweb(config)
hg-wsgi.conf file will be like,
WSGIScriptAlias /hg /usr/sw/mercurial/hgweb.wsgi <Directory "/usr/sw/mercurial/"> Options ExecCGI FollowSymlinks AddHandler wsgi-script .wsgi AllowOverride All Order allow,deny Allow from all AuthType Basic AuthName "Mercurial Repositories" AuthUserFile /usr/sw/mercurial/hgusers Require valid-user </Directory>
Basically this file will create a alias named ‘hg’ for all our repositories. It also defines permission, authentication type and repository access to hg users.
Adding users to mercurial
User can be added to mercurial by using ‘htpasswd’ command. The ‘-c’ option will be used to create user for first time in newly setup mercurial. For adding further users, just remove ‘-c’ option and execute the command.
sudo htpasswd -c /usr/sw/mercurial/hgusers superadmin
Provide the desired password for user named ‘superadmin’. All users credential will ge stored in “hguser” file located in “/usr/sw/mercurial/”.
To run mercurial web GUI, we should add following text to “etc/apache2/sites-available/default” and restart the server.
<VirtualHost *:80> /* commmented to increase readibility */ include /usr/sw/mercurial/hg-wsgi.conf </VirtualHost>
Now, if we enter url “http://localhost:80/hg” in browser, we should get popup asking for username and password to procced. The popup is due to line “AthType Basic” in hg-wsgi.conf file.
Creating repository can be done in few steps. First we have to make directory with project name inside path “/usr/sw/mercurial/repo/” and hg init the project directory.