diff options
author | Guido Günther <agx@sigxcpu.org> | 2013-06-29 13:06:43 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2013-06-29 13:17:13 +0200 |
commit | 9af186879956d16f4916e8fa8c29f18706958d04 (patch) | |
tree | 97925e92555f462e1f79793820b450fae31d511e /gbp | |
parent | 2718b5f593b1e37a3658ebb0993aeca17f2a861a (diff) |
gbp.git.Repository.get_branch(): use _git_command
instead of the deprecated _git_inout and clarify the return codes and
exceptions raised.
Diffstat (limited to 'gbp')
-rw-r--r-- | gbp/git/repository.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 9365d93..9a0256b 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -301,8 +301,10 @@ class GitRepository(object): """ On what branch is the current working copy - @return: current branch + @return: current branch or C{None} in an empty repo @rtype: C{str} + @raises GitRepositoryError: if HEAD is not a symbolic ref + (e.g. when in detached HEAD state) """ out, dummy, ret = self._git_inout('symbolic-ref', [ 'HEAD' ], capture_stderr=True) @@ -310,12 +312,16 @@ class GitRepository(object): # We don't append stderr since # "fatal: ref HEAD is not a symbolic ref" confuses people raise GitRepositoryError("Currently not on a branch") - ref = out.split('\n')[0] + # Check if ref really exists - failed = self._git_getoutput('show-ref', [ ref ])[1] - if not failed: - return ref[11:] # strip /refs/heads + try: + self._git_command('show-ref', [ ref ]) + branch = ref[11:] # strip /refs/heads + except GitRepositoryError: + branch = None # empty repo + return branch + def has_branch(self, branch, remote=False): """ |