/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/per_branch/test_branch.py

  • Committer: Jelmer Vernooij
  • Date: 2019-05-29 03:22:34 UTC
  • mfrom: (7303 work)
  • mto: This revision was merged to the branch mainline in revision 7306.
  • Revision ID: jelmer@jelmer.uk-20190529032234-mt3fuws8gq03tapi
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
    def test_branch_format_matches_bzrdir_branch_format(self):
56
56
        bzrdir_branch_format = self.bzrdir_format.get_branch_format()
57
57
        self.assertIs(
58
 
                self.branch_format.__class__,
59
 
                bzrdir_branch_format.__class__)
 
58
            self.branch_format.__class__,
 
59
            bzrdir_branch_format.__class__)
60
60
 
61
61
    def test_make_branch_gets_expected_format(self):
62
62
        branch = self.make_branch('.')
63
63
        self.assertIs(
64
 
                self.branch_format.__class__,
65
 
                branch._format.__class__)
 
64
            self.branch_format.__class__,
 
65
            branch._format.__class__)
66
66
 
67
67
 
68
68
class TestBranch(per_branch.TestCaseWithBranch):
162
162
        wt_a.add(['one'])
163
163
        rev1 = wt_a.commit('commit one')
164
164
 
165
 
        branch_b = wt_a.branch.controldir.sprout('b', revision_id=rev1).open_branch()
166
 
        self.assertEqual(wt_a.branch.user_url, branch_b.get_parent())
 
165
        branch_b = wt_a.branch.controldir.sprout(
 
166
            'b', revision_id=rev1).open_branch()
 
167
        self.assertEqual(
 
168
            urlutils.split_segment_parameters(wt_a.branch.user_url)[0],
 
169
            urlutils.split_segment_parameters(branch_b.get_parent())[0])
167
170
        return branch_b
168
171
 
169
172
    def test_clone_branch_nickname(self):
212
215
        wt = self.make_branch_and_tree('.')
213
216
        if not wt.branch.repository._format.supports_ghosts:
214
217
            raise tests.TestNotApplicable("repository format does not "
215
 
                "support ghosts")
 
218
                                          "support ghosts")
216
219
        wt.set_parent_ids([b'non:existent@rev--ision--0--2'],
217
 
            allow_leftmost_as_ghost=True)
 
220
                          allow_leftmost_as_ghost=True)
218
221
        self.assertEqual([b'non:existent@rev--ision--0--2'],
219
 
            wt.get_parent_ids())
 
222
                         wt.get_parent_ids())
220
223
        rev_id = wt.commit('commit against a ghost first parent.')
221
224
        rev = wt.branch.repository.get_revision(rev_id)
222
225
        self.assertEqual(rev.parent_ids, [b'non:existent@rev--ision--0--2'])
228
231
        wt = self.make_branch_and_tree('.')
229
232
        if not wt.branch.repository._format.supports_ghosts:
230
233
            raise tests.TestNotApplicable("repository format does not "
231
 
                "support ghosts")
 
234
                                          "support ghosts")
232
235
        wt.set_parent_ids([
233
 
                b'foo@azkhazan-123123-abcabc',
234
 
                b'wibble@fofof--20050401--1928390812',
 
236
            b'foo@azkhazan-123123-abcabc',
 
237
            b'wibble@fofof--20050401--1928390812',
235
238
            ],
236
239
            allow_leftmost_as_ghost=True)
237
240
        rev_id = wt.commit("commit from ghost base with one merge")
238
241
        # the revision should have been committed with two parents
239
242
        rev = wt.branch.repository.get_revision(rev_id)
240
243
        self.assertEqual([b'foo@azkhazan-123123-abcabc',
241
 
            b'wibble@fofof--20050401--1928390812'],
242
 
            rev.parent_ids)
 
244
                          b'wibble@fofof--20050401--1928390812'],
 
245
                         rev.parent_ids)
243
246
 
244
247
    def test_bad_revision(self):
245
248
        self.assertRaises(errors.InvalidRevisionId,
321
324
        self.assertEqual(0, len(repo.controldir.list_branches()))
322
325
        if not self.bzrdir_format.colocated_branches:
323
326
            raise tests.TestNotApplicable("control dir format does not support "
324
 
                "colocated branches")
 
327
                                          "colocated branches")
325
328
        try:
326
 
            child_branch1 = self.branch_format.initialize(repo.controldir, 
327
 
                name='branch1')
 
329
            child_branch1 = self.branch_format.initialize(repo.controldir,
 
330
                                                          name='branch1')
328
331
        except errors.UninitializableFormat:
