Merge lp:~abentley/bzr/branches-uncommitted into lp:bzr

Proposed by Aaron Bentley on 2013-05-08
Status: Needs review
Proposed branch: lp:~abentley/bzr/branches-uncommitted
Merge into: lp:bzr
Diff against target: 198 lines (+69/-15)
5 files modified
bzrlib/branch.py (+12/-1)
bzrlib/builtins.py (+7/-4)
bzrlib/remote.py (+4/-0)
bzrlib/tests/blackbox/test_branches.py (+37/-10)
bzrlib/tests/per_branch/test_branch.py (+9/-0)
To merge this branch: bzr merge lp:~abentley/bzr/branches-uncommitted
Reviewer Review Type Date Requested Status
John A Meinel Approve on 2013-05-09
Richard Wilbur 2013-05-08 Approve on 2013-05-08
Review via email: mp+162925@code.launchpad.net

Commit Message

Show uncommitted changes in branches.

Description of the Change

This branch enables showing uncommitted changes for colocated branches, similar to the display in the 'pipeline' plugin. Uncommitted changes in branches are created with switch --store, and are a good reminder of which branches are works-in-progress.

Branch.has_uncommitted is implemented because the other way of determining uncommitted changes is convoluted: call get_unshelver, providing a tree, and see whether it returns None.

To post a comment you must log in.
Richard Wilbur (richard-wilbur) wrote :

Looks like a very good thing to have. Thanks for implementing it the less convoluted way.
+1

review: Approve
John A Meinel (jameinel) wrote :

69 + prefix += 'U' if uncommitted else ' '

Given the line just before this is:

if active:
  prefix =
else:
  prefix =

I would probably follow suite here. (or change the other one to be consistent).

Otherwise seems good.

review: Approve

Unmerged revisions

6578. By Aaron Bentley on 2013-05-07

Add tests for branches command.

6577. By Aaron Bentley on 2013-05-05

Test has_uncommitted, add RemoteBranch implementation.

6576. By Aaron Bentley on 2013-05-05

Indent default branch the same as other branches.

6575. By Aaron Bentley on 2013-05-05

Fix failing tests.

6574. By Aaron Bentley on 2013-05-05

