From 76612cbd8d6888e2d831806ef4f4ca303199f016 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Wed, 26 Oct 2011 19:47:23 +0200 Subject: GitRepository: speed up get_branch() and make it more robust by using 'git symbolic-ref' --- gbp/git.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gbp/git.py b/gbp/git.py index 30417f5..d8ba6e8 100644 --- a/gbp/git.py +++ b/gbp/git.py @@ -361,9 +361,12 @@ class GitRepository(object): @return: current branch @rtype: string """ - for line in self.__git_getoutput('branch', [ '--no-color' ])[0]: - if line.startswith('*'): - return line.split(' ', 1)[1].strip() + out, dummy = self.__git_getoutput('symbolic-ref', [ 'HEAD' ]) + ref = out[0][:-1] + # Check if ref really exists + failed = self.__git_getoutput('show-ref', [ ref ])[1] + if not failed: + return ref[11:] # strip /refs/heads def get_merge_branch(self, branch): """ -- cgit v1.2.3