Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def get_revision(path=None):
"""
Return the revision identifier of the last commit in a git or svn source pool.
"""
if path is None:
path = "."
import os, re, subprocess
revision = None
os.chdir(path)
if os.path.exists('.git'):
# get git revision
output = subprocess.Popen(["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE).communicate()[0]
revision = output.strip()
elif os.path.exists('.svn'):
# get svn revision
REVISION_RE = re.compile('(\d+).*', re.M)
subprocess.Popen(["svn", "up", "-q"], stdout=None)
output = subprocess.Popen(["svnversion"], stdout=subprocess.PIPE).communicate()[0]
match = REVISION_RE.search(output)
if match:
revision = match.group(1)
return revision
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.