pythongitatlassian-sourcetreegitpython

sourcetree hook with python


I have a git hook, "commit-msg"

and it looks something like:

#!/bin/sh
python .git/hooks/Foo.py

Inside my Foo.py

I have:

import git
# doing some stuff based on git (evaluating latest changes)

when I commit using sourcetree if fails to run the hook ( also it does not commit )

//...
    Traceback (most recent call last):
      File ".git/hooks/Foo.py", line 2, in <module>
        import git
    ImportError: No module named git
//...

but if I commit directly from the terminal the hook works as expected.

Any suggestions to fix the commit on source tree?


Solution

  • Try to add this to your git hook file:

    export PATH=/usr/local/bin:$PATH
    

    See this SourceTree issue