tags:

views:

1112

answers:

3

Hi, all.

I used mercurial in a personal project, and I have been typing my username and password everytime I want to push something up to the server.

I have tried to add the following in the .hgrc file in my home dir, but it seems to be ignored at all.

[ui]
username = MY_USER_NAME
password = MY_PASSWORD

Please teach me how to do this in the right way, thanks in advance.

+6  A: 
Chris McCauley
Mine is similar to yours. My repository is on Google Code, I saved the auto-generated password with my username in ~/.hgrc but it doesn't work.
Satoru.Logic
Satoru, Chris is not talking about mercurial, but about ssh: ssh can be set up so that you don't have to identify yourself using a password (as described e.g. here: http://www.debian-administration.org/articles/152).
Tomislav Nakic-Alfirevic
@Chris, you're missing some `<>`
tonfa
@Tomislav - Thanks for the comment it made my realise that I could have been more clear. I'm talking about a pretty standard usage scenario for Mercurial.
Chris McCauley
Method 2 is really the *only* way to handle things securely and maintain user-level permissions on the remote system.
Peter Rowell
+3  A: 

A simple hack is to add username and password to the push url in your project's .hg/hgrc file:

[paths]
default = http://username:[email protected]/myproject

(Note that in this way you store the password in plain text)

If you're working on several projects under the same domain, you might want to add a rewrite rule in your ~/.hgrc file, to avoid repeating this for all projects:

[rewrite]
http.//mydomain.com = http://username:[email protected]

Again, since the password is stored in plain text, I usually store just my username.

If you're working under Gnome, I explain how to integrate Mercurial and the Gnome Keyring here:

http://aloiroberto.wordpress.com/2009/09/16/mercurial-gnome-keyring-integration/

Roberto Aloi
I have downloaded the extension, however, when I tried to make a push the password prompt refuses to let me pass :( May be I have done it the wrong way. I have never used Gnome Keyring before. Thank you all the same.
Satoru.Logic
You might want to use --debug and --verbose options for hg push to see what is going wrong...
Roberto Aloi
+9  A: 

You can make an auth section in your .hgrc, like so:

[auth]
bb1.prefix = https://bitbucket.org/foo/
bb1.username = foo
bb1.password = foo_passwd

(The ‘bb1’ part is an arbitrary identifier and is used to match prefix with username and password.)

See for more details: http://hgtip.com/tips/advanced/2009-10-01-configuring-user-auth-https/

Laurens Holst
Thanks, Laurens. This works for me.
Satoru.Logic
Why doesn't this work when the server is: ssh://HGSERVER ?the "ssh://username:password@HGSERVER" format doesn't work either..
Oren