Are there any easy ways to grab the git repository (on GitHub) version hash with Python code? I want to use this to handle versioning of 'dev' releases of my software on github.
-
1GutHub or Git repositories? stackoverflow.com/questions/5694389/…tMC– tMC2012-10-10 19:20:17 +00:00Commented Oct 10, 2012 at 19:20
-
Sorry it wasn't clear, I meant git repositories (I store them on github).Christopher Dorian– Christopher Dorian2012-10-10 19:24:39 +00:00Commented Oct 10, 2012 at 19:24
Add a comment
|
4 Answers
Like this ?
import subprocess
ref = subprocess.check_output("""
git 2>/dev/null show-ref | awk '/refs\/heads\/master/{print $1}'
""", shell=True)
print ref
Adapt it if you have something else than master
3 Comments
tMC
Via python. run the
git command via Popen and parse the output in python.tMC
No need to pipe it to awk. Just read
stdout from the Popen object and parse the text in Python. Python is very good as string handling!Christopher Dorian
Sorry, had to go with tMC's answer. check_output is from 2.7, I'de like backwards compatibility for now.