Configure Hg to not ask for user name and password on command line

10,820

Solution 1

You can configure your credentials in your user-wide hgrc (mercurial.ini in the user profile directory, on Windows):

[auth]
foo.prefix = example.com/path
foo.username = user
foo.password = password

Afterwards, the requests for this server will silently use the credentials provided in the hgrc file.

See the docs on hgrc for more information.


Update: After studying the TortoiseHg sources a little (the code in question being the SyncWidget.inclicked and SyncWidget.pullclicked methods in sync.py), I've found out that TortoiseHg, which does precisely what you're trying to achieve, apparently first tries the URL for the auth request, and, if it's been given, asks the user for the login and password, to rebuild a full URL (with credentials) and supply it to hg pull.

I guess you can do the same.

Solution 2

What about

hg clone https://user:password@host:port

Is such solution not workable for you?

Share:
10,820
Mot
Author by

Mot

Updated on June 04, 2022

Comments

  • Mot
    Mot about 2 years

    When I try to clone a https-authenticated Mercurial repository (e.g. from kiln), it asks me for my user name

    C:\temp\test>hg clone https://<my-login-name>.kilnhg.com/Code/Repositories/Group/test
    http authorization required
    realm: kiln
    user:
    

    We want to invoke the hg clone command from our GUI application with any URL provided by the user and ask the user on demand for the user name and password, if they are required.

    How can I configure Mercurial to invoke an arbitrary script which returns the user name/password, similar to scripts whose paths are defined in the environment variables GIT_ASKPASS or SSH_ASKPASS for Git?