List uncommitted branches.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/branch.py'
2--- bzrlib/branch.py 2012-07-19 18:28:25 +0000
3+++ bzrlib/branch.py 2013-05-08 04:37:28 +0000
4@@ -261,6 +261,9 @@
5 """
6 raise NotImplementedError(self.store_uncommitted)
7
8+ def has_uncommitted(self):
9+ return False
10+
11 def get_unshelver(self, tree):
12 """Return a shelf.Unshelver for this branch and tree.
13
14@@ -2412,6 +2415,10 @@
15 else:
16 return self
17
18+ @staticmethod
19+ def _has_uncommitted(branch):
20+ return branch._transport.has('stored-transform')
21+
22 def store_uncommitted(self, creator):
23 """Store uncommitted changes from a ShelfCreator.
24
25@@ -2423,13 +2430,17 @@
26 if creator is None:
27 branch._transport.delete('stored-transform')
28 return
29- if branch._transport.has('stored-transform'):
30+ if self._has_uncommitted(branch):
31 raise errors.ChangesAlreadyStored
32 transform = StringIO()
33 creator.write_shelf(transform)
34 transform.seek(0)
35 branch._transport.put_file('stored-transform', transform)
36
37+ def has_uncommitted(self):
38+ branch = self._uncommitted_branch()
39+ return self._has_uncommitted(branch)
40+
41 def get_unshelver(self, tree):
42 """Return a shelf.Unshelver for this branch and tree.
43
44
45=== modified file 'bzrlib/builtins.py'
46--- bzrlib/builtins.py 2012-09-27 17:41:19 +0000
47+++ bzrlib/builtins.py 2013-05-08 04:37:28 +0000
48@@ -1578,17 +1578,20 @@
49 continue
50 active = (active_branch is not None and
51 active_branch.base == branch.base)
52- names[name] = active
53+ names[name] = active, branch.has_uncommitted()
54+ branch_list = sorted(names.items())
55 # Only mention the current branch explicitly if it's not
56 # one of the colocated branches
57 if not any(names.values()) and active_branch is not None:
58- self.outf.write("* %s\n" % gettext("(default)"))
59- for name in sorted(names.keys()):
60- active = names[name]
61+ branch_list.insert(0,
62+ (gettext("(default)"),
63+ (True, active_branch.has_uncommitted())))
64+ for name, (active, uncommitted) in branch_list:
65 if active:
66 prefix = "*"
67 else:
68 prefix = " "
69+ prefix += 'U' if uncommitted else ' '
70 self.outf.write("%s %s\n" % (
71 prefix, name.encode(self.outf.encoding)))
72
73
74=== modified file 'bzrlib/remote.py'
75--- bzrlib/remote.py 2012-09-19 07:58:27 +0000
76+++ bzrlib/remote.py 2013-05-08 04:37:28 +0000
77@@ -3403,6 +3403,10 @@
78 self._ensure_real()
79 return self._real_branch.store_uncommitted(creator)
80
81+ def has_uncommitted(self):
82+ self._ensure_real()
83+ return self._real_branch.has_uncommitted()
84+
85 def get_unshelver(self, tree):
86 self._ensure_real()
87 return self._real_branch.get_unshelver(tree)
88
89=== modified file 'bzrlib/tests/blackbox/test_branches.py'
90--- bzrlib/tests/blackbox/test_branches.py 2012-02-13 17:34:46 +0000
91+++ bzrlib/tests/blackbox/test_branches.py 2013-05-08 04:37:28 +0000
92@@ -1,4 +1,4 @@
93-# Copyright (C) 2011 Canonical Ltd
94+# Copyright (C) 2011-2013 Canonical Ltd
95 #
96 # This program is free software; you can redistribute it and/or modify
97 # it under the terms of the GNU General Public License as published by
98@@ -19,6 +19,7 @@
99
100 from bzrlib.bzrdir import BzrDir
101 from bzrlib.tests import TestCaseWithTransport
102+from bzrlib.tests.per_branch.test_branch import FakeShelfCreator
103
104
105 class TestBranches(TestCaseWithTransport):
106@@ -28,7 +29,7 @@
107 # support.
108 self.run_bzr('init a')
109 out, err = self.run_bzr('branches a')
110- self.assertEquals(out, "* (default)\n")
111+ self.assertEquals(out, "* (default)\n")
112
113 def test_no_branch(self):
114 # Listing the branches in a control directory without branches.
115@@ -65,9 +66,9 @@
116 t.bzrdir.create_branch(name='another')
117 t.bzrdir.create_branch(name='colocated')
118 out, err = self.run_bzr('branches a')
119- self.assertEquals(out, "* (default)\n"
120- " another\n"
121- " colocated\n")
122+ self.assertEquals(out, "* (default)\n"
123+ " another\n"
124+ " colocated\n")
125
126 def test_indicates_branch(self):
127 t = self.make_repository('a', format='development-colo')
128@@ -75,8 +76,18 @@
129 branch = t.bzrdir.create_branch(name='colocated')
130 t.bzrdir.set_branch_reference(target_branch=branch)
131 out, err = self.run_bzr('branches a')
132- self.assertEquals(out, " another\n"
133- "* colocated\n")
134+ self.assertEquals(out, " another\n"
135+ "* colocated\n")
136+
137+ def test_indicates_uncommitted(self):
138+ t = self.make_repository('a', format='development-colo')
139+ t.bzrdir.create_branch(name='another')
140+ branch = t.bzrdir.create_branch(name='colocated')
141+ branch.store_uncommitted(FakeShelfCreator(branch))
142+ t.bzrdir.set_branch_reference(target_branch=branch)
143+ out, err = self.run_bzr('branches a')
144+ self.assertEquals(out, " another\n"
145+ "*U colocated\n")
146
147 def test_shared_repos(self):
148 self.make_repository('a', shared=True)
149@@ -84,10 +95,26 @@
150 b = BzrDir.create_branch_convenience('a/branch2')
151 b.create_checkout(lightweight=True, to_location='b')
152 out, err = self.run_bzr('branches b')
153- self.assertEquals(out, " branch1\n"
154- "* branch2\n")
155+ self.assertEquals(out, " branch1\n"
156+ "* branch2\n")
157+
158+ def test_shared_repos_uncommitted(self):
159+ self.make_repository('a', shared=True)
160+ BzrDir.create_branch_convenience('a/branch1')
161+ b = BzrDir.create_branch_convenience('a/branch2')
162+ b.create_checkout(lightweight=True, to_location='b')
163+ b.store_uncommitted(FakeShelfCreator(b))
164+ out, err = self.run_bzr('branches b')
165+ self.assertEquals(out, " branch1\n"
166+ "*U branch2\n")
167
168 def test_standalone_branch(self):
169 self.make_branch('a')
170 out, err = self.run_bzr('branches a')
171- self.assertEquals(out, "* (default)\n")
172+ self.assertEquals(out, "* (default)\n")
173+
174+ def test_standalone_branch_uncommitted(self):
175+ b = self.make_branch('a')
176+ b.store_uncommitted(FakeShelfCreator(b))
177+ out, err = self.run_bzr('branches a')
178+ self.assertEquals(out, "*U (default)\n")
179
180=== modified file 'bzrlib/tests/per_branch/test_branch.py'
181--- bzrlib/tests/per_branch/test_branch.py 2012-07-19 19:27:22 +0000
182+++ bzrlib/tests/per_branch/test_branch.py 2013-05-08 04:37:28 +0000
183@@ -1125,6 +1125,15 @@
184 branch.store_uncommitted(None)
185 self.assertIs(None, branch.get_unshelver(None))
186
187+ def test_has_uncommitted(self):
188+ branch = self.make_branch('b')
189+ self.assertFalse(branch.has_uncommitted())
190+ with skip_if_storing_uncommitted_unsupported():
191+ branch.store_uncommitted(FakeShelfCreator(branch))
192+ self.assertTrue(branch.has_uncommitted())
193+ branch.store_uncommitted(None)
194+ self.assertFalse(branch.has_uncommitted())
195+
196 def test_get_unshelver(self):
197 tree = self.make_branch_and_tree('tree')
198 tree.commit('')