156
149
tree = self._create_sample_tree()
157
150
checkout = tree.branch.create_checkout('checkout', lightweight=True)
158
151
self.run_bzr(['switch', 'branch-1', '-r1'], working_dir='checkout')
159
self.assertPathExists('checkout/file-1')
160
self.assertPathDoesNotExist('checkout/file-2')
152
self.failUnlessExists('checkout/file-1')
153
self.failIfExists('checkout/file-2')
162
155
def test_switch_only_revision(self):
163
156
tree = self._create_sample_tree()
164
157
checkout = tree.branch.create_checkout('checkout', lightweight=True)
165
self.assertPathExists('checkout/file-1')
166
self.assertPathExists('checkout/file-2')
158
self.failUnlessExists('checkout/file-1')
159
self.failUnlessExists('checkout/file-2')
167
160
self.run_bzr(['switch', '-r1'], working_dir='checkout')
168
self.assertPathExists('checkout/file-1')
169
self.assertPathDoesNotExist('checkout/file-2')
161
self.failUnlessExists('checkout/file-1')
162
self.failIfExists('checkout/file-2')
170
163
# Check that we don't accept a range
171
164
self.run_bzr_error(
172
165
['bzr switch --revision takes exactly one revision identifier'],
277
270
self.run_bzr('checkout --lightweight a checkout')
278
271
self.run_bzr('switch --directory checkout b')
279
272
self.assertFileEqual('initial\nmore\n', 'checkout/a')
282
class TestSwitchParentLocationBase(TestCaseWithTransport):
285
"""Set up a repository and branch ready for testing."""
286
super(TestSwitchParentLocationBase, self).setUp()
287
self.script_runner = script.ScriptRunner()
288
self.script_runner.run_script(self, '''
289
$ bzr init-repo --no-trees repo
292
shared repository: repo
293
$ bzr init repo/trunk
294
Created a repository branch...
295
Using shared repository: ...
298
def assertParent(self, expected_parent, branch):
299
"""Verify that the parent is not None and is set correctly."""
300
actual_parent = branch.get_parent()
301
self.assertIsSameRealPath(urlutils.local_path_to_url(expected_parent),
305
class TestSwitchParentLocation(TestSwitchParentLocationBase):
307
def _checkout_and_switch(self, option=''):
308
self.script_runner.run_script(self, '''
309
$ bzr checkout %(option)s repo/trunk checkout
311
$ bzr switch --create-branch switched
312
2>Tree is up to date at revision 0.
313
2>Switched to branch:...switched...
316
bound_branch = branch.Branch.open_containing('checkout')[0]
317
master_branch = branch.Branch.open_containing('repo/switched')[0]
318
return (bound_branch, master_branch)
320
def test_switch_parent_lightweight(self):
321
"""Lightweight checkout using bzr switch."""
322
bb, mb = self._checkout_and_switch(option='--lightweight')
323
self.assertParent('repo/trunk', bb)
324
self.assertParent('repo/trunk', mb)
326
def test_switch_parent_heavyweight(self):
327
"""Heavyweight checkout using bzr switch."""
328
bb, mb = self._checkout_and_switch()
329
self.assertParent('repo/trunk', bb)
330
self.assertParent('repo/trunk', mb)
333
class TestSwitchDoesntOpenMasterBranch(TestCaseWithTransport):
334
# See https://bugs.launchpad.net/bzr/+bug/812285
335
# "bzr switch --create-branch" can point the new branch's parent to the
336
# master branch, but it doesn't have to open it to do so.
338
def test_switch_create_doesnt_open_master_branch(self):
339
master = self.make_branch_and_tree('master')
341
# Note: not a lightweight checkout
342
checkout = master.branch.create_checkout('checkout')
344
def open_hook(branch):
345
# Just append the final directory of the branch
346
name = branch.base.rstrip('/').rsplit('/', 1)[1]
348
branch.Branch.hooks.install_named_hook('open', open_hook,
350
self.run_bzr('switch --create-branch -d checkout feature')
351
# We only open the master branch 1 time.
352
# This test should be cleaner to write, but see bug:
353
# https://bugs.launchpad.net/bzr/+bug/812295
354
self.assertEqual(1, opened.count('master'))