Rev 4367: (abentley) lightweight checkouts with stale locations can be switched in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu May 14 23:23:43 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4367
revision-id: pqm at pqm.ubuntu.com-20090514222335-85rfl946254b3vk2
parent: pqm at pqm.ubuntu.com-20090514182944-yz4v4ggktei02wo0
parent: aaron at aaronbentley.com-20090514163306-sj14ehll0fghp24k
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-05-14 23:23:35 +0100
message:
  (abentley) lightweight checkouts with stale locations can be switched
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/test_switch.py test_switch.py-20071122111948-0c5en6uz92bwl76h-1
    ------------------------------------------------------------
    revno: 4354.2.2
    revision-id: aaron at aaronbentley.com-20090514163306-sj14ehll0fghp24k
    parent: aaron at aaronbentley.com-20090514161004-vnof1g5j0kburnw5
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: switch2
    timestamp: Thu 2009-05-14 12:33:06 -0400
    message:
      Enable switch --force for lightweight checkouts after moves.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/tests/blackbox/test_switch.py test_switch.py-20071122111948-0c5en6uz92bwl76h-1
    ------------------------------------------------------------
    revno: 4354.2.1
    revision-id: aaron at aaronbentley.com-20090514161004-vnof1g5j0kburnw5
    parent: pqm at pqm.ubuntu.com-20090512090530-v9355ohetp61ltc1
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: switch2
    timestamp: Thu 2009-05-14 12:10:04 -0400
    message:
      Improve switch --force with lightweight checkouts.
    modified:
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-05-14 02:18:57 +0000
+++ b/bzrlib/builtins.py	2009-05-14 22:23:35 +0000
@@ -5304,25 +5304,41 @@
         from bzrlib import switch
         tree_location = '.'
         control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
-        branch = control_dir.open_branch()
+        try:
+            branch = control_dir.open_branch()
+            had_explicit_nick = branch.get_config().has_explicit_nickname()
+        except errors.NotBranchError:
+            had_explicit_nick = False
         try:
             to_branch = Branch.open(to_location)
         except errors.NotBranchError:
-            this_branch = control_dir.open_branch()
-            # This may be a heavy checkout, where we want the master branch
-            this_url = this_branch.get_bound_location()
-            # If not, use a local sibling
-            if this_url is None:
-                this_url = this_branch.base
+            this_url = self._get_branch_location(control_dir)
             to_branch = Branch.open(
                 urlutils.join(this_url, '..', to_location))
         switch.switch(control_dir, to_branch, force)
-        if branch.get_config().has_explicit_nickname():
+        if had_explicit_nick:
             branch = control_dir.open_branch() #get the new branch!
             branch.nick = to_branch.nick
         note('Switched to branch: %s',
             urlutils.unescape_for_display(to_branch.base, 'utf-8'))
 
+    def _get_branch_location(self, control_dir):
+        """Return location of branch for this control dir."""
+        try:
+            this_branch = control_dir.open_branch()
+            # This may be a heavy checkout, where we want the master branch
+            master_location = this_branch.get_bound_location()
+            if master_location is not None:
+                return master_location
+            # If not, use a local sibling
+            return this_branch.base
+        except errors.NotBranchError:
+            format = control_dir.find_branch_format()
+            if getattr(format, 'get_reference', None) is not None:
+                return format.get_reference(control_dir)
+            else:
+                return control_dir.root_transport.base
+
 
 class cmd_view(Command):
     """Manage filtered views.

=== modified file 'bzrlib/tests/blackbox/test_switch.py'
--- a/bzrlib/tests/blackbox/test_switch.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_switch.py	2009-05-14 16:33:06 +0000
@@ -133,3 +133,20 @@
         self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
         self.assertEqual(branchb_id, checkout.last_revision())
         self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
+
+    def prepare_lightweight_switch(self):
+        branch = self.make_branch('branch')
+        branch.create_checkout('tree', lightweight=True)
+        os.rename('branch', 'branch1')
+
+    def test_switch_lightweight_after_branch_moved(self):
+        self.prepare_lightweight_switch()
+        self.run_bzr('switch --force ../branch1', working_dir='tree')
+        branch_location = WorkingTree.open('tree').branch.base
+        self.assertEndsWith(branch_location, 'branch1/')
+
+    def test_switch_lightweight_after_branch_moved_relative(self):
+        self.prepare_lightweight_switch()
+        self.run_bzr('switch --force branch1', working_dir='tree')
+        branch_location = WorkingTree.open('tree').branch.base
+        self.assertEndsWith(branch_location, 'branch1/')




More information about the bazaar-commits mailing list