Executing python subprocess via git hook

Posted by aljesco on Stack Overflow See other posts from Stack Overflow or by aljesco
Published on 2012-06-07T16:18:46Z Indexed on 2012/06/07 16:40 UTC
Read the original article Hit count: 262

Filed under:
|
|
|

I'm running Gitolite over the Git repository and I have post-receive hook there written in Python. I need to execute "git" command at git repository directory. There are few lines of code:

proc = subprocess.Popen(['git', 'log', '-n1'], cwd='/home/git/repos/testing.git' stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc.communicate()

After I make new commit and push to repository, scripts executes and says

fatal: Not a git repository: '.'

If I run

proc = subprocess.Popen(['pwd'], cwd='/home/git/repos/testing.git' stdout=subprocess.PIPE, stderr=subprocess.PIPE)

it says, as expected, correct path to git repository (/home/git/repos/testing.git)

If I run this script manually from bash, it works correct and show correct output of "git log". What I'm doing wrong?

© Stack Overflow or respective owner

Related posts about python

Related posts about git