2

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

/var/vcroot/link/[repository]

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

ssh://connection-name/repository-name

As opposed to having to do this:

ssh://connection-name/var/vcroot/link/repository-name

I want something like svn's -r option.

4 Answers 4

1

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.

3
  • Don't needlessly double slashes, please. No need for the double slash before "hg" there. Commented Jan 18, 2011 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
    Commented Jun 15, 2011 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) Commented Jun 16, 2011 at 12:15
1

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.

1

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

#!/bin/sh
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.

0

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

[extensions]
schemes =

[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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .