aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-11-07 17:37:01 +0100
committerGuido Günther <agx@sigxcpu.org>2011-11-07 17:37:01 +0100
commit47f50cd2225f11274f12c59e896413d0279176fe (patch)
tree9864d569361742aa94a7e401aca42e3f2710edb4
parent1b15dc848f312005258c5a9bf762448acf5d9f8b (diff)
GitRepository: handle case when not on any branch
-rw-r--r--gbp/git.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/gbp/git.py b/gbp/git.py
index b5331169..95876f9b 100644
--- a/gbp/git.py
+++ b/gbp/git.py
@@ -238,7 +238,10 @@ class GitRepository(object):
@property
def branch(self):
"""The currently checked out branch"""
- return self.get_branch()
+ try:
+ return self.get_branch()
+ except GitRepositoryError:
+ return None
@property
def head(self):
@@ -284,7 +287,10 @@ class GitRepository(object):
@return: current branch
@rtype: C{str}
"""
- out, dummy = self.__git_getoutput('symbolic-ref', [ 'HEAD' ])
+ out, ret = self.__git_getoutput('symbolic-ref', [ 'HEAD' ])
+ if ret:
+ raise GitRepositoryError("Currently not on a branch")
+
ref = out[0][:-1]
# Check if ref really exists
failed = self.__git_getoutput('show-ref', [ ref ])[1]