update util.git

This commit is contained in:
Mort Yao 2014-07-21 00:25:26 +02:00
parent 4fa150f68b
commit e8bf96fc21

View File

@ -4,5 +4,10 @@ import os
def get_head(repo_path): def get_head(repo_path):
"""Get (branch, commit) from HEAD of a git repo.""" """Get (branch, commit) from HEAD of a git repo."""
try:
ref = open(os.path.join(repo_path, '.git', 'HEAD'), 'r').read().strip()[5:].split('/') ref = open(os.path.join(repo_path, '.git', 'HEAD'), 'r').read().strip()[5:].split('/')
return ref[-1], open(os.path.join(repo_path, '.git', *ref), 'r').read().strip()[:7] branch = ref[-1]
commit = open(os.path.join(repo_path, '.git', *ref), 'r').read().strip()[:7]
return branch, commit
except:
return None