Merge lp:~abudden/bzr/switch_parent_513709 into lp:bzr

Proposed by Dr Al
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 5835
Proposed branch: lp:~abudden/bzr/switch_parent_513709
Merge into: lp:bzr
Diff against target: 177 lines (+101/-4)
5 files modified
bzrlib/branch.py (+5/-1)
bzrlib/switch.py (+1/-0)
bzrlib/tests/blackbox/test_branch.py (+31/-0)
bzrlib/tests/blackbox/test_switch.py (+61/-3)
doc/en/release-notes/bzr-2.4.txt (+3/-0)
To merge this branch: bzr merge lp:~abudden/bzr/switch_parent_513709
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+59924@code.launchpad.net

Commit message

Set correct parent when using 'switch -b' with bound branches (Fix for Bug #513709).

Description of the change

Work in progress towards fixing Bug 513709.

To post a comment you must log in.
Revision history for this message
Dr Al (abudden) wrote :

The background for this (in addition to the bug report) is I'd really like to see the "changes relative to parent" view when using bound branches with a feature branch model. I think this is the first change that is required, but in Bazaar Explorer's view_workingtree.py there is the comment:

        # Display the delta versus the submit branch iff one is
        # defined and it's local. Unfortunately though, merging a feature
        # branch into trunk sets the merged-from branch as the submit
        # branch which means we see a "silly" submit delta panel for trunk.
        # To work around that, we don't show the panel for bound branches
        # as trunk ought to be bound. We could look for the name
        # "trunk" instead but that sounds even more of a hack. :-(

I'd also like to explore the background to this as this means even with this merge proposal, I can only view the changes if I open the master branch and not if I open the bound branch.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Thanks for working on this !

I've simplified the tests a bit (avoiding the code duplication) and put my changes at lp:~vila/bzr/switch_parent_513709 if you agree with them, just merge them in your own branch.

Now for the patch:

9 + bound_branch = self.get_master_branch()

Is confusing, this should be called master since this is what the branch is bound to.

Don't forget to add a news entry in the doc/en/release-notes/bzr-2.4 txt file.

Also, we need you to execute the contributor agreement http://www.canonical.com/contributors to be able to accept your patch.

I'll put this proposal into 'Work In Progress', put it back in 'NeedsReview' when needed.

review: Needs Fixing
Revision history for this message
Dr Al (abudden) wrote :

Okay, I've pushed those changes and sent the Canonical Contributors agreement to Martin Pool, <email address hidden> and you (Vincent).

On a note that's not related to this merge proposal, on http://www.canonical.com/contributors, there are two links to the PDF, one in the third paragraph just after "easy to understand" and one under item 1 of "How to submit it by email". The latter link doesn't work.

Revision history for this message
Martin Pool (mbp) wrote :

On 6 May 2011 09:21, Dr Al <email address hidden> wrote:
> Okay, I've pushed those changes and sent the Canonical Contributors agreement to Martin Pool, <email address hidden> and you (Vincent).

Got it, thanks.

>
> On a note that's not related to this merge proposal, on http://www.canonical.com/contributors, there are two links to the PDF, one in the third paragraph just after "easy to understand" and one under item 1 of "How to submit it by email".  The latter link doesn't work.

Thanks, bug 778334.

Revision history for this message
Vincent Ladeuil (vila) wrote :

> Okay, I've pushed those changes and sent the Canonical Contributors agreement
> to Martin Pool, <email address hidden> and you (Vincent).

Great, thanks !

>
> On a note that's not related to this merge proposal, on
> http://www.canonical.com/contributors, there are two links to the PDF, one in
> the third paragraph just after "easy to understand" and one under item 1 of
> "How to submit it by email". The latter link doesn't work.

Nice catch !

Marting was faster than me and filed bug #778334 :)

I'll land and update the bug page.

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/branch.py'
2--- bzrlib/branch.py 2011-04-27 11:25:28 +0000
3+++ bzrlib/branch.py 2011-05-06 07:26:44 +0000
4@@ -1271,7 +1271,11 @@
5 if repository_policy is not None:
6 repository_policy.configure_branch(result)
7 self.copy_content_into(result, revision_id=revision_id)
8- result.set_parent(self.bzrdir.root_transport.base)
9+ master_branch = self.get_master_branch()
10+ if master_branch is None:
11+ result.set_parent(self.bzrdir.root_transport.base)
12+ else:
13+ result.set_parent(master_branch.bzrdir.root_transport.base)
14 finally:
15 result.unlock()
16 return result
17
18=== modified file 'bzrlib/switch.py'
19--- bzrlib/switch.py 2010-05-07 11:50:28 +0000
20+++ bzrlib/switch.py 2011-05-06 07:26:44 +0000
21@@ -103,6 +103,7 @@
22 b.pull(to_branch, overwrite=True,
23 possible_transports=possible_transports)
24 b.set_bound_location(to_branch.base)
25+ b.set_parent(b.get_master_branch().get_parent())
26 else:
27 raise errors.BzrCommandError('Cannot switch a branch, '
28 'only a checkout.')
29
30=== modified file 'bzrlib/tests/blackbox/test_branch.py'
31--- bzrlib/tests/blackbox/test_branch.py 2011-04-19 04:37:48 +0000
32+++ bzrlib/tests/blackbox/test_branch.py 2011-05-06 07:26:44 +0000
33@@ -30,8 +30,10 @@
34 from bzrlib.tests import (
35 fixtures,
36 HardlinkFeature,
37+ script,
38 test_server,
39 )
40+from bzrlib.tests.blackbox import test_switch
41 from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
42 from bzrlib.tests.script import run_script
43 from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
44@@ -516,3 +518,32 @@
45 2>The command 'bzr %(command)s' has been deprecated in bzr 2.4. Please use 'bzr branch' instead.
46 2>bzr: ERROR: Not a branch...
47 """ % locals())
48+
49+
50+class TestBranchParentLocation(test_switch.TestSwitchParentLocationBase):
51+
52+ def _checkout_and_branch(self, option=''):
53+ self.script_runner.run_script(self, '''
54+ $ bzr checkout %(option)s repo/trunk checkout
55+ $ cd checkout
56+ $ bzr branch --switch ../repo/trunk ../repo/branched
57+ 2>Branched 0 revision(s).
58+ 2>Tree is up to date at revision 0.
59+ 2>Switched to branch:...branched...
60+ $ cd ..
61+ ''' % locals())
62+ bound_branch = branch.Branch.open_containing('checkout')[0]
63+ master_branch = branch.Branch.open_containing('repo/branched')[0]
64+ return (bound_branch, master_branch)
65+
66+ def test_branch_switch_parent_lightweight(self):
67+ """Lightweight checkout using bzr branch --switch."""
68+ bb, mb = self._checkout_and_branch(option='--lightweight')
69+ self.assertParent('repo/trunk', bb)
70+ self.assertParent('repo/trunk', mb)
71+
72+ def test_branch_switch_parent_heavyweight(self):
73+ """Heavyweight checkout using bzr branch --switch."""
74+ bb, mb = self._checkout_and_branch()
75+ self.assertParent('repo/trunk', bb)
76+ self.assertParent('repo/trunk', mb)
77
78=== modified file 'bzrlib/tests/blackbox/test_switch.py'
79--- bzrlib/tests/blackbox/test_switch.py 2011-04-15 07:01:22 +0000
80+++ bzrlib/tests/blackbox/test_switch.py 2011-05-06 07:26:44 +0000
81@@ -20,9 +20,16 @@
82
83 import os
84
85-from bzrlib import osutils
86+from bzrlib import (
87+ osutils,
88+ urlutils,
89+ branch,
90+ )
91 from bzrlib.workingtree import WorkingTree
92-from bzrlib.tests import TestCaseWithTransport
93+from bzrlib.tests import (
94+ TestCaseWithTransport,
95+ script,
96+ )
97 from bzrlib.directory_service import directories
98
99
100@@ -129,7 +136,7 @@
101 """Using switch on a heavy checkout should find master sibling
102
103 The behaviour of lighweight and heavy checkouts should be
104- consistentwhen using the convenient "switch to sibling" feature
105+ consistent when using the convenient "switch to sibling" feature
106 Both should switch to a sibling of the branch
107 they are bound to, and not a sibling of themself"""
108
109@@ -270,3 +277,54 @@
110 self.run_bzr('checkout --lightweight a checkout')
111 self.run_bzr('switch --directory checkout b')
112 self.assertFileEqual('initial\nmore\n', 'checkout/a')
113+
114+class TestSwitchParentLocationBase(TestCaseWithTransport):
115+
116+ def setUp(self):
117+ """Set up a repository and branch ready for testing."""
118+ super(TestSwitchParentLocationBase, self).setUp()
119+ self.script_runner = script.ScriptRunner()
120+ self.script_runner.run_script(self, '''
121+ $ bzr init-repo --no-trees repo
122+ Shared repository...
123+ Location:
124+ shared repository: repo
125+ $ bzr init repo/trunk
126+ Created a repository branch...
127+ Using shared repository: ...
128+ ''')
129+
130+ def assertParent(self, expected_parent, branch):
131+ """Verify that the parent is not None and is set correctly."""
132+ actual_parent = branch.get_parent()
133+ self.assertIsSameRealPath(urlutils.local_path_to_url(expected_parent),
134+ branch.get_parent())
135+
136+
137+class TestSwitchParentLocation(TestSwitchParentLocationBase):
138+
139+ def _checkout_and_switch(self, option=''):
140+ self.script_runner.run_script(self, '''
141+ $ bzr checkout %(option)s repo/trunk checkout
142+ $ cd checkout
143+ $ bzr switch --create-branch switched
144+ 2>Tree is up to date at revision 0.
145+ 2>Switched to branch:...switched...
146+ $ cd ..
147+ ''' % locals())
148+ bound_branch = branch.Branch.open_containing('checkout')[0]
149+ master_branch = branch.Branch.open_containing('repo/switched')[0]
150+ return (bound_branch, master_branch)
151+
152+ def test_switch_parent_lightweight(self):
153+ """Lightweight checkout using bzr switch."""
154+ bb, mb = self._checkout_and_switch(option='--lightweight')
155+ self.assertParent('repo/trunk', bb)
156+ self.assertParent('repo/trunk', mb)
157+
158+ def test_switch_parent_heavyweight(self):
159+ """Heavyweight checkout using bzr switch."""
160+ bb, mb = self._checkout_and_switch()
161+ self.assertParent('repo/trunk', bb)
162+ self.assertParent('repo/trunk', mb)
163+
164
165=== modified file 'doc/en/release-notes/bzr-2.4.txt'
166--- doc/en/release-notes/bzr-2.4.txt 2011-05-05 15:26:26 +0000
167+++ doc/en/release-notes/bzr-2.4.txt 2011-05-06 07:26:44 +0000
168@@ -37,6 +37,9 @@
169
170 * All Tree types can now be exported as tar.*, zip or directories.
171 (Aaron Bentley)
172+
173+* Correct parent is now set when using 'switch -b' with bound branches.
174+ (A. S. Budden, #513709)
175
176 Documentation
177 *************