bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
5557.1.15
by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt |
1 |
# Copyright (C) 2007-2011 Canonical Ltd
|
|
2999.1.1
by Ian Clatworthy
migrate switch command into the core - was in BzrTools |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
2999.1.1
by Ian Clatworthy
migrate switch command into the core - was in BzrTools |
16 |
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
17 |
"""Tests for breezy.switch."""
|
|
2999.1.1
by Ian Clatworthy
migrate switch command into the core - was in BzrTools |
18 |
|
19 |
||
20 |
import os |
|
21 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
22 |
from breezy import ( |
|
5162.3.1
by Aaron Bentley
Fix switch/merge when a ConfigurableFileMerger is used. |
23 |
branch, |
24 |
errors, |
|
25 |
merge as _mod_merge, |
|
26 |
switch, |
|
27 |
tests, |
|
|
6538.1.15
by Aaron Bentley
Switch.switch stores and restores changes. |
28 |
workingtree, |
|
5579.3.1
by Jelmer Vernooij
Remove unused imports. |
29 |
)
|
|
2999.1.1
by Ian Clatworthy
migrate switch command into the core - was in BzrTools |
30 |
|
31 |
||
32 |
class TestSwitch(tests.TestCaseWithTransport): |
|
33 |
||
|
3078.2.2
by Ian Clatworthy
get switch tests passing on heavyweight checkouts |
34 |
def setUp(self): |
35 |
super(TestSwitch, self).setUp() |
|
36 |
self.lightweight = True |
|
37 |
||
|
6538.1.15
by Aaron Bentley
Switch.switch stores and restores changes. |
38 |
@staticmethod
|
39 |
def _master_if_present(branch): |
|
40 |
master = branch.get_master_branch() |
|
41 |
if master: |
|
42 |
return master |
|
43 |
else: |
|
44 |
return branch |
|
45 |
||
|
2999.1.3
by Ian Clatworthy
fix pending merge detection and test |
46 |
def _setup_tree(self): |
|
2999.1.1
by Ian Clatworthy
migrate switch command into the core - was in BzrTools |
47 |
tree = self.make_branch_and_tree('branch-1') |
48 |
self.build_tree(['branch-1/file-1']) |
|
49 |
tree.add('file-1') |
|
50 |
tree.commit('rev1') |
|
|
2999.1.3
by Ian Clatworthy
fix pending merge detection and test |
51 |
return tree |
|
2999.1.1
by Ian Clatworthy
migrate switch command into the core - was in BzrTools |
52 |
|
|
6538.1.16
by Aaron Bentley
Restore uncommitted changes even if revisions are same. |
53 |
def _setup_uncommitted(self, same_revision=False): |
|
6538.1.15
by Aaron Bentley
Switch.switch stores and restores changes. |
54 |
tree = self._setup_tree() |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
55 |
to_branch = tree.controldir.sprout('branch-2').open_branch() |
|
6538.1.15
by Aaron Bentley
Switch.switch stores and restores changes. |
56 |
self.build_tree(['branch-1/file-2']) |
|
6538.1.16
by Aaron Bentley
Restore uncommitted changes even if revisions are same. |
57 |
if not same_revision: |
58 |
tree.add('file-2') |
|
59 |
tree.remove('file-1') |
|
60 |
tree.commit('rev2') |
|
|
6538.1.15
by Aaron Bentley
Switch.switch stores and restores changes. |
61 |
checkout = tree.branch.create_checkout('checkout', |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
62 |
lightweight=self.lightweight) |
|
6538.1.15
by Aaron Bentley
Switch.switch stores and restores changes. |
63 |
self.build_tree(['checkout/file-3']) |
64 |
checkout.add('file-3') |
|
65 |
return checkout, to_branch |
|
66 |
||
67 |
def test_switch_store_uncommitted(self): |
|
68 |
"""Test switch updates tree and stores uncommitted changes.""" |
|
69 |
checkout, to_branch = self._setup_uncommitted() |
|
70 |
self.assertPathDoesNotExist('checkout/file-1') |
|
71 |
self.assertPathExists('checkout/file-2') |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
72 |
switch.switch(checkout.controldir, to_branch, store_uncommitted=True) |
|
6538.1.15
by Aaron Bentley
Switch.switch stores and restores changes. |
73 |
self.assertPathExists('checkout/file-1') |
74 |
self.assertPathDoesNotExist('checkout/file-2') |
|
75 |
self.assertPathDoesNotExist('checkout/file-3') |
|
76 |
||
77 |
def test_switch_restore_uncommitted(self): |
|
78 |
"""Test switch updates tree and restores uncommitted changes.""" |
|
79 |
checkout, to_branch = self._setup_uncommitted() |
|
80 |
old_branch = self._master_if_present(checkout.branch) |
|
81 |
self.assertPathDoesNotExist('checkout/file-1') |
|
82 |
self.assertPathExists('checkout/file-2') |
|
83 |
self.assertPathExists('checkout/file-3') |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
84 |
switch.switch(checkout.controldir, to_branch, store_uncommitted=True) |
|
6538.1.15
by Aaron Bentley
Switch.switch stores and restores changes. |
85 |
checkout = workingtree.WorkingTree.open('checkout') |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
86 |
switch.switch(checkout.controldir, old_branch, store_uncommitted=True) |
|
6538.1.15
by Aaron Bentley
Switch.switch stores and restores changes. |
87 |
self.assertPathDoesNotExist('checkout/file-1') |
88 |
self.assertPathExists('checkout/file-2') |
|
89 |
self.assertPathExists('checkout/file-3') |
|
90 |
||
|
6538.1.16
by Aaron Bentley
Restore uncommitted changes even if revisions are same. |
91 |
def test_switch_restore_uncommitted_same_revision(self): |
92 |
"""Test switch updates tree and restores uncommitted changes.""" |
|
93 |
checkout, to_branch = self._setup_uncommitted(same_revision=True) |
|
94 |
old_branch = self._master_if_present(checkout.branch) |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
95 |
switch.switch(checkout.controldir, to_branch, store_uncommitted=True) |
|
6538.1.16
by Aaron Bentley
Restore uncommitted changes even if revisions are same. |
96 |
checkout = workingtree.WorkingTree.open('checkout') |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
97 |
switch.switch(checkout.controldir, old_branch, store_uncommitted=True) |
|
6538.1.16
by Aaron Bentley
Restore uncommitted changes even if revisions are same. |
98 |
self.assertPathExists('checkout/file-3') |
99 |
||
|
2999.1.3
by Ian Clatworthy
fix pending merge detection and test |
100 |
def test_switch_updates(self): |
101 |
"""Test switch updates tree and keeps uncommitted changes.""" |
|
|
6538.1.15
by Aaron Bentley
Switch.switch stores and restores changes. |
102 |
checkout, to_branch = self._setup_uncommitted() |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
103 |
self.assertPathDoesNotExist('checkout/file-1') |
104 |
self.assertPathExists('checkout/file-2') |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
105 |
switch.switch(checkout.controldir, to_branch) |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
106 |
self.assertPathExists('checkout/file-1') |
107 |
self.assertPathDoesNotExist('checkout/file-2') |
|
108 |
self.assertPathExists('checkout/file-3') |
|
|
2999.1.1
by Ian Clatworthy
migrate switch command into the core - was in BzrTools |
109 |
|
|
2999.1.3
by Ian Clatworthy
fix pending merge detection and test |
110 |
def test_switch_after_branch_moved(self): |
111 |
"""Test switch after the branch is moved.""" |
|
112 |
tree = self._setup_tree() |
|
|
3078.2.2
by Ian Clatworthy
get switch tests passing on heavyweight checkouts |
113 |
checkout = tree.branch.create_checkout('checkout', |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
114 |
lightweight=self.lightweight) |
|
2999.1.3
by Ian Clatworthy
fix pending merge detection and test |
115 |
self.build_tree(['branch-1/file-2']) |
116 |
tree.add('file-2') |
|
117 |
tree.remove('file-1') |
|
118 |
tree.commit('rev2') |
|
|
3044.1.4
by Martin Pool
Set default format to pack-0.92 |
119 |
self.build_tree(['checkout/file-3']) |
120 |
checkout.add('file-3') |
|
121 |
# rename the branch on disk, the checkout object is now invalid.
|
|
|
2999.1.3
by Ian Clatworthy
fix pending merge detection and test |
122 |
os.rename('branch-1', 'branch-2') |
123 |
to_branch = branch.Branch.open('branch-2') |
|
|
3078.2.5
by Ian Clatworthy
make switch fail without --force if branch missing |
124 |
# Check fails without --force
|
|
4340.1.1
by Jelmer Vernooij
Mention --force when bzr switch fails to open the current master branch. |
125 |
err = self.assertRaises( |
|
7490.61.1
by Jelmer Vernooij
Rename BzrCommandError to CommandError. |
126 |
(errors.CommandError, errors.NotBranchError), |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
127 |
switch.switch, checkout.controldir, to_branch) |
|
7490.61.1
by Jelmer Vernooij
Rename BzrCommandError to CommandError. |
128 |
if isinstance(err, errors.CommandError): |
|
4340.1.1
by Jelmer Vernooij
Mention --force when bzr switch fails to open the current master branch. |
129 |
self.assertContainsRe(str(err), |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
130 |
'Unable to connect to current master branch .*'
|
131 |
'To switch anyway, use --force.') |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
132 |
switch.switch(checkout.controldir, to_branch, force=True) |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
133 |
self.assertPathDoesNotExist('checkout/file-1') |
134 |
self.assertPathExists('checkout/file-2') |
|
135 |
self.assertPathExists('checkout/file-3') |
|
|
2999.1.3
by Ian Clatworthy
fix pending merge detection and test |
136 |
|
137 |
def test_switch_when_pending_merges(self): |
|
138 |
"""Test graceful failure if pending merges are outstanding.""" |
|
139 |
# Create 2 branches and a checkout
|
|
140 |
tree = self._setup_tree() |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
141 |
tree2 = tree.controldir.sprout('branch-2').open_workingtree() |
|
3078.2.2
by Ian Clatworthy
get switch tests passing on heavyweight checkouts |
142 |
checkout = tree.branch.create_checkout('checkout', |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
143 |
lightweight=self.lightweight) |
|
2999.1.3
by Ian Clatworthy
fix pending merge detection and test |
144 |
# Change tree2 and merge it into the checkout without committing
|
145 |
self.build_tree(['branch-2/file-2']) |
|
146 |
tree2.add('file-2') |
|
147 |
tree2.commit('rev2') |
|
148 |
checkout.merge_from_branch(tree2.branch) |
|
149 |
# Check the error reporting is as expected
|
|
|
7490.61.1
by Jelmer Vernooij
Rename BzrCommandError to CommandError. |
150 |
err = self.assertRaises(errors.CommandError, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
151 |
switch.switch, checkout.controldir, tree2.branch) |
|
2999.1.3
by Ian Clatworthy
fix pending merge detection and test |
152 |
self.assertContainsRe(str(err), |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
153 |
"Pending merges must be committed or reverted before using switch") |
|
3078.2.2
by Ian Clatworthy
get switch tests passing on heavyweight checkouts |
154 |
|
|
3984.5.1
by Daniel Watkins
Added whitebox test. |
155 |
def test_switch_with_revision(self): |
156 |
"""Test switch when a revision is given.""" |
|
157 |
# Create a tree with 2 revisions
|
|
|
3984.5.3
by Daniel Watkins
Updated testcase. |
158 |
tree = self.make_branch_and_tree('branch-1') |
159 |
self.build_tree(['branch-1/file-1']) |
|
160 |
tree.add('file-1') |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
161 |
tree.commit(rev_id=b'rev1', message='rev1') |
|
3984.5.1
by Daniel Watkins
Added whitebox test. |
162 |
self.build_tree(['branch-1/file-2']) |
163 |
tree.add('file-2') |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
164 |
tree.commit(rev_id=b'rev2', message='rev2') |
|
3984.5.1
by Daniel Watkins
Added whitebox test. |
165 |
# Check it out and switch to revision 1
|
166 |
checkout = tree.branch.create_checkout('checkout', |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
167 |
lightweight=self.lightweight) |
|
7045.4.8
by Jelmer Vernooij
Fix another 128 tests on python 3. |
168 |
switch.switch(checkout.controldir, tree.branch, revision_id=b"rev1") |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
169 |
self.assertPathExists('checkout/file-1') |
170 |
self.assertPathDoesNotExist('checkout/file-2') |
|
|
3984.5.1
by Daniel Watkins
Added whitebox test. |
171 |
|
|
4634.123.7
by John Arbash Meinel
Add direct tests that 'bzr switch' can handle root-id changes. |
172 |
def test_switch_changing_root_id(self): |
173 |
tree = self._setup_tree() |
|
174 |
tree2 = self.make_branch_and_tree('tree-2') |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
175 |
tree2.set_root_id(b'custom-root-id') |
|
4634.123.7
by John Arbash Meinel
Add direct tests that 'bzr switch' can handle root-id changes. |
176 |
self.build_tree(['tree-2/file-2']) |
177 |
tree2.add(['file-2']) |
|
178 |
tree2.commit('rev1b') |
|
179 |
checkout = tree.branch.create_checkout('checkout', |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
180 |
lightweight=self.lightweight) |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
181 |
switch.switch(checkout.controldir, tree2.branch) |
|
7358.14.1
by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id(''). |
182 |
self.assertEqual(b'custom-root-id', tree2.path2id('')) |
|
4634.123.7
by John Arbash Meinel
Add direct tests that 'bzr switch' can handle root-id changes. |
183 |
|
|
5162.3.1
by Aaron Bentley
Fix switch/merge when a ConfigurableFileMerger is used. |
184 |
def test_switch_configurable_file_merger(self): |
185 |
class DummyMerger(_mod_merge.ConfigurableFileMerger): |
|
186 |
name_prefix = 'file' |
|
187 |
||
188 |
_mod_merge.Merger.hooks.install_named_hook( |
|
189 |
'merge_file_content', DummyMerger, |
|
190 |
'test factory') |
|
191 |
foo = self.make_branch('foo') |
|
192 |
checkout = foo.create_checkout('checkout', lightweight=True) |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
193 |
self.build_tree_contents([('checkout/file', b'a')]) |
|
5162.3.1
by Aaron Bentley
Fix switch/merge when a ConfigurableFileMerger is used. |
194 |
checkout.add('file') |
195 |
checkout.commit('a') |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
196 |
bar = foo.controldir.sprout('bar').open_workingtree() |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
197 |
self.build_tree_contents([('bar/file', b'b')]) |
|
5162.3.1
by Aaron Bentley
Fix switch/merge when a ConfigurableFileMerger is used. |
198 |
bar.commit('b') |
|
7029.4.2
by Jelmer Vernooij
Fix more merge tests. |
199 |
self.build_tree_contents([('checkout/file', b'c')]) |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
200 |
switch.switch(checkout.controldir, bar.branch) |
|
5162.3.1
by Aaron Bentley
Fix switch/merge when a ConfigurableFileMerger is used. |
201 |
|
|
3078.2.2
by Ian Clatworthy
get switch tests passing on heavyweight checkouts |
202 |
|
203 |
class TestSwitchHeavyweight(TestSwitch): |
|
204 |
||
205 |
def setUp(self): |
|
206 |
super(TestSwitchHeavyweight, self).setUp() |
|
207 |
self.lightweight = False |
|
|
3078.2.4
by Ian Clatworthy
Add test for local commits handling |
208 |
|
209 |
def test_switch_with_local_commits(self): |
|
210 |
"""Test switch complains about local commits unless --force given.""" |
|
211 |
tree = self._setup_tree() |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
212 |
to_branch = tree.controldir.sprout('branch-2').open_branch() |
|
3078.2.4
by Ian Clatworthy
Add test for local commits handling |
213 |
self.build_tree(['branch-1/file-2']) |
214 |
tree.add('file-2') |
|
215 |
tree.remove('file-1') |
|
216 |
tree.commit('rev2') |
|
217 |
checkout = tree.branch.create_checkout('checkout') |
|
218 |
self.build_tree(['checkout/file-3']) |
|
219 |
checkout.add('file-3') |
|
220 |
checkout.commit(message='local only commit', local=True) |
|
221 |
self.build_tree(['checkout/file-4']) |
|
222 |
# Check the error reporting is as expected
|
|
|
7490.61.1
by Jelmer Vernooij
Rename BzrCommandError to CommandError. |
223 |
err = self.assertRaises(errors.CommandError, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
224 |
switch.switch, checkout.controldir, to_branch) |
|
3078.2.4
by Ian Clatworthy
Add test for local commits handling |
225 |
self.assertContainsRe(str(err), |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
226 |
'Cannot switch as local commits found in the checkout.') |
|
3078.2.4
by Ian Clatworthy
Add test for local commits handling |
227 |
# Check all is ok when force is given
|
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
228 |
self.assertPathDoesNotExist('checkout/file-1') |
229 |
self.assertPathExists('checkout/file-2') |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
230 |
switch.switch(checkout.controldir, to_branch, force=True) |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
231 |
self.assertPathExists('checkout/file-1') |
232 |
self.assertPathDoesNotExist('checkout/file-2') |
|
233 |
self.assertPathDoesNotExist('checkout/file-3') |
|
234 |
self.assertPathExists('checkout/file-4') |
|
|
3078.2.4
by Ian Clatworthy
Add test for local commits handling |
235 |
# Check that the checkout is a true mirror of the bound branch
|
|
3445.2.1
by John Arbash Meinel
Add tests for Branch.missing_revisions and deprecate it. |
236 |
self.assertEqual(to_branch.last_revision_info(), |
237 |
checkout.branch.last_revision_info()) |