53
55
os.chdir('checkout')
54
56
out, err = self.run_bzr('switch ../branch2')
55
57
self.assertContainsRe(err, 'Tree is up to date at revision 0.\n')
56
self.assertContainsRe(err, 'Switched to branch at .*/branch2.\n')
58
self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n')
57
59
self.assertEqual('', out)
59
61
def test_switch_out_of_date_light_checkout(self):
67
69
out, err = self.run_bzr('switch ../branch2')
68
70
#self.assertContainsRe(err, '\+N file')
69
71
self.assertContainsRe(err, 'Updated to revision 1.\n')
70
self.assertContainsRe(err, 'Switched to branch at .*/branch2.\n')
72
self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n')
71
73
self.assertEqual('', out)
73
75
def _test_switch_nick(self, lightweight):
75
77
tree1 = self.make_branch_and_tree('branch1')
76
78
tree2 = self.make_branch_and_tree('branch2')
77
79
tree2.pull(tree1.branch)
78
checkout = tree1.branch.create_checkout('checkout',
79
lightweight=lightweight)
80
checkout = tree1.branch.create_checkout('checkout',
81
lightweight=lightweight)
80
82
self.assertEqual(checkout.branch.nick, tree1.branch.nick)
81
83
self.assertEqual(checkout.branch.get_config().has_explicit_nickname(),
83
85
self.run_bzr('switch branch2', working_dir='checkout')
85
87
# we need to get the tree again, otherwise we don't get the new branch
86
88
checkout = WorkingTree.open('checkout')
87
89
self.assertEqual(checkout.branch.nick, tree2.branch.nick)
88
90
self.assertEqual(checkout.branch.get_config().has_explicit_nickname(),
91
93
def test_switch_nick(self):
92
94
self._test_switch_nick(lightweight=False)
99
101
tree1 = self.make_branch_and_tree('branch1')
100
102
tree2 = self.make_branch_and_tree('branch2')
101
103
tree2.pull(tree1.branch)
102
checkout = tree1.branch.create_checkout('checkout',
103
lightweight=lightweight)
104
checkout = tree1.branch.create_checkout('checkout',
105
lightweight=lightweight)
104
106
self.assertEqual(checkout.branch.nick, tree1.branch.nick)
105
107
checkout.branch.nick = "explicit_nick"
106
108
self.assertEqual(checkout.branch.nick, "explicit_nick")
107
109
self.assertEqual(checkout.branch.get_config()._get_explicit_nickname(),
109
111
self.run_bzr('switch branch2', working_dir='checkout')
111
113
# we need to get the tree again, otherwise we don't get the new branch
112
114
checkout = WorkingTree.open('checkout')
113
115
self.assertEqual(checkout.branch.nick, tree2.branch.nick)
114
116
self.assertEqual(checkout.branch.get_config()._get_explicit_nickname(),
117
119
def test_switch_explicit_nick(self):
118
120
self._test_switch_explicit_nick(lightweight=False)
128
130
tree2 = self.make_branch_and_tree('repo/branchb')
129
131
tree2.pull(tree1.branch)
130
132
branchb_id = tree2.commit('bar')
131
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
133
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
132
134
self.run_bzr(['switch', 'branchb'], working_dir='checkout')
133
135
self.assertEqual(branchb_id, checkout.last_revision())
134
136
checkout = checkout.controldir.open_workingtree()
166
168
tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
167
169
tree2.pull(tree1.branch)
168
170
branchb_id = tree2.commit('bar')
169
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
171
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
170
172
self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
171
173
self.assertEqual(branchb_id, checkout.last_revision())
172
174
checkout = checkout.controldir.open_workingtree()
181
183
tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
182
184
tree2.pull(tree1.branch)
183
185
branchb_id = tree2.commit('bar')
184
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
186
checkout = tree1.branch.create_checkout('checkout', lightweight=True)
185
187
self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
186
188
self.assertEqual(branchb_id, checkout.last_revision())
187
189
checkout = checkout.controldir.open_workingtree()
205
207
self.run_bzr(['switch', '-b', 'anotherbranch'])
206
208
self.assertEqual(
207
209
{'', 'anotherbranch'},
208
set(tree.branch.controldir.branch_names()))
210
set(tree.branch.controldir.get_branches().keys()))
210
212
def test_switch_into_unrelated_colocated(self):
211
213
# Create a new colocated branch from an existing non-colocated branch.
217
219
revid2 = tree.commit('rev2')
218
220
tree.controldir.create_branch(name='foo')
219
221
self.run_bzr_error(['Cannot switch a branch, only a checkout.'],
221
223
self.run_bzr(['switch', '--force', 'foo'])
223
225
def test_switch_existing_colocated(self):
310
312
def test_create_branch_no_branch(self):
311
313
self.prepare_lightweight_switch()
312
314
self.run_bzr_error(['cannot create branch without source branch'],
313
'switch --create-branch ../branch2', working_dir='tree')
315
'switch --create-branch ../branch2', working_dir='tree')
315
317
def test_create_branch(self):
316
318
branch = self.make_branch('branch')
317
319
tree = branch.create_checkout('tree', lightweight=True)
318
tree.commit('one', rev_id=b'rev-1')
320
tree.commit('one', rev_id='rev-1')
319
321
self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
320
322
tree = WorkingTree.open('tree')
321
323
self.assertEndsWith(tree.branch.base, '/branch2/')
323
325
def test_create_branch_local(self):
324
326
branch = self.make_branch('branch')
325
327
tree = branch.create_checkout('tree', lightweight=True)
326
tree.commit('one', rev_id=b'rev-1')
328
tree.commit('one', rev_id='rev-1')
327
329
self.run_bzr('switch --create-branch branch2', working_dir='tree')
328
330
tree = WorkingTree.open('tree')
329
331
# The new branch should have been created at the same level as
333
335
def test_create_branch_short_name(self):
334
336
branch = self.make_branch('branch')
335
337
tree = branch.create_checkout('tree', lightweight=True)
336
tree.commit('one', rev_id=b'rev-1')
338
tree.commit('one', rev_id='rev-1')
337
339
self.run_bzr('switch -b branch2', working_dir='tree')
338
340
tree = WorkingTree.open('tree')
339
341
# The new branch should have been created at the same level as
343
345
def test_create_branch_directory_services(self):
344
346
branch = self.make_branch('branch')
345
347
tree = branch.create_checkout('tree', lightweight=True)
347
348
class FooLookup(object):
348
def look_up(self, name, url, purpose=None):
349
def look_up(self, name, url):
350
351
directories.register('foo:', FooLookup, 'Create branches named foo-')
351
352
self.addCleanup(directories.remove, 'foo:')
352
353
self.run_bzr('switch -b foo:branch2', working_dir='tree')
357
358
from breezy import branch as _mod_branch
359
360
_mod_branch.Branch.hooks.install_named_hook('post_switch',
361
362
self.make_branch_and_tree('branch')
362
363
self.run_bzr('branch branch branch2')
363
364
self.run_bzr('checkout branch checkout')
370
371
from breezy import branch as _mod_branch
372
373
_mod_branch.Branch.hooks.install_named_hook('post_switch',
374
375
self.make_branch_and_tree('branch')
375
376
self.run_bzr('branch branch branch2')
376
377
self.run_bzr('checkout --lightweight branch checkout')
385
386
# create a source branch
386
387
a_tree = self.make_branch_and_tree('a')
387
self.build_tree_contents([('a/a', b'initial\n')])
388
self.build_tree_contents([('a/a', 'initial\n')])
389
390
a_tree.commit(message='initial')
391
392
# clone and add a differing revision
392
393
b_tree = a_tree.controldir.sprout('b').open_workingtree()
393
self.build_tree_contents([('b/a', b'initial\nmore\n')])
394
self.build_tree_contents([('b/a', 'initial\nmore\n')])
394
395
b_tree.commit(message='more')
396
397
self.run_bzr('checkout --lightweight a checkout')
397
398
self.run_bzr('switch --directory checkout b')
398
self.assertFileEqual(b'initial\nmore\n', 'checkout/a')
399
self.assertFileEqual('initial\nmore\n', 'checkout/a')
401
402
class TestSwitchParentLocationBase(TestCaseWithTransport):
405
406
super(TestSwitchParentLocationBase, self).setUp()
406
407
self.script_runner = script.ScriptRunner()
407
408
self.script_runner.run_script(self, '''
408
$ brz init-shared-repo --no-trees repo
409
$ brz init-repo --no-trees repo
409
410
Shared repository...
411
412
shared repository: repo
474
474
self.assertEqual(1, opened.count('master'))
477
class TestSmartServerSwitch(TestCaseWithTransport):
479
def test_switch_lightweight(self):
480
self.setup_smart_server_with_call_log()
481
t = self.make_branch_and_tree('from')
482
for count in range(9):
483
t.commit(message='commit %d' % count)
484
out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
486
self.reset_smart_call_log()
487
self.run_bzr(['switch', self.get_url('from')], working_dir='target')
488
# This figure represent the amount of work to perform this use case. It
489
# is entirely ok to reduce this number if a test fails due to rpc_count
490
# being too low. If rpc_count increases, more network roundtrips have
491
# become necessary for this use case. Please do not adjust this number
492
# 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.assertThat(self.hpss_calls, ContainsNoVfsCalls)
477
498
class TestSwitchUncommitted(TestCaseWithTransport):
479
500
def prepare(self):
508
529
self.assertPathDoesNotExist('checkout/a')
509
530
self.run_bzr(['switch', '-d', 'checkout', 'orig'])
510
531
self.assertPathDoesNotExist('checkout/a')
513
class TestSwitchStandAloneCorruption(TestCaseWithTransport):
515
def test_empty_tree_switch(self):
516
"""switch . on an empty tree gets infinite recursion
518
Inspired by: https://bugs.launchpad.net/bzr/+bug/1018628
520
self.script_runner = script.ScriptRunner()
521
self.script_runner.run_script(self, '''
523
Created a standalone tree (format: 2a)
525
2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.
528
def test_switch_on_previous_rev(self):
529
"""switch to previous rev in a standalone directory
531
Inspired by: https://bugs.launchpad.net/brz/+bug/1018628
533
self.script_runner = script.ScriptRunner()
534
self.script_runner.run_script(self, '''
536
Created a standalone tree (format: 2a)
537
$ brz commit -m 1 --unchanged
538
$ brz commit -m 2 --unchanged
540
2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.''',
541
null_output_matches_anything=True)
543
def test_switch_create_colo_locks_repo_path(self):
544
self.script_runner = script.ScriptRunner()
545
self.script_runner.run_script(self, '''
549
Created a standalone tree (format: 2a)
550
$ echo A > a && brz add a && brz commit -m A
557
''', null_output_matches_anything=True)
559
def test_switch_to_new_branch_on_old_rev(self):
560
"""switch to previous rev in a standalone directory
562
Inspired by: https://bugs.launchpad.net/brz/+bug/933362
564
self.script_runner = script.ScriptRunner()
565
self.script_runner.run_script(self, '''
567
Created a standalone tree (format: 2a)
568
$ brz switch -b trunk
569
2>Tree is up to date at revision 0.
570
2>Switched to branch trunk
571
$ brz commit -m 1 --unchanged
573
2>Committed revision 1.
574
$ brz commit -m 2 --unchanged
576
2>Committed revision 2.
577
$ brz switch -b blah -r1
578
2>Updated to revision 1.
579
2>Switched to branch blah