diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-10-26 19:47:23 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-10-27 19:20:17 +0200 |
commit | 76612cbd8d6888e2d831806ef4f4ca303199f016 (patch) | |
tree | 4a05357ac51549a15804d681fb43dff5b52130a1 | |
parent | 38b4f71f9ab960d2ff70e731e0895ec90e40911d (diff) |
GitRepository: speed up get_branch() and make it more robust
by using 'git symbolic-ref'
-rw-r--r-- | gbp/git.py | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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): """ |