Merge lp:~gz/bzr/2.5_backport_rmbranch_fixes into lp:bzr/2.5

Proposed by Martin Packman
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merged at revision: 6500
Proposed branch: lp:~gz/bzr/2.5_backport_rmbranch_fixes
Merge into: lp:bzr/2.5
Diff against target: 220 lines (+95/-23)
4 files modified
bzrlib/builtins.py (+47/-14)
bzrlib/tests/blackbox/test_rmbranch.py (+41/-8)
bzrlib/tests/blackbox/test_switch.py (+1/-1)
doc/en/release-notes/bzr-2.5.txt (+6/-0)
To merge this branch: bzr merge lp:~gz/bzr/2.5_backport_rmbranch_fixes
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Approve
Review via email: mp+106753@code.launchpad.net

Commit message

Backport fixes to rmbranch on colocated branches from 2.6

Description of the change

Backports from 2.6 fixes related to rmbranch which have caught out several people when working with colocated branches. Both bugs are included, as the second which fixes the specific issue of accidentally removing your active branch depends on some changes made in the first.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve (code)
Revision history for this message
Martin Packman (gz) wrote :

sent to pqm by email

Revision history for this message
Martin Packman (gz) wrote :

Failed on pqm as it failed to branch over http, contents of stdout were just:

    Could not determine branch type for 'http://bazaar.launchpad.net/~gz/bzr/2.5_backport_rmbranch_fixes'

Due current to launchpad database work causing lag, as the http rewriting uses a slave database.

