Skip to content

Commit e04f22f

Browse files
committed
sort the list of tags and branches when listed
1 parent 0d898fe commit e04f22f

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

gitless/cli/gl_branch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _do_list(repo, list_remote, v=False):
8181
pprint.blank()
8282

8383

84-
for b in (repo.lookup_branch(n) for n in repo.listall_branches()):
84+
for b in (repo.lookup_branch(n) for n in sorted(repo.listall_branches())):
8585
current_str = '*' if b.is_current else ' '
8686
upstream_str = '(upstream is {0})'.format(b.upstream) if b.upstream else ''
8787
color = colored.green if b.is_current else colored.yellow
@@ -91,8 +91,8 @@ def _do_list(repo, list_remote, v=False):
9191
pprint.item(' ➜ head is {0}'.format(pprint.commit_str(b.head)))
9292

9393
if list_remote:
94-
for r in repo.remotes:
95-
for b in (r.lookup_branch(n) for n in r.listall_branches()):
94+
for r in sorted(repo.remotes, key=lambda r: r.name):
95+
for b in (r.lookup_branch(n) for n in sorted(r.listall_branches())):
9696
pprint.item(' {0}'.format(colored.yellow(str(b))))
9797
if v:
9898
pprint.item(' ➜ head is {0}'.format(pprint.commit_str(b.head)))

gitless/cli/gl_tag.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ def _do_list(repo, list_remote):
5656
pprint.blank()
5757

5858
no_tags = True
59-
for t in (repo.lookup_tag(n) for n in repo.listall_tags()):
59+
for t in (repo.lookup_tag(n) for n in sorted(repo.listall_tags())):
6060
pprint.item('{0} ➜ tags {1}'.format(t, pprint.commit_str(t.commit)))
6161
no_tags = False
6262

6363
if list_remote:
64-
for r in repo.remotes:
65-
for t in (r.lookup_tag(n) for n in r.listall_tags()):
64+
for r in sorted(repo.remotes, key=lambda r: r.name):
65+
for t in (r.lookup_tag(n) for n in sorted(r.listall_tags())):
6666
pprint.item('{0} ➜ tags {1}'.format(t, pprint.commit_str(t.commit)))
6767
no_tags = False
6868

gitless/tests/test_e2e.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,18 @@ def test_upstream(self):
286286
self.assertRaises(
287287
ErrorReturnCode, gl.branch, '-su', 'non-existent/non-existent')
288288

289+
def test_list(self):
290+
gl.branch(c=self.BRANCH_1)
291+
gl.branch(c=self.BRANCH_2)
292+
branch_out = utils.stdout(gl.branch(_tty_out=False))
293+
self.assertTrue(
294+
branch_out.find(self.BRANCH_1) < branch_out.find(self.BRANCH_2))
295+
289296

290297
class TestTag(TestEndToEnd):
291298

292299
TAG_1 = 'tag1'
300+
TAG_2 = 'tag2'
293301

294302
def setUp(self):
295303
super(TestTag, self).setUp()
@@ -310,6 +318,13 @@ def test_remove(self):
310318
if self.TAG_1 in utils.stdout(gl.tag(_tty_out=False)):
311319
self.fail()
312320

321+
def test_list(self):
322+
gl.tag(c=self.TAG_1)
323+
gl.tag(c=self.TAG_2)
324+
tag_out = utils.stdout(gl.tag(_tty_out=False))
325+
self.assertTrue(
326+
tag_out.find(self.TAG_1) < tag_out.find(self.TAG_2))
327+
313328

314329
class TestDiffFile(TestEndToEnd):
315330

0 commit comments

Comments
 (0)