Search code examples
mercurialhookmercurial-hook

Mercurial changegroup hook is being passed wrong HG_URL


I've setup a simple changegroup hook for my Mercurial repositories to email the set of changes to interested users. I'd like to use a single script for every repository I manage, and I would also like to identify the repository the changegroup came from. According to the Mercurial Hooks documentation, the environment variable HG_URL is available for this purpose. However, I am not getting what I'm expecting from this variable:

expected:

https://repo01/hg/project

actual:

remote:https::rnideffer

Why is this the URL, and how do I get what I expected into the changegroup hook?


Solution

  • The changegroup hook can't always tell the remote URL being used. From the Hooks chapter of the Mercurial Book:

    When possible, Mercurial will tell a hook the location of the “far side” of an activity that transfers changeset data between repositories. This is provided by Mercurial in a Python parameter named url, or an environment variable named HG_URL. No comments

    This information is not always known. If a hook is invoked in a repository that is being served via http or ssh, Mercurial cannot tell where the remote repository is, but it may know where the client is connecting from. In such cases, the URL will take one of the following forms: No comments

    remote:ssh:1.2.3.4—remote ssh client, at the IP address 1.2.3.4. No comments

    remote:http:1.2.3.4—remote http client, at the IP address 1.2.3.4. If the client is using SSL, this will be of the form remote:https:1.2.3.4. No comments

    So you're being told they're pushing via https from a machine named rnideffer.

    Have you considered using the notify extension? It ships with mercurial, does pretty much exactly what you're describing, and can be provided with the URL prefix necessary to turn repo names into the URLs you want.