/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_switch.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from breezy.tests.features import UnicodeFilenameFeature
35
35
from breezy.directory_service import directories
36
36
 
 
37
from breezy.tests.matchers import ContainsNoVfsCalls
 
38
 
37
39
 
38
40
class TestSwitch(TestCaseWithTransport):
39
41
 
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)
58
60
 
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)
72
74
 
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(),
82
 
                         False)
 
84
            False)
83
85
        self.run_bzr('switch branch2', working_dir='checkout')
84
86
 
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(),
89
 
                         False)
 
91
            False)
90
92
 
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(),
108
 
                         "explicit_nick")
 
110
            "explicit_nick")
109
111
        self.run_bzr('switch branch2', working_dir='checkout')
110
112
 
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(),
115
 
                         tree2.branch.nick)
 
117
            tree2.branch.nick)
116
118
 
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()))
209
211
 
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.'],
220
 
                           'switch foo')
 
222
            'switch foo')
221
223
        self.run_bzr(['switch', '--force', 'foo'])
222
224
 
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')
314
316
 
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)
346
 
 
347
348
        class FooLookup(object):
348
 
            def look_up(self, name, url, purpose=None):
349
 
                return 'foo-' + name
 
349
            def look_up(self, name, url):
 
350
                return 'foo-'+name
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
358
359
        calls = []
359
360
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
360
 
                                                    calls.append, None)
 
361
            calls.append, None)
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
371
372
        calls = []
372
373
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
373
 
                                                    calls.append, None)
 
374
            calls.append, None)
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')
384
385
 
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')])
388
389
        a_tree.add('a')
389
390
        a_tree.commit(message='initial')
390
391
 
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')
395
396
 
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')
399
400
 
400
401
 
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...
410
411
                Location:
411
412
                  shared repository: repo
429
430
                $ cd checkout
430
431
                $ brz switch --create-branch switched
431
432
                2>Tree is up to date at revision 0.
432
 
                2>Switched to branch at .../switched/
 
433
                2>Switched to branch:...switched...
433
434
                $ cd ..
434
435
                ''' % locals())
435
436
        bound_branch = branch.Branch.open_containing('checkout')[0]
460
461
        # Note: not a lightweight checkout
461
462
        checkout = master.branch.create_checkout('checkout')
462
463
        opened = []
463
 
 
464
464
        def open_hook(branch):
465
465
            # Just append the final directory of the branch
466
466
            name = branch.base.rstrip('/').rsplit('/', 1)[1]
474
474
        self.assertEqual(1, opened.count('master'))
475
475
 
476
476
 
 
477
class TestSmartServerSwitch(TestCaseWithTransport):
 
478
 
 
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'),
 
485
            'target'])
 
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)
 
496
 
 
497
 
477
498
class TestSwitchUncommitted(TestCaseWithTransport):
478
499
 
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')
511
 
 
512
 
 
513
 
class TestSwitchStandAloneCorruption(TestCaseWithTransport):
514
 
 
515
 
    def test_empty_tree_switch(self):
516
 
        """switch . on an empty tree gets infinite recursion
517
 
 
518
 
        Inspired by: https://bugs.launchpad.net/bzr/+bug/1018628
519
 
        """
520
 
        self.script_runner = script.ScriptRunner()
521
 
        self.script_runner.run_script(self, '''
522
 
            $ brz init
523
 
            Created a standalone tree (format: 2a)
524
 
            $ brz switch .
525
 
            2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.
526
 
            ''')
527
 
 
528
 
    def test_switch_on_previous_rev(self):
529
 
        """switch to previous rev in a standalone directory
530
 
 
531
 
        Inspired by: https://bugs.launchpad.net/brz/+bug/1018628
532
 
        """
533
 
        self.script_runner = script.ScriptRunner()
534
 
        self.script_runner.run_script(self, '''
535
 
           $ brz init
536
 
           Created a standalone tree (format: 2a)
537
 
           $ brz commit -m 1 --unchanged
538
 
           $ brz commit -m 2 --unchanged
539
 
           $ brz switch -r 1
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)
542
 
 
543
 
    def test_switch_create_colo_locks_repo_path(self):
544
 
        self.script_runner = script.ScriptRunner()
545
 
        self.script_runner.run_script(self, '''
546
 
            $ mkdir mywork
547
 
            $ cd mywork
548
 
            $ brz init
549
 
            Created a standalone tree (format: 2a)
550
 
            $ echo A > a && brz add a && brz commit -m A
551
 
            $ brz switch -b br1
552
 
            $ cd ..
553
 
            $ mv mywork mywork1
554
 
            $ cd mywork1
555
 
            $ brz branches
556
 
              br1
557
 
            ''', null_output_matches_anything=True)
558
 
 
559
 
    def test_switch_to_new_branch_on_old_rev(self):
560
 
        """switch to previous rev in a standalone directory
561
 
 
562
 
        Inspired by: https://bugs.launchpad.net/brz/+bug/933362
563
 
        """
564
 
        self.script_runner = script.ScriptRunner()
565
 
        self.script_runner.run_script(self, '''
566
 
           $ brz init
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
572
 
           2>Committing to: ...
573
 
           2>Committed revision 1.
574
 
           $ brz commit -m 2 --unchanged
575
 
           2>Committing to: ...
576
 
           2>Committed revision 2.
577
 
           $ brz switch -b blah -r1
578
 
           2>Updated to revision 1.
579
 
           2>Switched to branch blah
580
 
           $ brz branches
581
 
           * blah
582
 
             trunk
583
 
           $ brz st
584
 
           ''')