/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: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
60
60
 
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)
74
74
 
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(),
84
 
            False)
 
84
                         False)
85
85
        self.run_bzr('switch branch2', working_dir='checkout')
86
86
 
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(),
91
 
            False)
 
91
                         False)
92
92
 
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(),
110
 
            "explicit_nick")
 
110
                         "explicit_nick")
111
111
        self.run_bzr('switch branch2', working_dir='checkout')
112
112
 
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(),
117
 
            tree2.branch.nick)
 
117
                         tree2.branch.nick)
118
118
 
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()
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.'],
222
 
            'switch foo')
 
222
                           'switch foo')
223
223
        self.run_bzr(['switch', '--force', 'foo'])
224
224
 
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')
316
316
 
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
 
348
349
        class FooLookup(object):
349
 
            def look_up(self, name, url):
350
 
                return 'foo-'+name
 
350
            def look_up(self, name, url, purpose=None):
 
351
                return 'foo-' + name
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
359
360
        calls = []
360
361
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
361
 
            calls.append, None)
 
362
                                                    calls.append, None)
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
372
373
        calls = []
373
374
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
374
 
            calls.append, None)
 
375
                                                    calls.append, None)
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')
385
386
 
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')])
389
390
        a_tree.add('a')
390
391
        a_tree.commit(message='initial')
391
392
 
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')
396
397
 
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')
400
401
 
401
402
 
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...
411
412
                Location:
412
413
                  shared repository: repo
430
431
                $ cd checkout
431
432
                $ brz switch --create-branch switched
432
433
                2>Tree is up to date at revision 0.
433
 
                2>Switched to branch:...switched...
 
434
                2>Switched to branch at .../switched/
434
435
                $ cd ..
435
436
                ''' % locals())
436
437
        bound_branch = branch.Branch.open_containing('checkout')[0]
461
462
        # Note: not a lightweight checkout
462
463
        checkout = master.branch.create_checkout('checkout')
463
464
        opened = []
 
465
 
464
466
        def open_hook(branch):
465
467
            # Just append the final directory of the branch
466
468
            name = branch.base.rstrip('/').rsplit('/', 1)[1]
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'),
485
 
            'target'])
 
487
                                 'target'])
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)
496
498
 
497
499
 
529
531
        self.assertPathDoesNotExist('checkout/a')
530
532
        self.run_bzr(['switch', '-d', 'checkout', 'orig'])
531
533
        self.assertPathDoesNotExist('checkout/a')
 
534
 
 
535
 
 
536
class TestSwitchStandAloneCorruption(TestCaseWithTransport):
 
537
 
 
538
    def test_empty_tree_switch(self):
 
539
        """switch . on an empty tree gets infinite recursion
 
540
 
 
541
        Inspired by: https://bugs.launchpad.net/bzr/+bug/1018628
 
542
        """
 
543
        self.script_runner = script.ScriptRunner()
 
544
        self.script_runner.run_script(self, '''
 
545
            $ brz init
 
546
            Created a standalone tree (format: 2a)
 
547
            $ brz switch .
 
548
            2>brz: ERROR: switching would create a branch reference loop. Use the "bzr up" command to switch to a different revision.
 
549
            ''')
 
550
 
 
551
    def test_switch_on_previous_rev(self):
 
552
        """switch to previous rev in a standalone directory
 
553
 
 
554
        Inspired by: https://bugs.launchpad.net/brz/+bug/1018628
 
555
        """
 
556
        self.script_runner = script.ScriptRunner()
 
557
        self.script_runner.run_script(self, '''
 
558
           $ brz init
 
559
           Created a standalone tree (format: 2a)
 
560
           $ brz commit -m 1 --unchanged
 
561
           $ brz commit -m 2 --unchanged
 
562
           $ brz switch -r 1
 
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)
 
565
 
 
566
    def test_switch_create_colo_locks_repo_path(self):
 
567
        self.script_runner = script.ScriptRunner()
 
568
        self.script_runner.run_script(self, '''
 
569
            $ mkdir mywork
 
570
            $ cd mywork
 
571
            $ brz init
 
572
            Created a standalone tree (format: 2a)
 
573
            $ echo A > a && brz add a && brz commit -m A
 
574
            $ brz switch -b br1
 
575
            $ cd ..
 
576
            $ mv mywork mywork1
 
577
            $ cd mywork1
 
578
            $ brz branches
 
579
              br1
 
580
            ''', null_output_matches_anything=True)
 
581
 
 
582
    def test_switch_to_new_branch_on_old_rev(self):
 
583
        """switch to previous rev in a standalone directory
 
584
 
 
585
        Inspired by: https://bugs.launchpad.net/brz/+bug/933362
 
586
        """
 
587
        self.script_runner = script.ScriptRunner()
 
588
        self.script_runner.run_script(self, '''
 
589
           $ brz init
 
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
 
595
           2>Committing to: ...
 
596
           2>Committed revision 1.
 
597
           $ brz commit -m 2 --unchanged
 
598
           2>Committing to: ...
 
599
           2>Committed revision 2.
 
600
           $ brz switch -b blah -r1
 
601
           2>Updated to revision 1.
 
602
           2>Switched to branch blah
 
603
           $ brz branches
 
604
           * blah
 
605
             trunk
 
606
           $ brz st
 
607
           ''')