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

mercurial

Solution

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.

Problem

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?

Original source