/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: Martin
  • Date: 2018-11-16 19:09:31 UTC
  • mfrom: (7175 work)
  • mto: This revision was merged to the branch mainline in revision 7177.
  • Revision ID: gzlist@googlemail.com-20181116190931-rmh7pk2an1zuecby
Merge trunk to resolve conflicts

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