Search code examples
mercurialmercurial-hook

Mercurial hook to test that username is valid when pushing to repository


I have a "central" repository that I want to ensure that no one pushes changes in to with a wrong user name.

But I can not figure out how to make a hook that tests the user name against a positive list. I have found in the Mercurial API a

ctx.user()
call that seems to be what I want to test my positive list against.

Also the hook could be a precommit hook that is distributed as part of the repository clone or it could be a hook on the central repository as a pre-incoming or something like that.

Any help or pointers would be greatly appreciated.


Solution

  • Thanks for the examples dls.

    In the end I decided to run it as a pretxnchangegroup hook and then use the hg log and grep to test the author field of the commits:

    [hooks]
    pretxnchangegroup.usercheck = hg log --template '{author}\n' -r \ 
    $HG_NODE: | grep -qe 'user1\|user2\|etc'
    

    It does of course not provide a very good feedback other than usercheck failed. But I think it is good enough for now.