Merge lp:~abentley/bzr/switch2 into lp:~bzr/bzr/trunk-old

Proposed by Aaron Bentley
Status: Merged
Merged at revision: not available
Proposed branch: lp:~abentley/bzr/switch2
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 78 lines
To merge this branch: bzr merge lp:~abentley/bzr/switch2
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+6593@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

This patch fixes switch for lightweight checkouts, so that when the
branch is moved, --force can be used to select the new branch.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkoMgLgACgkQ0F+nu1YWqI35/ACggWmRDO+GLjf5CFhVlaMRnzgl
WHYAn3K+yw8EHeSvkOQsesuU3WIOFT08
=/B60
-----END PGP SIGNATURE-----

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aaron Bentley wrote:
> Aaron Bentley has proposed merging lp:~abentley/bzr/switch2 into lp:bzr.
>
> Requested reviews:
> Bazaar Developers (bzr)
>
> Hi all,
>
> This patch fixes switch for lightweight checkouts, so that when the
> branch is moved, --force can be used to select the new branch.
>
> Aaron

 review: approve

Looks fine to me.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkoMhW4ACgkQJdeBCYSNAAPGNwCffWIj7bgsW5R/sLw+RxIjp/Vi
s+cAoIAZHgc7eBwHUMnwYH9ivVajYNpg
=KzRT
-----END PGP SIGNATURE-----

review: Approve

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 2009-05-14 02:18:57 +0000
+++ bzrlib/builtins.py 2009-05-15 00:35:13 +0000
@@ -5304,25 +5304,41 @@
5304 from bzrlib import switch5304 from bzrlib import switch
5305 tree_location = '.'5305 tree_location = '.'
5306 control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]5306 control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5307 branch = control_dir.open_branch()5307 try:
5308 branch = control_dir.open_branch()
5309 had_explicit_nick = branch.get_config().has_explicit_nickname()
5310 except errors.NotBranchError:
5311 had_explicit_nick = False
5308 try:5312 try:
5309 to_branch = Branch.open(to_location)5313 to_branch = Branch.open(to_location)
5310 except errors.NotBranchError:5314 except errors.NotBranchError:
5311 this_branch = control_dir.open_branch()5315 this_url = self._get_branch_location(control_dir)
5312 # This may be a heavy checkout, where we want the master branch
5313 this_url = this_branch.get_bound_location()
5314 # If not, use a local sibling
5315 if this_url is None:
5316 this_url = this_branch.base
5317 to_branch = Branch.open(5316 to_branch = Branch.open(
5318 urlutils.join(this_url, '..', to_location))5317 urlutils.join(this_url, '..', to_location))
5319 switch.switch(control_dir, to_branch, force)5318 switch.switch(control_dir, to_branch, force)
5320 if branch.get_config().has_explicit_nickname():5319 if had_explicit_nick:
5321 branch = control_dir.open_branch() #get the new branch!5320 branch = control_dir.open_branch() #get the new branch!
5322 branch.nick = to_branch.nick5321 branch.nick = to_branch.nick
5323 note('Switched to branch: %s',5322 note('Switched to branch: %s',
5324 urlutils.unescape_for_display(to_branch.base, 'utf-8'))5323 urlutils.unescape_for_display(to_branch.base, 'utf-8'))
53255324
5325 def _get_branch_location(self, control_dir):
5326 """Return location of branch for this control dir."""
5327 try:
5328 this_branch = control_dir.open_branch()
5329 # This may be a heavy checkout, where we want the master branch
5330 master_location = this_branch.get_bound_location()
5331 if master_location is not None:
5332 return master_location
5333 # If not, use a local sibling
5334 return this_branch.base
5335 except errors.NotBranchError:
5336 format = control_dir.find_branch_format()
5337 if getattr(format, 'get_reference', None) is not None:
5338 return format.get_reference(control_dir)
5339 else:
5340 return control_dir.root_transport.base
5341
53265342
5327class cmd_view(Command):5343class cmd_view(Command):
5328 """Manage filtered views.5344 """Manage filtered views.
53295345
=== modified file 'bzrlib/tests/blackbox/test_switch.py'
--- bzrlib/tests/blackbox/test_switch.py 2009-03-23 14:59:43 +0000
+++ bzrlib/tests/blackbox/test_switch.py 2009-05-15 00:35:13 +0000
@@ -133,3 +133,20 @@
133 self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')133 self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
134 self.assertEqual(branchb_id, checkout.last_revision())134 self.assertEqual(branchb_id, checkout.last_revision())
135 self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())135 self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
136
137 def prepare_lightweight_switch(self):
138 branch = self.make_branch('branch')
139 branch.create_checkout('tree', lightweight=True)
140 os.rename('branch', 'branch1')
141
142 def test_switch_lightweight_after_branch_moved(self):
143 self.prepare_lightweight_switch()
144 self.run_bzr('switch --force ../branch1', working_dir='tree')
145 branch_location = WorkingTree.open('tree').branch.base
146 self.assertEndsWith(branch_location, 'branch1/')
147
148 def test_switch_lightweight_after_branch_moved_relative(self):
149 self.prepare_lightweight_switch()
150 self.run_bzr('switch --force branch1', working_dir='tree')
151 branch_location = WorkingTree.open('tree').branch.base
152 self.assertEndsWith(branch_location, 'branch1/')