29
28
class TestSwitch(ExternalBase):
31
def _create_sample_tree(self):
32
tree = self.make_branch_and_tree('branch-1')
33
self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
40
30
def test_switch_up_to_date_light_checkout(self):
41
31
self.make_branch_and_tree('branch')
42
32
self.run_bzr('branch branch branch2')
145
135
self.assertEqual(branchb_id, checkout.last_revision())
146
136
self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
148
def test_switch_revision(self):
149
tree = self._create_sample_tree()
150
checkout = tree.branch.create_checkout('checkout', lightweight=True)
151
self.run_bzr(['switch', 'branch-1', '-r1'], working_dir='checkout')
152
self.failUnlessExists('checkout/file-1')
153
self.failIfExists('checkout/file-2')
155
def test_switch_only_revision(self):
156
tree = self._create_sample_tree()
157
checkout = tree.branch.create_checkout('checkout', lightweight=True)
158
self.failUnlessExists('checkout/file-1')
159
self.failUnlessExists('checkout/file-2')
160
self.run_bzr(['switch', '-r1'], working_dir='checkout')
161
self.failUnlessExists('checkout/file-1')
162
self.failIfExists('checkout/file-2')
163
# Check that we don't accept a range
165
['bzr switch --revision takes exactly one revision identifier'],
166
['switch', '-r0..2'], working_dir='checkout')
168
138
def prepare_lightweight_switch(self):
169
139
branch = self.make_branch('branch')
170
140
branch.create_checkout('tree', lightweight=True)
171
osutils.rename('branch', 'branch1')
141
os.rename('branch', 'branch1')
173
143
def test_switch_lightweight_after_branch_moved(self):
174
144
self.prepare_lightweight_switch()
227
197
tree = WorkingTree.open('tree')
228
198
self.assertEndsWith(tree.branch.base, 'foo-branch2/')
230
def test_switch_with_post_switch_hook(self):
231
from bzrlib import branch as _mod_branch
233
_mod_branch.Branch.hooks.install_named_hook('post_switch',
235
self.make_branch_and_tree('branch')
236
self.run_bzr('branch branch branch2')
237
self.run_bzr('checkout branch checkout')
239
self.assertLength(0, calls)
240
out, err = self.run_bzr('switch ../branch2')
241
self.assertLength(1, calls)
243
def test_switch_lightweight_co_with_post_switch_hook(self):
244
from bzrlib import branch as _mod_branch
246
_mod_branch.Branch.hooks.install_named_hook('post_switch',
248
self.make_branch_and_tree('branch')
249
self.run_bzr('branch branch branch2')
250
self.run_bzr('checkout --lightweight branch checkout')
252
self.assertLength(0, calls)
253
out, err = self.run_bzr('switch ../branch2')
254
self.assertLength(1, calls)