Rev 6449: (jelmer) Support switching a colocated branch in a standalone branch. in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/

Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jan 19 15:03:39 UTC 2012


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

------------------------------------------------------------
revno: 6449 [merge]
revision-id: pqm at pqm.ubuntu.com-20120119150338-i8nablep809146e1
parent: pqm at pqm.ubuntu.com-20120119140950-vyytyv8gf83qynav
parent: jelmer at samba.org-20120119123622-0tv72e20v53k8oxa
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.5
timestamp: Thu 2012-01-19 15:03:38 +0000
message:
  (jelmer) Support switching a colocated branch in a standalone branch.
   (Jelmer Vernooij)
modified:
  bzrlib/switch.py               switch.py-20071116011000-v5lnw7d2wkng9eux-1
  bzrlib/tests/blackbox/test_switch.py test_switch.py-20071122111948-0c5en6uz92bwl76h-1
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/switch.py'
--- a/bzrlib/switch.py	2011-12-18 15:28:38 +0000
+++ b/bzrlib/switch.py	2012-01-18 19:14:21 +0000
@@ -107,8 +107,17 @@
             b.set_bound_location(to_branch.base)
             b.set_parent(b.get_master_branch().get_parent())
         else:
-            raise errors.BzrCommandError(gettext('Cannot switch a branch, '
-                'only a checkout.'))
+            # If this is a standalone tree and the new branch
+            # is derived from this one, create a lightweight checkout.
+            graph = b.repository.get_graph(to_branch.repository)
+            if (b.bzrdir._format.colocated_branches and
+                 (force or graph.is_ancestor(b.last_revision(),
+                    to_branch.last_revision()))):
+                b.bzrdir.destroy_branch()
+                b.bzrdir.set_branch_reference(to_branch, name="")
+            else:
+                raise errors.BzrCommandError(gettext('Cannot switch a branch, '
+                    'only a checkout.'))
 
 
 def _any_local_commits(this_branch, possible_transports):

=== modified file 'bzrlib/tests/blackbox/test_switch.py'
--- a/bzrlib/tests/blackbox/test_switch.py	2012-01-18 17:47:06 +0000
+++ b/bzrlib/tests/blackbox/test_switch.py	2012-01-19 12:36:22 +0000
@@ -178,6 +178,32 @@
         self.assertPathExists('checkout/file-1')
         self.assertPathDoesNotExist('checkout/file-2')
 
+    def test_switch_into_colocated(self):
+        # Create a new colocated branch from an existing non-colocated branch.
+        tree = self.make_branch_and_tree('.', format='development-colo')
+        self.build_tree(['file-1', 'file-2'])
+        tree.add('file-1')
+        revid1 = tree.commit('rev1')
+        tree.add('file-2')
+        revid2 = tree.commit('rev2')
+        self.run_bzr(['switch', '-b', 'anotherbranch'])
+        self.assertEquals(
+            ['', 'anotherbranch'],
+            tree.branch.bzrdir.get_branches().keys())
+
+    def test_switch_into_unrelated_colocated(self):
+        # Create a new colocated branch from an existing non-colocated branch.
+        tree = self.make_branch_and_tree('.', format='development-colo')
+        self.build_tree(['file-1', 'file-2'])
+        tree.add('file-1')
+        revid1 = tree.commit('rev1')
+        tree.add('file-2')
+        revid2 = tree.commit('rev2')
+        tree.bzrdir.create_branch(name='foo')
+        self.run_bzr_error(['Cannot switch a branch, only a checkout.'],
+            'switch foo')
+        self.run_bzr(['switch', '--force', 'foo'])
+
     def test_switch_existing_colocated(self):
         # Create a branch branch-1 that initially is a checkout of 'foo'
         # Use switch to change it to 'anotherbranch'

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2012-01-19 14:09:50 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2012-01-19 15:03:38 +0000
@@ -26,6 +26,9 @@
 .. Improvements to existing commands, especially improved performance 
    or memory usage, or better results.
 
+* "bzr switch -b" in a standalone tree will now create a colocated branch.
+  (Jelmer Vernooij, #918197)
+
 Bug Fixes
 *********
 




More information about the bazaar-commits mailing list