Support git unicode branches
Use `gitpython` to get repository branches instead of our custom/hacky
csv parser.
With this change, we loose the output from `git branch -r` command
shown to the user under the build output.
@@ -174,51 +174,14 @@ class Backend(BaseVCS):
@property
def branches(self):
- # Only show remote branches
- retcode, stdout, _ = self.run(
- 'git',
- 'branch',
- '-r',
- record_as_success=True,
- )
- # error (or no branches found)
- if retcode != 0:
- return []
- return self.parse_branches(stdout)
-
- def parse_branches(self, data):
- """
- Parse output of git branch -r.
-
- e.g.:
-
- origin/2.0.X
- origin/HEAD -> origin/master
- origin/develop
- origin/master
- origin/release/2.0.0
- origin/release/2.1.0
- """
- clean_branches = []
- # StringIO below is expecting Unicode data, so ensure that it gets it.
- if not isinstance(data, str):
- data = str(data)
- delimiter = str(' ').encode('utf-8') if PY2 else str(' ')
- raw_branches = csv.reader(StringIO(data), delimiter=delimiter)
- for branch in raw_branches:
- branch = [f for f in branch if f not in ('', '*')]
- # Handle empty branches
- if branch:
- branch = branch[0]
- if branch.startswith('origin/'):
- verbose_name = branch.replace('origin/', '')
- if verbose_name in ['HEAD']:
- continue
- clean_branches.append(
- VCSVersion(self, branch, verbose_name))
- else:
- clean_branches.append(VCSVersion(self, branch, branch))
- return clean_branches
+ repo = git.Repo(self.working_dir)
+ versions = []
+ for branch in repo.branches:
+ verbose_name = branch.name
+ if verbose_name.startswith('origin/'):
+ verbose_name = verbose_name.replace('origin/', '')
+ versions.append(VCSVersion(self, str(branch), verbose_name))
+ return versions
@property
def commit(self):
