We're switching from Subversion to Mercurial in our corporate environment. There will be a central repository that is accessible via HTTPS with basic HTTP authentication.

Now I'm curious whether it's possible to force specific usernames for commits? I'm talking about the usernames that can be set in .hgrc like this

username = John Doe <john.doe@mycompany.com>

and that are visible in the log messages.

Because this file is placed on each developer's machine it's outside of the administrator's control.

This wouldn't be a problem because we trust our internal developers but externals (freelancers) will also have access to at least some repositories. We definitively don't want them to checkin under different names.

It would be great if the username can be bound/forced to the HTTP username. For example if John pushes his changes to the URL https://john@mycompany.com/hg/project1 then the usernames of all commits will be set to John Doe <john.doe@mycompany.com.

Is this possible?

  • We're now using the commitsigs (bitbucket.org/mg/commitsigs) extensions to sign every commit with a GPG key. The central repository server doesn't accept any push that contains unsigned change sets. That way we can make sure of the correct identities of the authors.
    – Sven
    Feb 11, 2011 at 8:03

2 Answers 2


You can enforce the usernames at the server side, at push time. I.e. for your freelancers it might be feasible to only let them push changes that contain some pre-approved username (this can somewhat restrict other nice features of Mercurial, i.e. that people can share their changes with each other before pushing). You might also just have a complete list of pre-approved usernames on the central server.

All this can be done with a pretxnchangegroup hook.

  • 2
    Can you please provide an example?
    – Sven
    Feb 4, 2011 at 12:30

As djc mentioned, you can use a pretxnchangegroup hook. The documentation for enforcing commit policy on your central repo is found on the EnsureCommitPolicy wiki page in the Mercurial docs.

This may create other problems since the users won't discover the issue until they try to push back up to the "main" repository which has the hook installed. In this case they would have to strip all the revisions from their repo and re-apply them with a new username.

A better option, IMO, would be to just not allow your freelancers to have access to the main repositories. They can send the changesets to your main developers who then massage the patches and put them in the repository themselves.

If you need to just fix an existing problem, see "Can I change the username on a mercurial changeset" on stackoverflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.