I am trying to make a command for git to directly email the diff,
what I have thought is to get the diff to a text file to email,
but not sure why
pr = subprocess.Popen( "git diff HEAD^ HEAD" , cwd = os.path.dirname( os.getcwd() ), shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE )
(out, error) = pr.communicate()
print "Error : " + str(error)
print "out : " + str(out)
gives error saying
Error : error: Could not access 'HEAD^'
out :
whereas I want diff in out variable to email.
You are probably not issuing the command in correct folder, where git is initialized.
Your actual problem is, that os.path.dirname
command is striping out the folder from the command os.getcwd
and you are actually running the command in parent folder. If you get rid of os.path.dirname
and just use os.getcwd
your code should work.
There are two changes to be made in the code to work . Changes are git commands inside Popen and working directory. After making the changes the code can be as given below which will work without any error
pr = subprocess.Popen(['git', 'diff', 'HEAD~1' ,'HEAD'] , cwd = os.getcwd(), shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE )
(out, error) = pr.communicate()
print "Error : " + str(error)
print "out : " + str(out)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.