Rev 6466: (jelmer) Raise NotBranchError from BzrDir.destroy_branch. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/

Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jan 31 16:10:49 UTC 2012


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/

------------------------------------------------------------
revno: 6466 [merge]
revision-id: pqm at pqm.ubuntu.com-20120131161049-cz8sy2sy2g0vk356
parent: pqm at pqm.ubuntu.com-20120128030657-jeig9rj6gbh078ug
parent: jelmer at samba.org-20120131154317-y028tz0r9xesvn9p
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.5
timestamp: Tue 2012-01-31 16:10:49 +0000
message:
  (jelmer) Raise NotBranchError from BzrDir.destroy_branch. (Jelmer Vernooij)
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/controldir.py           controldir.py-20100802102926-hvtvh0uae5epuibp-1
  bzrlib/tests/blackbox/test_rmbranch.py test_rmbranch.py-20100131150653-auenl06hu4y2d9tr-1
  bzrlib/tests/per_controldir/test_controldir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2012-01-28 00:41:30 +0000
+++ b/bzrlib/builtins.py	2012-01-31 15:43:17 +0000
@@ -6454,8 +6454,8 @@
     def run(self, location=None):
         if location is None:
             location = "."
-        branch = Branch.open_containing(location)[0]
-        branch.bzrdir.destroy_branch()
+        cdir = controldir.ControlDir.open_containing(location)[0]
+        cdir.destroy_branch()
 
 
 class cmd_shelve(Command):

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2012-01-28 02:05:52 +0000
+++ b/bzrlib/bzrdir.py	2012-01-31 15:43:17 +0000
@@ -862,7 +862,7 @@
 
     def create_branch(self, name=None, repository=None,
             append_revisions_only=None):
-        """See BzrDir.create_branch."""
+        """See ControlDir.create_branch."""
         if name is None:
             name = self._get_selected_branch()
         return self._format.get_branch_format().initialize(self, name=name,
@@ -870,7 +870,7 @@
                 append_revisions_only=append_revisions_only)
 
     def destroy_branch(self, name=None):
-        """See BzrDir.create_branch."""
+        """See ControlDir.destroy_branch."""
         if name is None:
             name = self._get_selected_branch()
         path = self._get_branch_path(name)
@@ -885,7 +885,11 @@
                 self._write_branch_list(branches)
             finally:
                 self.control_files.unlock()
-        self.transport.delete_tree(path)
+        try:
+            self.transport.delete_tree(path)
+        except errors.NoSuchFile:
+            raise errors.NotBranchError(path=urlutils.join(self.transport.base,
+                path), bzrdir=self)
 
     def create_repository(self, shared=False):
         """See BzrDir.create_repository."""

=== modified file 'bzrlib/controldir.py'
--- a/bzrlib/controldir.py	2012-01-27 14:01:25 +0000
+++ b/bzrlib/controldir.py	2012-01-31 15:43:17 +0000
@@ -163,7 +163,7 @@
         """Create a branch in this ControlDir.
 
         :param name: Name of the colocated branch to create, None for
-            the default branch.
+            the user selected branch or "" for the active branch.
         :param append_revisions_only: Whether this branch should only allow
             appending new revisions to its history.
 
@@ -175,8 +175,9 @@
     def destroy_branch(self, name=None):
         """Destroy a branch in this ControlDir.
 
-        :param name: Name of the branch to destroy, None for the default 
-            branch.
+        :param name: Name of the branch to destroy, None for the 
+            user selected branch or "" for the active branch.
+        :raise NotBranchError: When the branch does not exist
         """
         raise NotImplementedError(self.destroy_branch)
 
@@ -302,7 +303,7 @@
     def _get_selected_branch(self):
         """Return the name of the branch selected by the user.
 
-        :return: Name of the branch selected by the user, or None.
+        :return: Name of the branch selected by the user, or "".
         """
         branch = self.root_transport.get_segment_parameters().get("branch")
         if branch is None:

=== modified file 'bzrlib/tests/blackbox/test_rmbranch.py'
--- a/bzrlib/tests/blackbox/test_rmbranch.py	2011-12-14 20:21:52 +0000
+++ b/bzrlib/tests/blackbox/test_rmbranch.py	2012-01-25 17:31:04 +0000
@@ -83,6 +83,6 @@
         # being too low. If rpc_count increases, more network roundtrips have
         # become necessary for this use case. Please do not adjust this number
         # upwards without agreement from bzr's network support maintainers.
-        self.assertLength(5, self.hpss_calls)
+        self.assertLength(2, self.hpss_calls)
         self.assertLength(1, self.hpss_connections)
         self.assertThat(self.hpss_calls, ContainsNoVfsCalls)

=== modified file 'bzrlib/tests/per_controldir/test_controldir.py'
--- a/bzrlib/tests/per_controldir/test_controldir.py	2012-01-18 20:27:41 +0000
+++ b/bzrlib/tests/per_controldir/test_controldir.py	2012-01-25 17:31:04 +0000
@@ -159,6 +159,14 @@
         bzrdir.create_branch()
         bzrdir.open_branch()
 
+    def test_destroy_branch_no_branch(self):
+        branch = self.make_repository('branch')
+        bzrdir = branch.bzrdir
+        try:
+            self.assertRaises(errors.NotBranchError, bzrdir.destroy_branch)
+        except (errors.UnsupportedOperation, errors.TransportNotPossible):
+            raise TestNotApplicable('Format does not support destroying branch')
+
     def test_destroy_repository(self):
         repo = self.make_repository('repository')
         bzrdir = repo.bzrdir

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2012-01-28 00:41:30 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2012-01-31 15:43:17 +0000
@@ -86,6 +86,9 @@
 * ``ControlDir`` now has a new method ``set_branch_reference`` which can
   be used for setting branch references. (Jelmer Vernooij)
 
+* ``ControlDir.destroy_branch`` now raises ``NotBranchError`` rather than
+  ``NoSuchFile`` if the branch didn't exist. (Jelmer Vernooij, #921693)
+
 Internals
 *********
 




More information about the bazaar-commits mailing list