This snippet of code works on most Unix I have access to (Linux, Solaris, AIX) as well as on Windows 7/ Server 2008 R2 and up that I've used to get the output of git log:
from subprocess import Popen, PIPE
import platform
cmd = ["git", "--no-pager"]
if platform.system() == "Windows":
cmd.append("--work-tree=/path/to/working/copy")
cmd.extend(["log", "--pretty=format:\"%cd %h\"", "--date=short", "--", "/path/to/working/copy/filename/to/check"])
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
proc.wait()
f = proc.stdout
some_stuff = f.read()
f.close()
However, on Windows XP using msysgit I'm not getting any value to the some_stuff variable, which is weird since running the generated command works on the command line on Windows.
Any tips on what should I do here?
After doing some research, here's what I've found:
git.cmd
instead of directly specifying git.exe
. By testing the above-mentioned, it seems that:
--work-tree
option anymore os.path.normpath()
will not work, as it will assume case-insensitivity and alter the drive letter to lowercase.
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.