I have some basic python script inside my git repo. First I test some git command in my repo:
$ git ls-remote --heads origin master
a5dd03655381fcxxxx4e759ceba7aeb6456 refs/heads/master
Now I want to execute the same command in Python:
if subprocess.call(["git", "ls-remote --heads origin master"]):
print("OK")
else:
print("Not OK")
The output is:
git: 'ls-remote --heads origin master' is not a git command. See 'git --help'.
OK
What am I missing? When I just execute ls-remote
in my python script it works:
a5dd03655381fcxxxx4e759ceba7aeb6456 HEAD
a5dd03655381fcxxxx4e759ceba7aeb6456 refs/heads/master
(I know the if statement is 'wrong/useless now').
you need to put every parameter in a separate item in the list.
import subprocess
if subprocess.call(["git", "ls-remote", "--heads", "origin", "master"]):
print("OK")
else:
print("Not OK")
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.