149
155
tree = self._create_sample_tree()
150
156
checkout = tree.branch.create_checkout('checkout', lightweight=True)
151
157
self.run_bzr(['switch', 'branch-1', '-r1'], working_dir='checkout')
152
self.failUnlessExists('checkout/file-1')
153
self.failIfExists('checkout/file-2')
158
self.assertPathExists('checkout/file-1')
159
self.assertPathDoesNotExist('checkout/file-2')
155
161
def test_switch_only_revision(self):
156
162
tree = self._create_sample_tree()
157
163
checkout = tree.branch.create_checkout('checkout', lightweight=True)
158
self.failUnlessExists('checkout/file-1')
159
self.failUnlessExists('checkout/file-2')
164
self.assertPathExists('checkout/file-1')
165
self.assertPathExists('checkout/file-2')
160
166
self.run_bzr(['switch', '-r1'], working_dir='checkout')
161
self.failUnlessExists('checkout/file-1')
162
self.failIfExists('checkout/file-2')
167
self.assertPathExists('checkout/file-1')
168
self.assertPathDoesNotExist('checkout/file-2')
163
169
# Check that we don't accept a range
164
170
self.run_bzr_error(
165
171
['bzr switch --revision takes exactly one revision identifier'],
252
258
self.assertLength(0, calls)
253
259
out, err = self.run_bzr('switch ../branch2')
254
260
self.assertLength(1, calls)
262
def test_switch_lightweight_directory(self):
263
"""Test --directory option"""
265
# create a source branch
266
a_tree = self.make_branch_and_tree('a')
267
self.build_tree_contents([('a/a', 'initial\n')])
269
a_tree.commit(message='initial')
271
# clone and add a differing revision
272
b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
273
self.build_tree_contents([('b/a', 'initial\nmore\n')])
274
b_tree.commit(message='more')
276
self.run_bzr('checkout --lightweight a checkout')
277
self.run_bzr('switch --directory checkout b')
278
self.assertFileEqual('initial\nmore\n', 'checkout/a')
281
class TestSwitchParentLocation(TestCaseWithTransport):
284
"""Set up a repository and branch ready for testing."""
285
super(TestSwitchParentLocation, self).setUp()
286
self.script_runner = script.ScriptRunner()
287
self.script_runner.run_script(self, '''
288
$ bzr init-repo --no-trees repo
291
shared repository: repo
292
$ bzr init repo/trunk
293
Created a repository branch...
294
Using shared repository: ...
297
def assertParentCorrect(self, branch, expected_parent, name):
298
"""Verify that the parent is not None and is set correctly."""
299
actual_parent = branch.get_parent()
300
self.assertIsNot(actual_parent, None, name + "Parent not set")
301
expected = urlutils.strip_trailing_slash(urlutils.normalize_url(expected_parent))
302
actual = urlutils.strip_trailing_slash(urlutils.normalize_url(actual_parent))
303
self.assertEquals(expected, actual, name + "Parent set incorrectly")
305
def _create_checkout_and_switch(self, option, suffix):
306
self.script_runner.run_script(self, '''
307
$ bzr checkout %(option)s repo/trunk work_%(suffix)s_switch
308
$ cd work_%(suffix)s_switch
309
$ bzr switch --create-branch switched_%(suffix)s
310
2>Tree is up to date at revision 0.
311
2>Switched to branch:...switched_%(suffix)s...
314
bound_branch = branch.Branch.open_containing('work_%(suffix)s_switch' % locals())[0]
315
master_branch = branch.Branch.open_containing('repo/switched_%(suffix)s' % locals())[0]
316
return (bound_branch, master_branch)
318
def test_switch_parent_lightweight(self):
319
"""Verify parent directory for lightweight checkout using bzr switch."""
320
bb, mb = self._create_checkout_and_switch(option='--lightweight', suffix='lw')
321
self.assertParentCorrect(bb, urlutils.local_path_to_url('repo/trunk'), "Checkout")
322
self.assertParentCorrect(mb, urlutils.local_path_to_url('repo/trunk'), "Master Branch")
324
def test_switch_parent_heavyweight(self):
325
"""Verify parent directory for heavyweight checkout using bzr switch."""
326
bb, mb = self._create_checkout_and_switch(option='', suffix='hw')
327
self.assertParentCorrect(bb, urlutils.local_path_to_url('repo/trunk'), "Bound Branch")
328
self.assertParentCorrect(mb, urlutils.local_path_to_url('repo/trunk'), "Master Branch")