GitRepository: handle case when not on any branch
authorGuido Günther <agx@sigxcpu.org>
Mon, 7 Nov 2011 16:37:01 +0000 (17:37 +0100)
committerGuido Günther <agx@sigxcpu.org>
Mon, 7 Nov 2011 16:37:01 +0000 (17:37 +0100)
gbp/git.py

index b533116..95876f9 100644 (file)
@@ -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]