Installing mercurial
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 :

hg --version

The output should be something like this in your terminal.

Mercurial Distributed SCM (version 2.2.2)
(see for more information)

Copyright (C) 2005-2012 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO

Mercurial configuration
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,

allow_archive=gz, zip, bz2

“/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


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/”.

Running 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

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.

Local mercurial repository

Local mercurial repository

Creating repository
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.

Leave a comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.