Using the github webhooks, I would like to be able to pull any changes to a remote development server. At the moment, when in the appropriate directory, git pull
gets any changes that need to be made. However, I can’t figure out how to call that function from within Python. I have tried the following:
JavaScript
x
4
1
import subprocess
2
process = subprocess.Popen("git pull", stdout=subprocess.PIPE)
3
output = process.communicate()[0]
4
But this results in the following error
JavaScript
1
8
1
Traceback (most recent call last):
2
File "<stdin>", line 1, in <module>
3
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
4
errread, errwrite)
5
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
6
raise child_exception
7
OSError: [Errno 2] No such file or directory
8
Is there a way that I can call this bash command from within Python?
Advertisement
Answer
Have you considered using GitPython? It’s designed to handle all this nonsense for you.
JavaScript
1
5
1
import git
2
3
g = git.cmd.Git(git_dir)
4
g.pull()
5