Working on the Same hg Repository

  1. 1. Problem
  2. 2. Discussion
  3. 3. Workaround

What do we do when two users need to work on the same hg repository?

Problem

By “same”, I mean the same folder in the filesystem. In the case that I encountered, I need to modify the repository on another user’s account, directly, and do the regular commits, pulls, and pushes as if I were working on my own repository.

Discussion

Usually this scenario should not happen. Whenever there are two users, each user usually has his/her own repository. Modifications contributed by the two users are merged using standard version control methods. Furthermore, the ecosystem that the repository relies on should be in a shared state, e.g. in the /opt folder, so that the users only need to take care of the repository itself.

Now, what happened is that, only the first user will be the main contributor to the repository. Moreover, the repository relies on a heavy ecosystem, which is cumbersome to setup in a new account. Yes, historically, the ecosystem is setup under the second user’s account, and not shared by the first user.

Workaround

One can always do something like following to enforce the manipulation of the repository,

1
sudo hg -u USER OPERATION

To avoid invoking the super user privilege, add writing permissions to the files in the .hg folder of the repository.

1
2
sudo find .hg -type d -exec chmod 757 {} \;
sudo find .hg -type f -exec chmod 646 {} \;

When the user commits any changes to the repository, the writing permission is required to modify the .hg files.

Then add following information to the hgrc file in the repository

1
2
3
4
[paths]
dev = PATH_TO_REPO
[ui]
username = USER <USER_EMAIL>

Then when doing push and pull, make sure to interact with the dev repository defined in the hgrc file.

1
2
hg push dev
hg pull dev

In this manner, the commits are directed to the dev path under the specified user.

Finally, in .hgrc file, add

1
2
[trusted]
users = trokita

to avoid some annoying outputs from the commandline.