Rev 6482: (jelmer) Require --force to remove active branches in 'bzr rmbranch'. in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Mar 6 17:43:03 UTC 2012
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6482 [merge]
revision-id: pqm at pqm.ubuntu.com-20120306174302-b6y3hyh1yfnutk9o
parent: pqm at pqm.ubuntu.com-20120306164545-6i5cyyfxctiwq11p
parent: jelmer at samba.org-20120228101024-5g7vqt5nsfsq1dh3
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2012-03-06 17:43:02 +0000
message:
(jelmer) Require --force to remove active branches in 'bzr rmbranch'.
(Jelmer Vernooij)
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_rmbranch.py test_rmbranch.py-20100131150653-auenl06hu4y2d9tr-1
doc/en/release-notes/bzr-2.6.txt bzr2.6.txt-20120116134316-8w1xxom1c7vcu1t5-1
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2012-03-06 16:45:45 +0000
+++ b/bzrlib/builtins.py 2012-03-06 17:43:02 +0000
@@ -6458,12 +6458,22 @@
takes_args = ["location?"]
- takes_options = ['directory']
+ takes_options = ['directory',
+ Option('force', help='Remove branch even if it is the active branch.')]
aliases = ["rmbranch"]
- def run(self, directory=None, location=None):
+ def run(self, directory=None, location=None, force=False):
br = open_nearby_branch(near=directory, location=location)
+ if not force and br.bzrdir.has_workingtree():
+ try:
+ active_branch = br.bzrdir.open_branch(name="")
+ except errors.NotBranchError:
+ active_branch = None
+ if (active_branch is not None and
+ br.control_url == active_branch.control_url):
+ raise errors.BzrCommandError(
+ gettext("Branch is active. Use --force to remove it."))
br.bzrdir.destroy_branch(br.name)
=== modified file 'bzrlib/tests/blackbox/test_rmbranch.py'
--- a/bzrlib/tests/blackbox/test_rmbranch.py 2012-02-23 16:48:41 +0000
+++ b/bzrlib/tests/blackbox/test_rmbranch.py 2012-02-28 10:10:24 +0000
@@ -28,7 +28,7 @@
class TestRemoveBranch(TestCaseWithTransport):
- def example_branch(self, path='.', format=None):
+ def example_tree(self, path='.', format=None):
tree = self.make_branch_and_tree(path, format=format)
self.build_tree_contents([(path + '/hello', 'foo')])
tree.add('hello')
@@ -40,29 +40,41 @@
def test_remove_local(self):
# Remove a local branch.
- self.example_branch('a')
- self.run_bzr('rmbranch a')
+ tree = self.example_tree('a')
+ self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
+ 'rmbranch a')
+ self.run_bzr('rmbranch --force a')
dir = bzrdir.BzrDir.open('a')
self.assertFalse(dir.has_branch())
self.assertPathExists('a/hello')
self.assertPathExists('a/goodbye')
def test_no_branch(self):
- # No branch in the current directory.
+ # No branch in the current directory.
self.make_repository('a')
self.run_bzr_error(['Not a branch'],
'rmbranch a')
+ def test_no_tree(self):
+ # removing the active branch is possible if there is no tree
+ tree = self.example_tree('a')
+ tree.bzrdir.destroy_workingtree()
+ self.run_bzr('rmbranch', working_dir='a')
+ dir = bzrdir.BzrDir.open('a')
+ self.assertFalse(dir.has_branch())
+
def test_no_arg(self):
# location argument defaults to current directory
- self.example_branch('a')
- self.run_bzr('rmbranch', working_dir='a')
+ self.example_tree('a')
+ self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
+ 'rmbranch a')
+ self.run_bzr('rmbranch --force', working_dir='a')
dir = bzrdir.BzrDir.open('a')
self.assertFalse(dir.has_branch())
def test_remove_colo(self):
# Remove a colocated branch.
- tree = self.example_branch('a')
+ tree = self.example_tree('a')
tree.bzrdir.create_branch(name="otherbranch")
self.assertTrue(tree.bzrdir.has_branch('otherbranch'))
self.run_bzr('rmbranch %s,branch=otherbranch' % tree.bzrdir.user_url)
@@ -72,7 +84,7 @@
def test_remove_colo_directory(self):
# Remove a colocated branch.
- tree = self.example_branch('a')
+ tree = self.example_tree('a')
tree.bzrdir.create_branch(name="otherbranch")
self.assertTrue(tree.bzrdir.has_branch('otherbranch'))
self.run_bzr('rmbranch otherbranch -d %s' % tree.bzrdir.user_url)
@@ -80,6 +92,17 @@
self.assertFalse(dir.has_branch('otherbranch'))
self.assertTrue(dir.has_branch())
+ def test_remove_active_colo_branch(self):
+ # Remove a colocated branch.
+ dir = self.make_repository('a').bzrdir
+ branch = dir.create_branch('otherbranch')
+ branch.create_checkout('a')
+ self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
+ 'rmbranch otherbranch -d %s' % branch.bzrdir.user_url)
+ self.assertTrue(dir.has_branch('otherbranch'))
+ self.run_bzr('rmbranch --force otherbranch -d %s' % branch.bzrdir.user_url)
+ self.assertFalse(dir.has_branch('otherbranch'))
+
class TestSmartServerRemoveBranch(TestCaseWithTransport):
=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- a/doc/en/release-notes/bzr-2.6.txt 2012-02-28 10:02:24 +0000
+++ b/doc/en/release-notes/bzr-2.6.txt 2012-02-28 10:06:39 +0000
@@ -37,6 +37,9 @@
* ``bzr rmbranch`` now supports removing colocated branches.
(Jelmer Vernooij, #920653)
+* ``bzr rmbranch`` no longer removes active branches unless ``--force``
+ is specified. (Jelmer Vernooij, #922953)
+
* Two new command hooks, ``pre_command`` and ``post_command``,
provide notification before and after a command has been run.
(Brian de Alwis, Jelmer Vernooij)
More information about the bazaar-commits
mailing list