Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am setting up a Mercurial repository layout, and have a directory with all the repositories in it.


As SSH is the only way I know of to access Mercurial remotely, I know howto setup public key authentication, and setup the appropriate environment variables. What I want to know is there any way to set the repository root so users can just type


As opposed to having to do this:


I want something like svn's -r option.

share|improve this question
up vote 1 down vote accepted

That depends on whether users are logging in as themselves, or as a dedicated Mercurial user. If you create a dedicated Mercurial user, and authenticate by key, then you can set the home directory of the Mercurial user to be /var/vcroot/link, and the single slash after connection-name will be relative to that.

Note that your second example will be nonfunctional due to a missing slash for that same reason (i.e. it should be ssh://connection-name//var/vcroot/link/repository-name).

If you have users logging in as themselves, then each user will have to create a symlink into $HOME for that to work. Alternately, you can make /hg a symlink to /var/vcroot/link, and use ssh://connection-name//hg/repository-name, which is probably short enough to be convenient.

share|improve this answer
Don't needlessly double slashes, please. No need for the double slash before "hg" there. – Jürgen A. Erhard Jan 18 '11 at 14:39
Jae is incorrect. The double-slashes in "//hg" are absolutely required (at least as of Mercurial 1.6.4, just tested) to match my example, as a single slash will start the pathing at your home directory, not the filesystem root. – Zed Jun 15 '11 at 16:56
I sit corrected (I can't remember what fuzz I had on my brain at the time, because it's obvious how wrong my comment was, and I wonder why I didn't see it) – Jürgen A. Erhard Jun 16 '11 at 12:15

Responding to this part of your question:

As SSH is the only way I know of to access Mercurial remotely

You can also access mercurial remotely over http/https.

share|improve this answer

I solved this by creating a shell script /usr/local/bin/hg:

cd /var/vcroot/link
/usr/bin/hg $*

If you then remotely run 'hg init ssh://connection-name/repository-name', the repository is created in /var/vcroot/link/repository-name, and cloning and pushing work as expected. I haven't tested anything else though.

share|improve this answer

I like the idea of changing the home directory to /var/vcroot/link, but if they log in with different user names, then that wont work.

You can instead suggest to your users that they setup a special scheme for your server. The standard schemes extension lets you do that. They should add

schemes =

server = ssh://connection-name//var/vcroot/link/

to a config file and then they can do

$ hg clone server://repository-name

instead of

$ hg clone ssh://connection-name//var/vcroot/link/repository-name

If you have control over their machines, then you can even enable and configure the extension in the /etc/mercurial/hgrc file to make it a system-wide setting.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.