Revision history for this message
Martin Packman (gz) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2012-02-16 16:42:43 +0000
+++ bzrlib/builtins.py 2012-05-22 08:15:24 +0000
@@ -149,9 +149,9 @@
149 return location149 return location
150150
151151
152def lookup_sibling_branch(control_dir, location, possible_transports=None):152def open_sibling_branch(control_dir, location, possible_transports=None):
153 """Lookup sibling branch.153 """Open a branch, possibly a sibling.
154 154
155 :param control_dir: Control directory relative to which to lookup the155 :param control_dir: Control directory relative to which to lookup the
156 location.156 location.
157 :param location: Location to look up157 :param location: Location to look up
@@ -162,13 +162,31 @@
162 return control_dir.open_branch(location, 162 return control_dir.open_branch(location,
163 possible_transports=possible_transports)163 possible_transports=possible_transports)
164 except (errors.NotBranchError, errors.NoColocatedBranchSupport):164 except (errors.NotBranchError, errors.NoColocatedBranchSupport):
165 this_url = _get_branch_location(control_dir)
166 return Branch.open(
167 urlutils.join(
168 this_url, '..', urlutils.escape(location)))
169
170
171def open_nearby_branch(near=None, location=None, possible_transports=None):
172 """Open a nearby branch.
173
174 :param near: Optional location of container from which to open branch
175 :param location: Location of the branch
176 :return: Branch instance
177 """
178 if near is None:
179 if location is None:
180 location = "."
165 try:181 try:
166 return Branch.open(location)182 return Branch.open(location,
183 possible_transports=possible_transports)
167 except errors.NotBranchError:184 except errors.NotBranchError:
168 this_url = _get_branch_location(control_dir)185 near = "."
169 return Branch.open(186 cdir = controldir.ControlDir.open(near,
170 urlutils.join(187 possible_transports=possible_transports)
171 this_url, '..', urlutils.escape(location)))188 return open_sibling_branch(cdir, location,
189 possible_transports=possible_transports)
172190
173191
174@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))192@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
@@ -6247,7 +6265,12 @@
6247 possible_transports=possible_transports,6265 possible_transports=possible_transports,
6248 source_branch=branch).open_branch()6266 source_branch=branch).open_branch()
6249 else:6267 else:
6250 to_branch = lookup_sibling_branch(control_dir, to_location)6268 try:
6269 to_branch = Branch.open(to_location,
6270 possible_transports=possible_transports)
6271 except errors.NotBranchError:
6272 to_branch = open_sibling_branch(control_dir, to_location,
6273 possible_transports=possible_transports)
6251 if revision is not None:6274 if revision is not None:
6252 revision = revision.as_revision_id(to_branch)6275 revision = revision.as_revision_id(to_branch)
6253 switch.switch(control_dir, to_branch, force, revision_id=revision)6276 switch.switch(control_dir, to_branch, force, revision_id=revision)
@@ -6450,13 +6473,23 @@
64506473
6451 takes_args = ["location?"]6474 takes_args = ["location?"]
64526475
6476 takes_options = ['directory',
6477 Option('force', help='Remove branch even if it is the active branch.')]
6478
6453 aliases = ["rmbranch"]6479 aliases = ["rmbranch"]
64546480
6455 def run(self, location=None):6481 def run(self, directory=None, location=None, force=False):
6456 if location is None:6482 br = open_nearby_branch(near=directory, location=location)
6457 location = "."6483 if not force and br.bzrdir.has_workingtree():
6458 cdir = controldir.ControlDir.open_containing(location)[0]6484 try:
6459 cdir.destroy_branch()6485 active_branch = br.bzrdir.open_branch(name="")
6486 except errors.NotBranchError:
6487 active_branch = None
6488 if (active_branch is not None and
6489 br.control_url == active_branch.control_url):
6490 raise errors.BzrCommandError(
6491 gettext("Branch is active. Use --force to remove it."))
6492 br.bzrdir.destroy_branch(br.name)
64606493
64616494
6462class cmd_shelve(Command):6495class cmd_shelve(Command):
64636496
=== modified file 'bzrlib/tests/blackbox/test_rmbranch.py'
--- bzrlib/tests/blackbox/test_rmbranch.py 2012-01-25 17:31:04 +0000
+++ bzrlib/tests/blackbox/test_rmbranch.py 2012-05-22 08:15:24 +0000
@@ -28,7 +28,7 @@
2828
29class TestRemoveBranch(TestCaseWithTransport):29class TestRemoveBranch(TestCaseWithTransport):
3030
31 def example_branch(self, path='.', format=None):31 def example_tree(self, path='.', format=None):
32 tree = self.make_branch_and_tree(path, format=format)32 tree = self.make_branch_and_tree(path, format=format)
33 self.build_tree_contents([(path + '/hello', 'foo')])33 self.build_tree_contents([(path + '/hello', 'foo')])
34 tree.add('hello')34 tree.add('hello')
@@ -40,29 +40,41 @@
4040
41 def test_remove_local(self):41 def test_remove_local(self):
42 # Remove a local branch.42 # Remove a local branch.
43 self.example_branch('a')43 tree = self.example_tree('a')
44 self.run_bzr('rmbranch a')44 self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
45 'rmbranch a')
46 self.run_bzr('rmbranch --force a')
45 dir = bzrdir.BzrDir.open('a')47 dir = bzrdir.BzrDir.open('a')
46 self.assertFalse(dir.has_branch())48 self.assertFalse(dir.has_branch())
47 self.assertPathExists('a/hello')49 self.assertPathExists('a/hello')
48 self.assertPathExists('a/goodbye')50 self.assertPathExists('a/goodbye')
4951
50 def test_no_branch(self):52 def test_no_branch(self):
51 # No branch in the current directory. 53 # No branch in the current directory.
52 self.make_repository('a')54 self.make_repository('a')
53 self.run_bzr_error(['Not a branch'],55 self.run_bzr_error(['Not a branch'],
54 'rmbranch a')56 'rmbranch a')
5557
58 def test_no_tree(self):
59 # removing the active branch is possible if there is no tree
60 tree = self.example_tree('a')
61 tree.bzrdir.destroy_workingtree()
62 self.run_bzr('rmbranch', working_dir='a')
63 dir = bzrdir.BzrDir.open('a')
64 self.assertFalse(dir.has_branch())
65
56 def test_no_arg(self):66 def test_no_arg(self):
57 # location argument defaults to current directory67 # location argument defaults to current directory
58 self.example_branch('a')68 self.example_tree('a')
59 self.run_bzr('rmbranch', working_dir='a')69 self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
70 'rmbranch a')
71 self.run_bzr('rmbranch --force', working_dir='a')
60 dir = bzrdir.BzrDir.open('a')72 dir = bzrdir.BzrDir.open('a')
61 self.assertFalse(dir.has_branch())73 self.assertFalse(dir.has_branch())
6274
63 def test_remove_colo(self):75 def test_remove_colo(self):
64 # Remove a colocated branch.76 # Remove a colocated branch.
65 tree = self.example_branch('a', format='development-colo')77 tree = self.example_tree('a')
66 tree.bzrdir.create_branch(name="otherbranch")78 tree.bzrdir.create_branch(name="otherbranch")
67 self.assertTrue(tree.bzrdir.has_branch('otherbranch'))79 self.assertTrue(tree.bzrdir.has_branch('otherbranch'))
68 self.run_bzr('rmbranch %s,branch=otherbranch' % tree.bzrdir.user_url)80 self.run_bzr('rmbranch %s,branch=otherbranch' % tree.bzrdir.user_url)
@@ -70,6 +82,27 @@
70 self.assertFalse(dir.has_branch('otherbranch'))82 self.assertFalse(dir.has_branch('otherbranch'))
71 self.assertTrue(dir.has_branch())83 self.assertTrue(dir.has_branch())
7284
85 def test_remove_colo_directory(self):
86 # Remove a colocated branch.
87 tree = self.example_tree('a')
88 tree.bzrdir.create_branch(name="otherbranch")
89 self.assertTrue(tree.bzrdir.has_branch('otherbranch'))
90 self.run_bzr('rmbranch otherbranch -d %s' % tree.bzrdir.user_url)
91 dir = bzrdir.BzrDir.open('a')
92 self.assertFalse(dir.has_branch('otherbranch'))
93 self.assertTrue(dir.has_branch())
94
95 def test_remove_active_colo_branch(self):
96 # Remove a colocated branch.
97 dir = self.make_repository('a').bzrdir
98 branch = dir.create_branch('otherbranch')
99 branch.create_checkout('a')
100 self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
101 'rmbranch otherbranch -d %s' % branch.bzrdir.user_url)
102 self.assertTrue(dir.has_branch('otherbranch'))
103 self.run_bzr('rmbranch --force otherbranch -d %s' % branch.bzrdir.user_url)
104 self.assertFalse(dir.has_branch('otherbranch'))
105
73106
74class TestSmartServerRemoveBranch(TestCaseWithTransport):107class TestSmartServerRemoveBranch(TestCaseWithTransport):
75108
@@ -83,6 +116,6 @@
83 # being too low. If rpc_count increases, more network roundtrips have116 # being too low. If rpc_count increases, more network roundtrips have
84 # become necessary for this use case. Please do not adjust this number117 # become necessary for this use case. Please do not adjust this number
85 # upwards without agreement from bzr's network support maintainers.118 # upwards without agreement from bzr's network support maintainers.
86 self.assertLength(2, self.hpss_calls)119 self.assertLength(5, self.hpss_calls)
87 self.assertLength(1, self.hpss_connections)120 self.assertLength(1, self.hpss_connections)
88 self.assertThat(self.hpss_calls, ContainsNoVfsCalls)121 self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
89122
=== modified file 'bzrlib/tests/blackbox/test_switch.py'
--- bzrlib/tests/blackbox/test_switch.py 2012-02-03 12:47:10 +0000
+++ bzrlib/tests/blackbox/test_switch.py 2012-05-22 08:15:24 +0000
@@ -472,5 +472,5 @@
472 # become necessary for this use case. Please do not adjust this number472 # become necessary for this use case. Please do not adjust this number
473 # upwards without agreement from bzr's network support maintainers.473 # upwards without agreement from bzr's network support maintainers.
474 self.assertLength(24, self.hpss_calls)474 self.assertLength(24, self.hpss_calls)
475 self.assertLength(5, self.hpss_connections)475 self.assertLength(4, self.hpss_connections)
476 self.assertThat(self.hpss_calls, ContainsNoVfsCalls)476 self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
477477
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- doc/en/release-notes/bzr-2.5.txt 2012-04-30 11:12:00 +0000
+++ doc/en/release-notes/bzr-2.5.txt 2012-05-22 08:15:24 +0000
@@ -26,6 +26,12 @@
26.. Improvements to existing commands, especially improved performance 26.. Improvements to existing commands, especially improved performance
27 or memory usage, or better results.27 or memory usage, or better results.
2828
29* ``bzr rmbranch`` now supports removing colocated branches.
30 (Jelmer Vernooij, #920653)
31
32* ``bzr rmbranch`` no longer removes active branches unless ``--force``
33 is specified. (Jelmer Vernooij, #922953)
34
29Bug Fixes35Bug Fixes
30*********36*********
3137

Subscribers

People subscribed via source and target branches