Merge "be more rigorous about parsing the branch list"

This commit is contained in:
Jenkins 2017-02-06 14:59:16 +00:00 committed by Gerrit Code Review
commit c3807bb2cf

View File

@ -175,10 +175,26 @@ def get_branches(workdir, repo):
cwd=os.path.join(workdir, repo),
stderr=subprocess.STDOUT,
).strip()
return [
branch
for branch in output.split()
]
# Example output:
# * (no branch)
# master
# stable/mitaka
# stable/newton
# stable/ocata
# remotes/origin/HEAD -> origin/master
# remotes/origin/master
# remotes/origin/stable/mitaka
# remotes/origin/stable/newton
# remotes/origin/stable/ocata
results = []
for line in output.splitlines():
branch = line.strip().lstrip('*').strip()
if branch.startswith('('):
continue
if '->' in branch:
continue
results.append(branch)
return results
except subprocess.CalledProcessError as e:
print('ERROR failed to retrieve list of branches: %s [%s]' %
(e, e.output.strip()))