Merge lp:~jelmer/bzr/branches-indicates-current-branch into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 6396
Proposed branch: lp:~jelmer/bzr/branches-indicates-current-branch
Merge into: lp:bzr
Diff against target: 121 lines (+48/-8)
5 files modified
bzrlib/builtins.py (+23/-5)
bzrlib/tests/blackbox/test_branch.py (+1/-1)
bzrlib/tests/blackbox/test_branches.py (+20/-1)
bzrlib/tests/blackbox/test_init.py (+1/-1)
doc/en/release-notes/bzr-2.5.txt (+3/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/branches-indicates-current-branch
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+86152@code.launchpad.net

Commit message

Indicate current branch in 'bzr branches'.

Description of the change

Make 'bzr branches' indicate the currently active branch.

To post a comment you must log in.
Revision history for this message
Gordon Tyler (doxxx) wrote :

Something to consider would be to use a * in front of the name instead, to match Git.

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

> Something to consider would be to use a * in front of the name instead, to
> match Git.
That's exactly what this does.. :)

Revision history for this message
Gordon Tyler (doxxx) wrote :

Sorry, misread the diff. Carry on!

Revision history for this message
Vincent Ladeuil (vila) wrote :

[minor nit]

84 +* ``bzr branches`` now indicates the active colocated branch.

... by prefixing it with...

Worth mentioning in what's new ?

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/builtins.py'
2--- bzrlib/builtins.py 2011-12-20 18:47:35 +0000
3+++ bzrlib/builtins.py 2011-12-21 16:30:36 +0000
4@@ -1435,12 +1435,30 @@
5 self.outf.encoding).rstrip("/"))
6 else:
7 dir = controldir.ControlDir.open_containing(location)[0]
8- for branch in dir.list_branches():
9- if branch.name is None:
10- self.outf.write(gettext(" (default)\n"))
11+ try:
12+ active_branch = dir.open_branch(name=None)
13+ except errors.NotBranchError:
14+ active_branch = None
15+ branches = dir.get_branches()
16+ names = {}
17+ for name, branch in branches.iteritems():
18+ if name is None:
19+ continue
20+ active = (active_branch is not None and
21+ active_branch.base == branch.base)
22+ names[name] = active
23+ # Only mention the current branch explicitly if it's not
24+ # one of the colocated branches
25+ if not any(names.values()) and active_branch is not None:
26+ self.outf.write("* %s\n" % gettext("(default)"))
27+ for name in sorted(names.keys()):
28+ active = names[name]
29+ if active:
30+ prefix = "*"
31 else:
32- self.outf.write(" %s\n" % branch.name.encode(
33- self.outf.encoding))
34+ prefix = " "
35+ self.outf.write("%s %s\n" % (
36+ prefix, name.encode(self.outf.encoding)))
37
38
39 class cmd_checkout(Command):
40
41=== modified file 'bzrlib/tests/blackbox/test_branch.py'
42--- bzrlib/tests/blackbox/test_branch.py 2011-12-14 20:08:26 +0000
43+++ bzrlib/tests/blackbox/test_branch.py 2011-12-21 16:30:36 +0000
44@@ -79,7 +79,7 @@
45 self.assertEqual('', out)
46 self.assertEqual('Branched 2 revisions.\n', err)
47 out, err = self.run_bzr('branches b')
48- self.assertEqual(" thiswasa\n orig\n", out)
49+ self.assertEqual(" orig\n thiswasa\n", out)
50 self.assertEqual('', err)
51 out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
52 self.assertEqual('', out)
53
54=== modified file 'bzrlib/tests/blackbox/test_branches.py'
55--- bzrlib/tests/blackbox/test_branches.py 2011-08-30 09:03:33 +0000
56+++ bzrlib/tests/blackbox/test_branches.py 2011-12-21 16:30:36 +0000
57@@ -17,6 +17,7 @@
58
59 """Black-box tests for bzr branches."""
60
61+from bzrlib.branch import BranchReferenceFormat
62 from bzrlib.tests import TestCaseWithTransport
63
64
65@@ -27,7 +28,7 @@
66 # support.
67 self.run_bzr('init a')
68 out, err = self.run_bzr('branches a')
69- self.assertEquals(out, " (default)\n")
70+ self.assertEquals(out, "* (default)\n")
71
72 def test_no_branch(self):
73 # Listing the branches in a control directory without branches.
74@@ -58,3 +59,21 @@
75 self.assertIs(True, 'source/subsource' in lines, lines)
76 self.assertIs(True, 'checkout/subcheckout' in lines, lines)
77 self.assertIs(True, 'checkout' not in lines, lines)
78+
79+ def test_indicates_non_branch(self):
80+ t = self.make_branch_and_tree('a', format='development-colo')
81+ t.bzrdir.create_branch(name='another')
82+ t.bzrdir.create_branch(name='colocated')
83+ out, err = self.run_bzr('branches a')
84+ self.assertEquals(out, "* (default)\n"
85+ " another\n"
86+ " colocated\n")
87+
88+ def test_indicates_branch(self):
89+ t = self.make_repository('a', format='development-colo')
90+ t.bzrdir.create_branch(name='another')
91+ branch = t.bzrdir.create_branch(name='colocated')
92+ BranchReferenceFormat().initialize(t.bzrdir, target_branch=branch)
93+ out, err = self.run_bzr('branches a')
94+ self.assertEquals(out, " another\n"
95+ "* colocated\n")
96
97=== modified file 'bzrlib/tests/blackbox/test_init.py'
98--- bzrlib/tests/blackbox/test_init.py 2011-11-17 17:24:57 +0000
99+++ bzrlib/tests/blackbox/test_init.py 2011-12-21 16:30:36 +0000
100@@ -61,7 +61,7 @@
101 out)
102 self.assertEqual('', err)
103 out, err = self.run_bzr('branches')
104- self.assertEqual(" abranch\n", out)
105+ self.assertEqual(" abranch\n", out)
106 self.assertEqual('', err)
107
108 def test_init_at_repository_root(self):
109
110=== modified file 'doc/en/release-notes/bzr-2.5.txt'
111--- doc/en/release-notes/bzr-2.5.txt 2011-12-21 15:32:34 +0000
112+++ doc/en/release-notes/bzr-2.5.txt 2011-12-21 16:30:36 +0000
113@@ -46,6 +46,9 @@
114 will mean bzr works with non-ascii files when no locale or an incorrect
115 locale is set. (Martin Packman, #794353)
116
117+* ``bzr branches`` now indicates the active colocated branch.
118+ (Jelmer Vernooij, #891667)
119+
120 * ``bzr send`` now only opens a single connection, rather than two,
121 to the target branch. (Jelmer Vernooij)
122