329
332
            # branch references are not default init'able and
330
333
            # not all bzrdirs support colocated branches.
341
344
        for val in (True, False):
342
345
            try:
343
346
                branch = self.branch_format.initialize(repo.controldir,
344
 
                    append_revisions_only=True)
 
347
                                                       append_revisions_only=True)
345
348
            except (errors.UninitializableFormat, errors.UpgradeRequired):
346
349
                # branch references are not default init'able and
347
350
                # not all branches support append_revisions_only
358
361
            self.assertFalse(branch.get_append_revisions_only())
359
362
        else:
360
363
            self.assertRaises(errors.UpgradeRequired,
361
 
                branch.set_append_revisions_only, True)
 
364
                              branch.set_append_revisions_only, True)
362
365
            self.assertFalse(branch.get_append_revisions_only())
363
366
 
364
367
    def test_create_open_branch_uses_repository(self):
369
372
        child_transport = repo.controldir.root_transport.clone('child')
370
373
        child_transport.mkdir('.')
371
374
        try:
372
 
            child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
 
375
            child_dir = self.bzrdir_format.initialize_on_transport(
 
376
                child_transport)
373
377
        except errors.UninitializableFormat:
374
 
            raise tests.TestNotApplicable("control dir format not initializable")
 
378
            raise tests.TestNotApplicable(
 
379
                "control dir format not initializable")
375
380
        try:
376
381
            child_branch = self.branch_format.initialize(child_dir)
377
382
        except errors.UninitializableFormat:
429
434
            rev1 = checkout_b.commit('rev1')
430
435
        except errors.NoRoundtrippingSupport:
431
436
            raise tests.TestNotApplicable(
432
 
                    'roundtripping between %r and %r not supported' %
433
 
                    (checkout_b.branch, checkout_b.branch.get_master_branch()))
 
437
                'roundtripping between %r and %r not supported' %
 
438
                (checkout_b.branch, checkout_b.branch.get_master_branch()))
434
439
        self.assertEqual(rev1, branch_a.last_revision())
435
440
        self.assertNotEqual(checkout_b.branch.base, branch_a.base)
436
441
 
457
462
        source_branch = _mod_branch.Branch.open(url)
458
463
        # sanity check that the test will be valid
459
464
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
460
 
            source_branch.lock_write)
 
465
                          source_branch.lock_write)
461
466
        checkout = source_branch.create_checkout('c', lightweight=True)
462
467
        self.assertEqual(rev_id, checkout.last_revision())
463
468
 
474
479
        source_branch = _mod_branch.Branch.open(url)
475
480
        # sanity check that the test will be valid
476
481
        self.assertRaises((errors.LockError, errors.TransportNotPossible),
477
 
            source_branch.lock_write)
 
482
                          source_branch.lock_write)
478
483
        checkout = source_branch.create_checkout('c')
479
484
        self.assertEqual(rev_id, checkout.last_revision())
480
485
 
553
558
                          self.get_readonly_url('g/p/q'))
554
559
        branch = self.make_branch('.')
555
560
        if not branch.controldir._format.supports_transport(
556
 
            transport.get_transport_from_url(self.get_readonly_url('.'))):
 
561
                transport.get_transport_from_url(self.get_readonly_url('.'))):
557
562
            raise tests.TestNotApplicable("format does not support transport")
558
563
        branch, relpath = _mod_branch.Branch.open_containing(
559
564
            self.get_readonly_url(''))
653
658
            raise tests.TestNotApplicable('Uninitializable branch format')
654
659
 
655
660
        self.assertEqual(None,
656
 
            made_branch._format.get_reference(made_branch.controldir, name))
 
661
                         made_branch._format.get_reference(made_branch.controldir, name))
657
662
 
658
663
    def test_set_reference(self):
659
664
        """set_reference on all regular branches should be callable."""
666
671
        other_branch = self.make_branch('other')
667
672
        try:
668
673
            this_branch._format.set_reference(this_branch.controldir, None,
669
 
                other_branch)
 
674
                                              other_branch)
670
675
        except (NotImplementedError, errors.IncompatibleFormat):
671
676
            # that's ok
672
677
            pass
693
698
        self.assertEqual(direct_opened_branch.__class__, made_branch.__class__)
694
699
        self.assertEqual(opened_control, direct_opened_branch.controldir)
695
700
        self.assertIsInstance(direct_opened_branch._format,
696
 
            self.branch_format.__class__)
 
701
                              self.branch_format.__class__)
697
702
 
698
703
        # find it via Branch.open
699
704
        opened_branch = _mod_branch.Branch.open(readonly_t.base)
