Re: share Mercurial repo's in user home directory

From: Norman Gray <gray_at_nxg.name>
Date: Fri, 22 Oct 2021 09:40:57 UTC
Dale, hello.

On 22 Oct 2021, at 0:09, Dale Scott wrote:

> This is not directly related to FreeBSD....  is it possible to share a Mercurial repository with remote users simply by putting it in a user directory and the remote users specifying the ssh protocol in their hg clone, pull, push... commands?

Yes, this works fine.  I do this in a couple of different variants.

>  I successfully do this now with git for a small number of users. I created a new system user and put headless git repos in the new user's home directory, then added a public ssh key for each developer to the new user's authorized_keys file. Remote users access the git repos in the home directory by simply using the ssh syntax with git clone, pull and push (and authenticate using their private key).
>
>  Does this also work with Mercurial?

Do you mean a user 'hg', say, which has in its home directory user1/repo1, user1/repo2, user2/repo1, and so on?  You'd clone those with

    % hg clone ssh://hg@myhost/user1/repo1

which would result in a directory `repo1/` on the client user's machine, with that URI retained as the default remote repo for pull and push and friends.  The one mild gotcha with that syntax is that the directory path is relative to the home directory of the connecting user 'hg' (as you'd expect), so that if the repos were for some reason elsewhere, you'd specify this with ssh://hg@myhost//path/to/repo, with an extra slash indicating the root directory.

You can either do

    % cd ~hg/user1/repo1
    % hg init

and push to the above URI, or you can simply copy the .hg/ from an existing repo into place (as you'd expect).  That is: there are no surprises here, and all of the state in a repo is indeed contained in the .hg file at the root.

The final remark is that you should probably have this remote repo as a 'publishing' repo (which is what happens by default when you do `hg init`).  When you push local revisions to a publishing repo, they are changed from 'draft' to 'public' phase.

One of the nice things about Mercurial is that 'as you'd expect' is a phrase that comes up a lot.

Best wishes,

Norman


-- 
Norman Gray  :  https://nxg.me.uk