Merge lp:~richard-wilbur/bzr/branches-uncommitted into lp:bzr

Proposed by Richard Wilbur
Status: Work in progress
Proposed branch: lp:~richard-wilbur/bzr/branches-uncommitted
Merge into: lp:bzr
Diff against target: 272 lines (+81/-29)
7 files modified
bzrlib/branch.py (+13/-2)
bzrlib/builtins.py (+12/-11)
bzrlib/remote.py (+5/-1)
bzrlib/tests/blackbox/test_branch.py (+2/-2)
bzrlib/tests/blackbox/test_branches.py (+37/-10)
bzrlib/tests/blackbox/test_init.py (+2/-2)
bzrlib/tests/per_branch/test_branch.py (+10/-1)
To merge this branch: bzr merge lp:~richard-wilbur/bzr/branches-uncommitted
Reviewer Review Type Date Requested Status
Vincent Ladeuil Needs Fixing
Richard Wilbur concept already approved on another branch. Approve
Review via email: mp+259295@code.launchpad.net

Commit message

Fixed up Aaron Bentley's branches-uncommitted code (from 2 years ago) to merge into current trunk.

Description of the change

Updated Aaron Bentley's branches-uncommitted branch from 2013 to work with new trunk: 2 new tests on trunk failed because of change in 'branches' command output formatting and content. Fixed regression in test suite caused by unintentional change in behaviour of 'branches' command (original behaviour restored). Added documentation for status flags in output.

Implemented John Arbash-Meinel's recommendation for code style uniformity.

To post a comment you must log in.
6608. By Richard Wilbur

Provide a little more explanation in documentation.

6609. By Richard Wilbur

Update copyright dates.

Revision history for this message
Richard Wilbur (richard-wilbur) wrote :

John, you and I had already approved of Aaron Bentley's changes that this branch is based on--with the suggestion of reformatting part of it to make the code style more consistent.

I fixed an unnoticed regression in that code, the attendant bit rot of two years, and added a little polish to the documentation.

Revision history for this message
Richard Wilbur (richard-wilbur) wrote :

I guess John is pretty busy. On the authority that the concept was already approved and these are relatively trivial changes, I'll approve this and go ahead an merge it.

review: Approve (concept already approved on another branch.)
Revision history for this message
Richard Wilbur (richard-wilbur) wrote :

sent to pqm by email

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

I can't help but think that 'uncommitted' in not part of the branch domain.

I can see dragons around shelves rotting in side a branch.

shelves are working tree related, it's expected that they rot there and the tools to deal with that are related to working trees.

If one want to keep some unfinished work, I can't see the cons about committing it.

As a bzr user I know how to resume work from this revision as well as stepping back from it to continue work without that revision.

review: Needs Fixing

Unmerged revisions

6609. By Richard Wilbur

Update copyright dates.

6608. By Richard Wilbur

Provide a little more explanation in documentation.

6607. By Richard Wilbur

Make boolean->visual flag conversion with consistent syntax. Document flags.

6606. By Richard Wilbur

Fix branches command handling of active flags.

6605. By Richard Wilbur

Fix 2 trivial test failures simply due to change in branches output format.

6604. By Richard Wilbur

