Created
May 31, 2012 01:33
-
-
Save nathania/2840185 to your computer and use it in GitHub Desktop.
Execute git command from Python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE | |
from os import path | |
git_command = ['/usr/bin/git', 'status'] | |
repository = path.dirname('/path/to/dir/') | |
git_query = Popen(git_command, cwd=repository, stdout=PIPE, stderr=PIPE) | |
(git_status, error) = git_query.communicate() | |
if git_query.poll() == 0: | |
# Do stuff |
Thanks!
This was really helpful. I could create a script to completed push the code if there is any untracked files in my local with this hint
Hello Nathania,
I made a git command in python, http://goo.gl/JUHJjc would you like to have some comments on it, I am going to do a version using gitPython API which i discovered after I was all done with the one using subprocess, however still debating which approach is better !
The link doesn't work anymore, could you please provide another one?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this !