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

Proposed by Aaron Bentley on 2009-05-14
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 2009-05-14 Approve on 2009-05-14
Review via email: mp+6593@code.launchpad.net
To post a comment you must log in.
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-----

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
1=== modified file 'bzrlib/builtins.py'
2--- bzrlib/builtins.py 2009-05-14 02:18:57 +0000
3+++ bzrlib/builtins.py 2009-05-15 00:35:13 +0000
4@@ -5304,25 +5304,41 @@
5 from bzrlib import switch
6 tree_location = '.'
7 control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
8- branch = control_dir.open_branch()
9+ try:
10+ branch = control_dir.open_branch()
11+ had_explicit_nick = branch.get_config().has_explicit_nickname()
12+ except errors.NotBranchError:
13+ had_explicit_nick = False
14 try:
15 to_branch = Branch.open(to_location)
16 except errors.NotBranchError:
17- this_branch = control_dir.open_branch()
18- # This may be a heavy checkout, where we want the master branch
19- this_url = this_branch.get_bound_location()
20- # If not, use a local sibling
21- if this_url is None:
22- this_url = this_branch.base
23+ this_url = self._get_branch_location(control_dir)
24 to_branch = Branch.open(
25 urlutils.join(this_url, '..', to_location))
26 switch.switch(control_dir, to_branch, force)
27- if branch.get_config().has_explicit_nickname():
28+ if had_explicit_nick:
29 branch = control_dir.open_branch() #get the new branch!
30 branch.nick = to_branch.nick
31 note('Switched to branch: %s',
32 urlutils.unescape_for_display(to_branch.base, 'utf-8'))
33
34+ def _get_branch_location(self, control_dir):
35+ """Return location of branch for this control dir."""
36+ try:
37+ this_branch = control_dir.open_branch()
38+ # This may be a heavy checkout, where we want the master branch
39+ master_location = this_branch.get_bound_location()
40+ if master_location is not None:
41+ return master_location
42+ # If not, use a local sibling
43+ return this_branch.base
44+ except errors.NotBranchError:
45+ format = control_dir.find_branch_format()
46+ if getattr(format, 'get_reference', None) is not None:
47+ return format.get_reference(control_dir)
48+ else:
49+ return control_dir.root_transport.base
50+
51
52 class cmd_view(Command):
53 """Manage filtered views.
54
55=== modified file 'bzrlib/tests/blackbox/test_switch.py'
56--- bzrlib/tests/blackbox/test_switch.py 2009-03-23 14:59:43 +0000
57+++ bzrlib/tests/blackbox/test_switch.py 2009-05-15 00:35:13 +0000
58@@ -133,3 +133,20 @@
59 self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
60 self.assertEqual(branchb_id, checkout.last_revision())
61 self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
62+
63+ def prepare_lightweight_switch(self):
64+ branch = self.make_branch('branch')
65+ branch.create_checkout('tree', lightweight=True)
66+ os.rename('branch', 'branch1')
67+
68+ def test_switch_lightweight_after_branch_moved(self):
69+ self.prepare_lightweight_switch()
70+ self.run_bzr('switch --force ../branch1', working_dir='tree')
71+ branch_location = WorkingTree.open('tree').branch.base
72+ self.assertEndsWith(branch_location, 'branch1/')
73+
74+ def test_switch_lightweight_after_branch_moved_relative(self):
75+ self.prepare_lightweight_switch()
76+ self.run_bzr('switch --force branch1', working_dir='tree')
77+ branch_location = WorkingTree.open('tree').branch.base
78+ self.assertEndsWith(branch_location, 'branch1/')