728
733
            self.assertIs(None, branch.get_old_bound_location())
729
734
        except errors.UpgradeRequired:
730
735
            raise tests.TestNotApplicable(
731
 
                    'Format does not store old bound locations')
 
736
                'Format does not store old bound locations')
732
737
        branch2 = self.make_branch('branch2')
733
738
        branch.bind(branch2)
734
739
        self.assertIs(None, branch.get_old_bound_location())
735
740
        branch.unbind()
736
 
        self.assertContainsRe(branch.get_old_bound_location(), '\\/branch2\\/$')
 
741
        self.assertContainsRe(
 
742
            branch.get_old_bound_location(), '\\/branch2\\/$')
737
743
 
738
744
    def test_bind_diverged(self):
739
745
        tree_a = self.make_branch_and_tree('tree_a')
772
778
        self.assertNotEqual(None, branch.get_master_branch())
773
779
        branch.bind(master2)
774
780
        self.assertEqual('.', urlutils.relative_url(self.get_url('master2'),
775
 
                branch.get_master_branch().base))
 
781
                                                    branch.get_master_branch().base))
776
782
 
777
783
    def test_set_bound_location_clears_cached_master_branch(self):
778
784
        """b.set_bound_location clears any cached value of b.get_master_branch.
788
794
        self.assertNotEqual(None, branch.get_master_branch())
789
795
        branch.set_bound_location(self.get_url('master2'))
790
796
        self.assertEqual('.', urlutils.relative_url(self.get_url('master2'),
791
 
                branch.get_master_branch().base))
 
797
                                                    branch.get_master_branch().base))
792
798
 
793
799
 
794
800
class TestStrict(per_branch.TestCaseWithBranch):
939
945
        branch = self.make_branch('branch')
940
946
        try:
941
947
            branch.set_reference_info('path/to/file',
942
 
            '../reference_branch', b'file-id')
 
948
                                      '../reference_branch', b'file-id')
943
949
        except errors.UnsupportedOperation:
944
950
            raise tests.TestNotApplicable('Branch cannot hold references.')
945
951
        referenced_branch = self.make_branch('reference_branch')
960
966
 
961
967
    def test_copied_locations_are_rebased(self):
962
968
        branch = self.make_branch_with_reference('branch', 'reference')
963
 
        new_branch = branch.controldir.sprout('branch/new-branch').open_branch()
 
969
        new_branch = branch.controldir.sprout(
 
970
            'branch/new-branch').open_branch()
964
971
        self.assertEqual('../reference',
965
972
                         new_branch.get_reference_info('path/to/file')[0])
966
973
 
982
989
 
983
990
    def test_update_references_skips_known_references(self):
984
991
        branch = self.make_branch_with_reference('branch', 'reference')
985
 
        new_branch = branch.controldir.sprout('branch/new-branch').open_branch()
 
992
        new_branch = branch.controldir.sprout(
 
993
            'branch/new-branch').open_branch()
986
994
        new_branch.set_reference_info('../foo', '../foo', b'file-id')
987
995
        new_branch.update_references(branch)
988
996
        self.assertEqual('reference',
990
998
 
991
999
    def test_pull_updates_references(self):
992
1000
        branch = self.make_branch_with_reference('branch', 'reference')
993
 
        new_branch = branch.controldir.sprout('branch/new-branch').open_branch()
 
1001
        new_branch = branch.controldir.sprout(
 
1002
            'branch/new-branch').open_branch()
994
1003
        new_branch.set_reference_info('../foo', '../foo', b'file-id2')
995
1004
        branch.pull(new_branch)
996
1005
        self.assertEqual('foo',
998
1007
 
999
1008
    def test_push_updates_references(self):
1000
1009
        branch = self.make_branch_with_reference('branch', 'reference')
1001
 
        new_branch = branch.controldir.sprout('branch/new-branch').open_branch()
 
1010
        new_branch = branch.controldir.sprout(
 
1011
            'branch/new-branch').open_branch()
1002
1012
        new_branch.set_reference_info('../foo', '../foo', b'file-id2')
1003
1013
        new_branch.push(branch)
1004
1014
        self.assertEqual('foo',
1058
1068
        super(TestUncommittedChanges, self).setUp()
1059
1069
        if not self.branch_format.supports_store_uncommitted():
1060
1070
            raise tests.TestNotApplicable(
1061
 
                    'Branch format does not support store_uncommitted')
 
1071
                'Branch format does not support store_uncommitted')
1062
1072
 
1063
1073
    def bind(self, branch, master):
1064
1074
        try: