add util.git

This commit is contained in:
Mort Yao 2014-07-21 00:02:45 +02:00
parent cb9ccc91ab
commit 4fa150f68b

8
src/you_get/util/git.py Normal file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env python
import os
def get_head(repo_path):
"""Get (branch, commit) from HEAD of a git repo."""
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]