From e8bf96fc212225a6482fa1976ba8843e1f9a7082 Mon Sep 17 00:00:00 2001 From: Mort Yao Date: Mon, 21 Jul 2014 00:25:26 +0200 Subject: [PATCH] update util.git --- src/you_get/util/git.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/you_get/util/git.py b/src/you_get/util/git.py index 01a8ce17..6891709e 100644 --- a/src/you_get/util/git.py +++ b/src/you_get/util/git.py @@ -4,5 +4,10 @@ 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] + try: + ref = open(os.path.join(repo_path, '.git', 'HEAD'), 'r').read().strip()[5:].split('/') + branch = ref[-1] + commit = open(os.path.join(repo_path, '.git', *ref), 'r').read().strip()[:7] + return branch, commit + except: + return None