oeqa.utils.git: implement GitRepo.get_current_branch()

(From OE-Core rev: dcba2302adab47b398f1ce7d09c38828ea9ae426)

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Markus Lehtonen 2016-05-16 14:36:27 +03:00 committed by Richard Purdie
parent 6cf74643e9
commit 618a2ede75
2 changed files with 10 additions and 5 deletions

View File

@ -116,12 +116,9 @@ class BuildPerfTestResult(unittest.TextTestResult):
if not rev:
rev = self.repo.rev_parse('HEAD')
if not branch:
try:
# Strip 11 chars, i.e. 'refs/heads' from the beginning
branch = self.repo.run_cmd(['symbolic-ref', 'HEAD'])[11:]
except GitError:
branch = self.repo.get_current_branch()
if not branch:
log.debug('Currently on detached HEAD')
branch = None
return str(rev), str(branch)
def addSuccess(self, test):

View File

@ -46,4 +46,12 @@ class GitRepo(object):
# Revision does not exist
return None
def get_current_branch(self):
"""Get current branch"""
try:
# Strip 11 chars, i.e. 'refs/heads' from the beginning
return self.run_cmd(['symbolic-ref', 'HEAD'])[11:]
except GitError:
return None