55
55
os.chdir('checkout')
56
56
out, err = self.run_bzr('switch ../branch2')
57
57
self.assertContainsRe(err, 'Tree is up to date at revision 0.\n')
58
self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n')
58
self.assertContainsRe(err, 'Switched to branch at .*/branch2.\n')
59
59
self.assertEqual('', out)
61
61
def test_switch_out_of_date_light_checkout(self):
69
69
out, err = self.run_bzr('switch ../branch2')
70
70
#self.assertContainsRe(err, '\+N file')
71
71
self.assertContainsRe(err, 'Updated to revision 1.\n')
72
self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n')
72
self.assertContainsRe(err, 'Switched to branch at .*/branch2.\n')
73
73
self.assertEqual('', out)
75
75
def _test_switch_nick(self, lightweight):
77
77
tree1 = self.make_branch_and_tree('branch1')
78
78
tree2 = self.make_branch_and_tree('branch2')
79
79
tree2.pull(tree1.branch)
80
checkout = tree1.branch.create_checkout('checkout',
81
lightweight=lightweight)
80
checkout = tree1.branch.create_checkout('checkout',
81
lightweight=lightweight)
82
82
self.assertEqual(checkout.branch.nick, tree1.branch.nick)
83
83
self.assertEqual(checkout.branch.get_config().has_explicit_nickname(),
85
85
self.run_bzr('switch branch2', working_dir='checkout')
87
87
# we need to get the tree again, otherwise we don't get the new branch
88
88
checkout = WorkingTree.open('checkout')
89
89
self.assertEqual(checkout.branch.nick, tree2.branch.nick)
90
90
self.assertEqual(checkout.branch.get_config().has_explicit_nickname(),
93
93
def test_switch_nick(self):
94
94
self._test_switch_nick(lightweight=False)
101
101
tree1 = self.make_branch_and_tree('branch1')
102
102
tree2 = self.make_branch_and_tree('branch2')
103
103
tree2.pull(tree1.branch)
104
checkout = tree1.branch.create_checkout('checkout',
105
lightweight=lightweight)
104
checkout = tree1.branch.create_checkout('checkout',
105
lightweight=lightweight)
106
106
self.assertEqual(checkout.branch.nick, tree1.branch.nick)
107
107
checkout.branch.nick = "explicit_nick"
108
108
self.assertEqual(checkout.branch.nick, "explicit_nick")
109
109
self.assertEqual(checkout.branch.get_config()._get_explicit_nickname(),
111
111
self.run_bzr('switch branch2', working_dir='checkout')
113
113
# we need to get the tree again, otherwise we don't get the new branch
114
114
checkout = WorkingTree.open('checkout')
115
115
self.assertEqual(checkout.branch.nick, tree2.branch.nick)
116
116
self.assertEqual(checkout.branch.get_config()._get_explicit_nickname(),
119
119
def test_switch_explicit_nick(self):
120
120
self._test_switch_explicit_nick(lightweight=False)
130
130
tree2 = self.make_branch_and_tree('repo/branchb')
131
131
tree2.pull(tree1.branch)
132
132
branchb_id = tree2.commit('bar')
133
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
133
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
134
134
self.run_bzr(['switch', 'branchb'], working_dir='checkout')
135
135
self.assertEqual(branchb_id, checkout.last_revision())
136
136
checkout = checkout.controldir.open_workingtree()
168
168
tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
169
169
tree2.pull(tree1.branch)
170
170
branchb_id = tree2.commit('bar')
171
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
171
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
172
172
self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
173
173
self.assertEqual(branchb_id, checkout.last_revision())
174
174
checkout = checkout.controldir.open_workingtree()
183
183
tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
184
184
tree2.pull(tree1.branch)
185
185
branchb_id = tree2.commit('bar')
186
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
186
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
187
187
self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
188
188
self.assertEqual(branchb_id, checkout.last_revision())
189
189
checkout = checkout.controldir.open_workingtree()
207
207
self.run_bzr(['switch', '-b', 'anotherbranch'])
208
208
self.assertEqual(
209
209
{'', 'anotherbranch'},
210
set(tree.branch.controldir.get_branches().keys()))
210
set(tree.branch.controldir.branch_names()))
212
212
def test_switch_into_unrelated_colocated(self):
213
213
# Create a new colocated branch from an existing non-colocated branch.
219
219
revid2 = tree.commit('rev2')
220
220
tree.controldir.create_branch(name='foo')
221
221
self.run_bzr_error(['Cannot switch a branch, only a checkout.'],
223
223
self.run_bzr(['switch', '--force', 'foo'])
225
225
def test_switch_existing_colocated(self):
312
312
def test_create_branch_no_branch(self):
313
313
self.prepare_lightweight_switch()
314
314
self.run_bzr_error(['cannot create branch without source branch'],
315
'switch --create-branch ../branch2', working_dir='tree')
315
'switch --create-branch ../branch2', working_dir='tree')
317
317
def test_create_branch(self):
318
318
branch = self.make_branch('branch')
319
319
tree = branch.create_checkout('tree', lightweight=True)
320
tree.commit('one', rev_id='rev-1')
320
tree.commit('one', rev_id=b'rev-1')
321
321
self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
322
322
tree = WorkingTree.open('tree')
323
323
self.assertEndsWith(tree.branch.base, '/branch2/')
325
325
def test_create_branch_local(self):
326
326
branch = self.make_branch('branch')
327
327
tree = branch.create_checkout('tree', lightweight=True)
328
tree.commit('one', rev_id='rev-1')
328
tree.commit('one', rev_id=b'rev-1')
329
329
self.run_bzr('switch --create-branch branch2', working_dir='tree')
330
330
tree = WorkingTree.open('tree')
331
331
# The new branch should have been created at the same level as
335
335
def test_create_branch_short_name(self):
336
336
branch = self.make_branch('branch')
337
337
tree = branch.create_checkout('tree', lightweight=True)
338
tree.commit('one', rev_id='rev-1')
338
tree.commit('one', rev_id=b'rev-1')
339
339
self.run_bzr('switch -b branch2', working_dir='tree')
340
340
tree = WorkingTree.open('tree')
341
341
# The new branch should have been created at the same level as
345
345
def test_create_branch_directory_services(self):
346
346
branch = self.make_branch('branch')
347
347
tree = branch.create_checkout('tree', lightweight=True)
348
349
class FooLookup(object):
349
def look_up(self, name, url):
350
def look_up(self, name, url, purpose=None):
351
352
directories.register('foo:', FooLookup, 'Create branches named foo-')
352
353
self.addCleanup(directories.remove, 'foo:')
353
354
self.run_bzr('switch -b foo:branch2', working_dir='tree')
358
359
from breezy import branch as _mod_branch
360
361
_mod_branch.Branch.hooks.install_named_hook('post_switch',
362
363
self.make_branch_and_tree('branch')
363
364
self.run_bzr('branch branch branch2')
364
365
self.run_bzr('checkout branch checkout')
371
372
from breezy import branch as _mod_branch
373
374
_mod_branch.Branch.hooks.install_named_hook('post_switch',
375
376
self.make_branch_and_tree('branch')
376
377
self.run_bzr('branch branch branch2')
377
378
self.run_bzr('checkout --lightweight branch checkout')
386
387
# create a source branch
387
388
a_tree = self.make_branch_and_tree('a')
388
self.build_tree_contents([('a/a', 'initial\n')])
389
self.build_tree_contents([('a/a', b'initial\n')])
390
391
a_tree.commit(message='initial')
392
393
# clone and add a differing revision
393
394
b_tree = a_tree.controldir.sprout('b').open_workingtree()
394
self.build_tree_contents([('b/a', 'initial\nmore\n')])
395
self.build_tree_contents([('b/a', b'initial\nmore\n')])
395
396
b_tree.commit(message='more')
397
398
self.run_bzr('checkout --lightweight a checkout')
398
399
self.run_bzr('switch --directory checkout b')
399
self.assertFileEqual('initial\nmore\n', 'checkout/a')
400
self.assertFileEqual(b'initial\nmore\n', 'checkout/a')
402
403
class TestSwitchParentLocationBase(TestCaseWithTransport):
406
407
super(TestSwitchParentLocationBase, self).setUp()
407
408
self.script_runner = script.ScriptRunner()
408
409
self.script_runner.run_script(self, '''
409
$ brz init-repo --no-trees repo
410
$ brz init-shared-repo --no-trees repo
410
411
Shared repository...
412
413
shared repository: repo
482
484
for count in range(9):
483
485
t.commit(message='commit %d' % count)
484
486
out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
486
488
self.reset_smart_call_log()
487
489
self.run_bzr(['switch', self.get_url('from')], working_dir='target')
488
490
# This figure represent the amount of work to perform this use case. It
490
492
# being too low. If rpc_count increases, more network roundtrips have
491
493
# become necessary for this use case. Please do not adjust this number
492
494
# upwards without agreement from bzr's network support maintainers.
493
self.assertLength(24, self.hpss_calls)
494
self.assertLength(4, self.hpss_connections)
495
self.assertLength(21, self.hpss_calls)
496
self.assertLength(3, self.hpss_connections)
495
497
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
529
531
self.assertPathDoesNotExist('checkout/a')
530
532
self.run_bzr(['switch', '-d', 'checkout', 'orig'])
531
533
self.assertPathDoesNotExist('checkout/a')
536
class TestSwitchStandAloneCorruption(TestCaseWithTransport):
538
def test_empty_tree_switch(self):
539
"""switch . on an empty tree gets infinite recursion
541
Inspired by: https://bugs.launchpad.net/bzr/+bug/1018628
543
self.script_runner = script.ScriptRunner()
544
self.script_runner.run_script(self, '''
546
Created a standalone tree (format: 2a)
548
2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.
551
def test_switch_on_previous_rev(self):
552
"""switch to previous rev in a standalone directory
554
Inspired by: https://bugs.launchpad.net/brz/+bug/1018628
556
self.script_runner = script.ScriptRunner()
557
self.script_runner.run_script(self, '''
559
Created a standalone tree (format: 2a)
560
$ brz commit -m 1 --unchanged
561
$ brz commit -m 2 --unchanged
563
2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.''',
564
null_output_matches_anything=True)
566
def test_switch_create_colo_locks_repo_path(self):
567
self.script_runner = script.ScriptRunner()
568
self.script_runner.run_script(self, '''
572
Created a standalone tree (format: 2a)
573
$ echo A > a && brz add a && brz commit -m A
580
''', null_output_matches_anything=True)
582
def test_switch_to_new_branch_on_old_rev(self):
583
"""switch to previous rev in a standalone directory
585
Inspired by: https://bugs.launchpad.net/brz/+bug/933362
587
self.script_runner = script.ScriptRunner()
588
self.script_runner.run_script(self, '''
590
Created a standalone tree (format: 2a)
591
$ brz switch -b trunk
592
2>Tree is up to date at revision 0.
593
2>Switched to branch trunk
594
$ brz commit -m 1 --unchanged
596
2>Committed revision 1.
597
$ brz commit -m 2 --unchanged
599
2>Committed revision 2.
600
$ brz switch -b blah -r1
601
2>Updated to revision 1.
602
2>Switched to branch blah