Show uncommitted changes in branches.(Aaron Bentley) Suffers from some test breakage(3).

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 2013-05-23 10:04:17 +0000
3+++ bzrlib/branch.py 2015-05-20 19:29:33 +0000
4@@ -1,4 +1,4 @@
5-# Copyright (C) 2005-2012 Canonical Ltd
6+# Copyright (C) 2005-2013, 2015 Canonical Ltd
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10@@ -261,6 +261,9 @@
11 """
12 raise NotImplementedError(self.store_uncommitted)
13
14+ def has_uncommitted(self):
15+ return False
16+
17 def get_unshelver(self, tree):
18 """Return a shelf.Unshelver for this branch and tree.
19
20@@ -2412,6 +2415,10 @@
21 else:
22 return self
23
24+ @staticmethod
25+ def _has_uncommitted(branch):
26+ return branch._transport.has('stored-transform')
27+
28 def store_uncommitted(self, creator):
29 """Store uncommitted changes from a ShelfCreator.
30
31@@ -2423,13 +2430,17 @@
32 if creator is None:
33 branch._transport.delete('stored-transform')
34 return
35- if branch._transport.has('stored-transform'):
36+ if self._has_uncommitted(branch):
37 raise errors.ChangesAlreadyStored
38 transform = StringIO()
39 creator.write_shelf(transform)
40 transform.seek(0)
41 branch._transport.put_file('stored-transform', transform)
42
43+ def has_uncommitted(self):
44+ branch = self._uncommitted_branch()
45+ return self._has_uncommitted(branch)
46+
47 def get_unshelver(self, tree):
48 """Return a shelf.Unshelver for this branch and tree.
49
50
51=== modified file 'bzrlib/builtins.py'
52--- bzrlib/builtins.py 2013-05-23 10:04:17 +0000
53+++ bzrlib/builtins.py 2015-05-20 19:29:33 +0000
54@@ -1,4 +1,4 @@
55-# Copyright (C) 2005-2012 Canonical Ltd
56+# Copyright (C) 2005-2013, 2015 Canonical Ltd
57 #
58 # This program is free software; you can redistribute it and/or modify
59 # it under the terms of the GNU General Public License as published by
60@@ -1547,7 +1547,8 @@
61 __doc__ = """List the branches available at the current location.
62
63 This command will print the names of all the branches at the current
64- location.
65+ location. Flags colocated branches: '*' for active (current working
66+ tree) and 'U' for uncommitted changes.
67 """
68
69 takes_args = ['location?']
70@@ -1578,17 +1579,17 @@
71 continue
72 active = (active_branch is not None and
73 active_branch.base == branch.base)
74- names[name] = active
75+ names[name] = active, branch.has_uncommitted()
76+ branch_list = sorted(names.items())
77 # Only mention the current branch explicitly if it's not
78 # one of the colocated branches
79- if not any(names.values()) and active_branch is not None:
80- self.outf.write("* %s\n" % gettext("(default)"))
81- for name in sorted(names.keys()):
82- active = names[name]
83- if active:
84- prefix = "*"
85- else:
86- prefix = " "
87+ if not any([active for (active, u) in names.values()]) and active_branch is not None:
88+ branch_list.insert(0,
89+ (gettext("(default)"),
90+ (True, active_branch.has_uncommitted())))
91+ for name, (active, uncommitted) in branch_list:
92+ prefix = "*" if active else " "
93+ prefix += 'U' if uncommitted else ' '
94 self.outf.write("%s %s\n" % (
95 prefix, name.encode(self.outf.encoding)))
96
97
98=== modified file 'bzrlib/remote.py'
99--- bzrlib/remote.py 2012-09-19 07:58:27 +0000
100+++ bzrlib/remote.py 2015-05-20 19:29:33 +0000
101@@ -1,4 +1,4 @@
102-# Copyright (C) 2006-2012 Canonical Ltd
103+# Copyright (C) 2006-2013, 2015 Canonical Ltd
104 #
105 # This program is free software; you can redistribute it and/or modify
106 # it under the terms of the GNU General Public License as published by
107@@ -3403,6 +3403,10 @@
108 self._ensure_real()
109 return self._real_branch.store_uncommitted(creator)
110
111+ def has_uncommitted(self):
112+ self._ensure_real()
113+ return self._real_branch.has_uncommitted()
114+
115 def get_unshelver(self, tree):
116 self._ensure_real()
117 return self._real_branch.get_unshelver(tree)
118
119=== modified file 'bzrlib/tests/blackbox/test_branch.py'
120--- bzrlib/tests/blackbox/test_branch.py 2012-02-23 23:26:35 +0000
121+++ bzrlib/tests/blackbox/test_branch.py 2015-05-20 19:29:33 +0000
122@@ -1,4 +1,4 @@
123-# Copyright (C) 2006-2012 Canonical Ltd
124+# Copyright (C) 2006-2012, 2015 Canonical Ltd
125 #
126 # This program is free software; you can redistribute it and/or modify
127 # it under the terms of the GNU General Public License as published by
128@@ -87,7 +87,7 @@
129 self.assertEqual('', out)
130 self.assertEqual('Branched 2 revisions.\n', err)
131 out, err = self.run_bzr('branches b')
132- self.assertEqual(" orig\n thiswasa\n", out)
133+ self.assertEqual(" orig\n thiswasa\n", out)
134 self.assertEqual('', err)
135 out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
136 self.assertEqual('', out)
137
138=== modified file 'bzrlib/tests/blackbox/test_branches.py'
139--- bzrlib/tests/blackbox/test_branches.py 2012-02-13 17:34:46 +0000
140+++ bzrlib/tests/blackbox/test_branches.py 2015-05-20 19:29:33 +0000
141@@ -1,4 +1,4 @@
142-# Copyright (C) 2011 Canonical Ltd
143+# Copyright (C) 2011-2013, 2015 Canonical Ltd
144 #
145 # This program is free software; you can redistribute it and/or modify
146 # it under the terms of the GNU General Public License as published by
147@@ -19,6 +19,7 @@
148
149 from bzrlib.bzrdir import BzrDir
150 from bzrlib.tests import TestCaseWithTransport
151+from bzrlib.tests.per_branch.test_branch import FakeShelfCreator
152
153
154 class TestBranches(TestCaseWithTransport):
155@@ -28,7 +29,7 @@
156 # support.
157 self.run_bzr('init a')
158 out, err = self.run_bzr('branches a')
159- self.assertEquals(out, "* (default)\n")
160+ self.assertEquals(out, "* (default)\n")
161
162 def test_no_branch(self):
163 # Listing the branches in a control directory without branches.
164@@ -65,9 +66,9 @@
165 t.bzrdir.create_branch(name='another')
166 t.bzrdir.create_branch(name='colocated')
167 out, err = self.run_bzr('branches a')
168- self.assertEquals(out, "* (default)\n"
169- " another\n"
170- " colocated\n")
171+ self.assertEquals(out, "* (default)\n"
172+ " another\n"
173+ " colocated\n")
174
175 def test_indicates_branch(self):
176 t = self.make_repository('a', format='development-colo')
177@@ -75,8 +76,18 @@
178 branch = t.bzrdir.create_branch(name='colocated')
179 t.bzrdir.set_branch_reference(target_branch=branch)
180 out, err = self.run_bzr('branches a')
181- self.assertEquals(out, " another\n"
182- "* colocated\n")
183+ self.assertEquals(out, " another\n"
184+ "* colocated\n")
185+
186+ def test_indicates_uncommitted(self):
187+ t = self.make_repository('a', format='development-colo')
188+ t.bzrdir.create_branch(name='another')
189+ branch = t.bzrdir.create_branch(name='colocated')
190+ branch.store_uncommitted(FakeShelfCreator(branch))
191+ t.bzrdir.set_branch_reference(target_branch=branch)
192+ out, err = self.run_bzr('branches a')
193+ self.assertEquals(out, " another\n"
194+ "*U colocated\n")
195
196 def test_shared_repos(self):
197 self.make_repository('a', shared=True)
198@@ -84,10 +95,26 @@
199 b = BzrDir.create_branch_convenience('a/branch2')
200 b.create_checkout(lightweight=True, to_location='b')
201 out, err = self.run_bzr('branches b')
202- self.assertEquals(out, " branch1\n"
203- "* branch2\n")
204+ self.assertEquals(out, " branch1\n"
205+ "* branch2\n")
206+
207+ def test_shared_repos_uncommitted(self):
208+ self.make_repository('a', shared=True)
209+ BzrDir.create_branch_convenience('a/branch1')
210+ b = BzrDir.create_branch_convenience('a/branch2')
211+ b.create_checkout(lightweight=True, to_location='b')
212+ b.store_uncommitted(FakeShelfCreator(b))
213+ out, err = self.run_bzr('branches b')
214+ self.assertEquals(out, " branch1\n"
215+ "*U branch2\n")
216
217 def test_standalone_branch(self):
218 self.make_branch('a')
219 out, err = self.run_bzr('branches a')
220- self.assertEquals(out, "* (default)\n")
221+ self.assertEquals(out, "* (default)\n")
222+
223+ def test_standalone_branch_uncommitted(self):
224+ b = self.make_branch('a')
225+ b.store_uncommitted(FakeShelfCreator(b))
226+ out, err = self.run_bzr('branches a')
227+ self.assertEquals(out, "*U (default)\n")
228
229=== modified file 'bzrlib/tests/blackbox/test_init.py'
230--- bzrlib/tests/blackbox/test_init.py 2012-08-23 14:24:38 +0000
231+++ bzrlib/tests/blackbox/test_init.py 2015-05-20 19:29:33 +0000
232@@ -1,4 +1,4 @@
233-# Copyright (C) 2006-2011 Canonical Ltd
234+# Copyright (C) 2006-2012, 2015 Canonical Ltd
235 #
236 # This program is free software; you can redistribute it and/or modify
237 # it under the terms of the GNU General Public License as published by
238@@ -61,7 +61,7 @@
239 out)
240 self.assertEqual('', err)
241 out, err = self.run_bzr('branches')
242- self.assertEqual(" abranch\n", out)
243+ self.assertEqual(" abranch\n", out)
244 self.assertEqual('', err)
245
246 def test_init_at_repository_root(self):
247
248=== modified file 'bzrlib/tests/per_branch/test_branch.py'
249--- bzrlib/tests/per_branch/test_branch.py 2012-07-19 19:27:22 +0000
250+++ bzrlib/tests/per_branch/test_branch.py 2015-05-20 19:29:33 +0000
251@@ -1,4 +1,4 @@
252-# Copyright (C) 2005-2012 Canonical Ltd
253+# Copyright (C) 2005-2013, 2015 Canonical Ltd
254 #
255 # This program is free software; you can redistribute it and/or modify
256 # it under the terms of the GNU General Public License as published by
257@@ -1125,6 +1125,15 @@
258 branch.store_uncommitted(None)
259 self.assertIs(None, branch.get_unshelver(None))
260
261+ def test_has_uncommitted(self):
262+ branch = self.make_branch('b')
263+ self.assertFalse(branch.has_uncommitted())
264+ with skip_if_storing_uncommitted_unsupported():
265+ branch.store_uncommitted(FakeShelfCreator(branch))
266+ self.assertTrue(branch.has_uncommitted())
267+ branch.store_uncommitted(None)
268+ self.assertFalse(branch.has_uncommitted())
269+
270 def test_get_unshelver(self):
271 tree = self.make_branch_and_tree('tree')
272 tree.commit('')