From 596a587847c470e44c04e0c2ea83edb33ab86c00 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Wed, 25 Nov 2009 21:08:18 -0800 Subject: [PATCH] gitcmds: Add a 'split' parameter to all_refs() Passing split=True causes all_refs() to return three separate local_branches, remote_branches, and tags lists. all_refs() now returns a single concatenated list by default. Signed-off-by: David Aguilar --- cola/gitcmds.py | 7 +++++-- cola/models/main.py | 2 +- test/test_cola_gitcmds.py | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/cola/gitcmds.py b/cola/gitcmds.py index 2fd76ff8..5dd97aa3 100644 --- a/cola/gitcmds.py +++ b/cola/gitcmds.py @@ -92,7 +92,7 @@ def for_each_ref_basename(refs): return map(lambda x: x[len(refs) + 1:], non_heads) -def all_refs(): +def all_refs(split=False): """Return a tuple of (local branches, remote branches, tags).""" local_branches = [] remote_branches = [] @@ -106,7 +106,10 @@ def all_refs(): if ref.startswith(prefix) and not ref.endswith('/HEAD'): dst.append(ref[prefix_len:]) continue - return local_branches, remote_branches, tags + if split: + return local_branches, remote_branches, tags + else: + return local_branches + remote_branches + tags def tracked_branch(branch=None): diff --git a/cola/models/main.py b/cola/models/main.py index fe28e7d1..51dd72e2 100644 --- a/cola/models/main.py +++ b/cola/models/main.py @@ -305,7 +305,7 @@ class MainModel(ObservableModel): self.set_unstaged(self.modified + self.unmerged + self.untracked) self.set_remotes(self.git.remote().splitlines()) - local_branches, remote_branches, tags = gitcmds.all_refs() + local_branches, remote_branches, tags = gitcmds.all_refs(split=True) self.set_local_branches(local_branches) self.set_remote_branches(remote_branches) self.set_tags(tags) diff --git a/test/test_cola_gitcmds.py b/test/test_cola_gitcmds.py index ac789202..9e8ab319 100644 --- a/test/test_cola_gitcmds.py +++ b/test/test_cola_gitcmds.py @@ -85,7 +85,24 @@ class GitCmdsTestCase(helper.GitRepositoryTestCase): git remote add origin . && git fetch origin > /dev/null 2>&1 """) - local, remote, tags = gitcmds.all_refs() + refs = gitcmds.all_refs() + self.assertEqual(refs, + ['a', 'b', 'c', 'master', + 'origin/a', 'origin/b', 'origin/c', 'origin/master', + 'd', 'e', 'f']) + + def test_all_refs_split(self): + self.shell(""" + git branch a && + git branch b && + git branch c && + git tag d && + git tag e && + git tag f && + git remote add origin . && + git fetch origin > /dev/null 2>&1 + """) + local, remote, tags = gitcmds.all_refs(split=True) self.assertEqual(local, ['a', 'b', 'c', 'master']) self.assertEqual(remote, ['origin/a', 'origin/b', 'origin/c', 'origin/master']) self.assertEqual(tags, ['d', 'e', 'f']) -- 2.11.4.GIT