Wednesday, January 26, 2011

Running a simple Mercurial server (hg serve) and allowing push

I've been using mercurial (via Google Code Repository) as a simple solution for version control. The best feature is that Mercurial (hg for short) allows me to commit things to the repository that no-one else sees until I "push" them out (committing and pushing are two separate operations).

Lately I've had a need to quickly share code for an internal, non-FOSS project.  Running an internal hg server seems, at first glance, much harder than for SVN or CVS : while there is a simple "hg serve" command, the documentation is sparse, and in fact misleading.  The documentation would have you believe that hg serve is read-only, whereas it is not.  There are a few tricks required to run it as a cheap solution just for sharing between colleagues and avoiding the "oops, lost my laptop" issues.

First, run the program in daemon mode, and force it to read a config file:
hg serve -d --web-config E:\hg\config.txt


The following configuration file (config.txt in the command-line above) allows you a)  to have multiple repositories b) enables your colleagues to push changes and c) does not require an SSL connection.


[collections]
e:\hg = e:\hg


[web]
allow_push = *
push_ssl = false

Obviously, the setup is insecure, and is meant for private LANs or VPNs -- anything sensitive should use the more tedious solutions that rely on Apache and SSL.

No comments: