Wednesday, November 18, 2009

Mercurial installation and remote server interaction by hg-login

I want to have mercurial on my machine, but I also want to have "central repository" for continuous integration builds. I chosen mercurial because it is fast (like git), and it has good support in NetBeans (at least I heard it has ;)).
To push/pull changes to/from server, I use hg-login. Ssh is also necessary. Ok, so here are the steps:
1. Install mercurial on both client and server.
apt-get install mercurial
2. Create user mercurial on the server, and disable his shell.
sudo adduser mercurial
Edit /etc/shadow and set his password to "*".
3. Go to server (ssh will suffice) and switch to user mercurial.
sudo su - mercurial
4. Go to /home/mercurial and create repositories directory.
cd /home/mercurial
mkdir repositories
5. Create file hg-login in /home/mercurial. Copy script there. Script can be found on http://mercurial.selenic.com/wiki/HgLogin
mcedit hg-login
It can be necessary to change the script. In my case I needed to change /usr/local/bin/hg to /usr/bin/hg. Change to where your hg command is located.
6. Go back to client machine. Generate ssh keys pair for yourself.
ssh-keygen
Add private key to your ssh agent.
ssh-add
This way when you connect by ssh from client, you are automatically authenticated.
7. Go to server again. In /home/mercurial/.ssh create file authorized_keys.
cd /home/mercurial/.ssh
touch authorized_keys
In this file put line:
command="/home/mercurial/hg-login franek",no-port-forwarding,no-X11-forwarding,no-agent-forwarding [key]
franek is user name. Replace [key] with content of your .ssh/id_rsa.pub file from client. Put whole content there (with ssh-rsa in the beginning and <user>@<host> at the end).
8. Create repository in /home/mercurial/repositories/.
cd /home/mercurial/repositories
mkdir myapplication
cd myapplication
hg init
9. Allow franek to access myapplication repository. In /home/mercurial/repositories create file myapplication.allow. In this file list users who has to have access to myapplication repository. In this case franek, so the file looks like this:
franek
10. On client machine, go to directory where your application is: cd <yourdir>/myapplication
11. Create local mercurial repository.
hg init
12. Add all what is in /myapplication directory to local repository.
hg add
13. Commit added files.
hg commit
You'll need to edit commit comment.
14. Push changes to remote repository.
hg push ssh://mercurial@yourserver/myapplication
While creating this recipe, hg-login site was very helpful.
As I mentioned before, I chosen mercurial because of Netbeans. But I don't find Netbeans support of mercurial satisfactory. I am used to eclipse and it's great support for CVS. In eclipse, if there are some changes in CVS and I don't have them (incoming changes), I can see what has changed (file by file diff) before I update my code. I failed to do this in Netbeans with mercurial.

1 comment:

Anonymous said...

you have a nice site.thanks for sharing this site. various kinds of ebooks are available here

http://feboook.blogspot.com