Reputation: 1804
I made a python script using subprocess
that among other things pushes the committed changes into remote git repository.
The files really pushed to the remote repo but for some reason I get only the last line of the git message that appears after the push.
Here's the relevant peace of code:
p = subprocess.Popen('git push --tag origin HEAD:develop' ,stdout=subprocess.PIPE,stderr=subprocess.STDOUT')
result = p.communicate()[0]
print ("Result from GIT: " + result)
prints the following:
Result from GIT: To https://example.org/someUser/repo.git
fe4929f6..25bb62e9 HEAD -> develop
* [new tag] 1.0.1.7 -> 1.0.1.7
While the full message, which is what I get when I'm making the push from windows terminal is:
Counting objects: 25, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (23/23), done.
Writing objects: 100% (25/25), 2.18 KiB | 0 bytes/s, done.
Total 25 (delta 20), reused 0 (delta 0)
To https://example.org/someUser/repo.git
828b9e31..249be2ba HEAD -> develop
Is there a way that I can get the full message (so that I can print it in my script) and not only the last line?
Thank you
Upvotes: 0
Views: 484
Reputation: 18834
When running git, you need to add the --progress
flag.
From the git manual (run git help push
)
--progress
Progress status is reported on the standard error stream by default when it is attached to a terminal, unless -q is specified. This flag forces progress status even if the standard error stream is not directed to a terminal.
This can be integrated in your program as follows:
p = subprocess.Popen('git push --progress --tag origin HEAD:develop' ,stdout=subprocess.PIPE,stderr=subprocess.STDOUT')
result = p.communicate()[0]
print ("Result from GIT: " + result)
Notice that using this flag may make the parsing of the output of the script harder, as human readable output of git may change in future releases of git without warning. (Use --porcelain
to do the opposite of what you asked, produce machine readable output always)
Upvotes: 2