Search code examples
pythonmercurialmercurial-hook

Mercurial hook precommit get repository path


I'm coding a script to check syntax of repository files.

So, I added to my .hgrc file this line :

precommit = python ~/tools/check_syntax.py

But I want get the path of repository in which I try to commit from check_syntax.py file.

Do you know a way to do that ?


Solution

  • hg root will give you the top of your current working directory. So something like:

    [hooks]
    precommit = python ~/tools/check_syntax.py $($HG root)
    

    will set the top of your current working directory as first argument of your script.