~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_branch.py

[merge] bzr.dev 2294

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
 
83
83
    def test_append_revisions(self):
84
84
        """Test appending more than one revision"""
 
85
        wt = self.make_branch_and_tree('tree')
 
86
        wt.commit('f', rev_id='rev1')
 
87
        wt.commit('f', rev_id='rev2')
 
88
        wt.commit('f', rev_id='rev3')
 
89
 
85
90
        br = self.get_branch()
 
91
        br.fetch(wt.branch)
86
92
        br.append_revision("rev1")
87
93
        self.assertEquals(br.revision_history(), ["rev1",])
88
94
        br.append_revision("rev2", "rev3")
89
95
        self.assertEquals(br.revision_history(), ["rev1", "rev2", "rev3"])
90
96
        self.assertRaises(errors.ReservedId, br.append_revision, 'current:')
91
97
 
 
98
    def test_revision_ids_are_utf8(self):
 
99
        wt = self.make_branch_and_tree('tree')
 
100
        wt.commit('f', rev_id='rev1')
 
101
        wt.commit('f', rev_id='rev2')
 
102
        wt.commit('f', rev_id='rev3')
 
103
 
 
104
        br = self.get_branch()
 
105
        br.fetch(wt.branch)
 
106
        br.set_revision_history(['rev1', 'rev2', 'rev3'])
 
107
        rh = br.revision_history()
 
108
        self.assertEqual(['rev1', 'rev2', 'rev3'], rh)
 
109
        for revision_id in rh:
 
110
            self.assertIsInstance(revision_id, str)
 
111
        last = br.last_revision()
 
112
        self.assertEqual('rev3', last)
 
113
        self.assertIsInstance(last, str)
 
114
        revno, last = br.last_revision_info()
 
115
        self.assertEqual(3, revno)
 
116
        self.assertEqual('rev3', last)
 
117
        self.assertIsInstance(last, str)
 
118
 
92
119
    def test_fetch_revisions(self):
93
120
        """Test fetch-revision operation."""
94
121
        get_transport(self.get_url()).mkdir('b1')
213
240
        branch_d = branch_b.clone(repo_d.bzrdir)
214
241
        self.assertEqual(random_parent, branch_d.get_parent())
215
242
 
 
243
    def test_copy_content_incomplete(self):
 
244
        tree = self.make_branch_and_tree('commit_tree')
 
245
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
246
        tree.add('foo')
 
247
        tree.commit('revision 1', rev_id='1')
 
248
        source = self.make_branch_and_tree('source')
 
249
        # this gives us an incomplete repository
 
250
        tree.bzrdir.open_repository().copy_content_into(
 
251
            source.branch.repository)
 
252
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
 
253
        tree.bzrdir.open_branch().copy_content_into(source.branch)
 
254
 
 
255
 
216
256
    def test_sprout_branch_nickname(self):
217
257
        # test the nick name is reset always
218
258
        raise TestSkipped('XXX branch sprouting is not yet tested..')
327
367
        branch.nick = u"\u1234"
328
368
        self.assertEqual(branch.nick, u"\u1234")
329
369
 
330
 
    def test_commit_nicks(self):
331
 
        """Nicknames are committed to the revision"""
332
 
        get_transport(self.get_url()).mkdir('bzr.dev')
333
 
        wt = self.make_branch_and_tree('bzr.dev')
334
 
        branch = wt.branch
335
 
        branch.nick = "My happy branch"
336
 
        wt.commit('My commit respect da nick.')
337
 
        committed = branch.repository.get_revision(branch.last_revision())
338
 
        self.assertEqual(committed.properties["branch-nick"], 
339
 
                         "My happy branch")
340
 
 
341
370
    def test_create_open_branch_uses_repository(self):
342
371
        try:
343
372
            repo = self.make_repository('.', shared=True)
588
617
        self.assertEqual("foo", self.get_branch().get_push_location())
589
618
 
590
619
    def test_set_push_location(self):
591
 
        from bzrlib.config import (locations_config_filename,
592
 
                                   ensure_config_dir_exists)
593
 
        ensure_config_dir_exists()
594
 
        fn = locations_config_filename()
595
620
        branch = self.get_branch()
596
621
        branch.set_push_location('foo')
597
 
        local_path = urlutils.local_path_from_url(branch.base[:-1])
598
 
        self.assertFileEqual("[%s]\n"
599
 
                             "push_location = foo\n"
600
 
                             "push_location:policy = norecurse" % local_path,
601
 
                             fn)
602
 
 
603
 
    # TODO RBC 20051029 test getting a push location from a branch in a 
604
 
    # recursive section - that is, it appends the branch name.
 
622
        self.assertEqual('foo', branch.get_push_location())
605
623
 
606
624
 
607
625
class TestFormat(TestCaseWithBranch):
642
660
                         branch.BranchFormat.find_format(opened_control))
643
661
 
644
662
 
 
663
class TestBound(TestCaseWithBranch):
 
664
 
 
665
    def test_bind_unbind(self):
 
666
        branch = self.make_branch('1')
 
667
        branch2 = self.make_branch('2')
 
668
        try:
 
669
            branch.bind(branch2)
 
670
        except errors.UpgradeRequired:
 
671
            raise TestSkipped('Format does not support binding')
 
672
        self.assertTrue(branch.unbind())
 
673
        self.assertFalse(branch.unbind())
 
674
        self.assertIs(None, branch.get_bound_location())
 
675
 
 
676
    def test_old_bound_location(self):
 
677
        branch = self.make_branch('branch1')
 
678
        try:
 
679
            self.assertIs(None, branch.get_old_bound_location())
 
680
        except errors.UpgradeRequired:
 
681
            raise TestSkipped('Format does not store old bound locations')
 
682
        branch2 = self.make_branch('branch2')
 
683
        branch.bind(branch2)
 
684
        self.assertIs(None, branch.get_old_bound_location())
 
685
        branch.unbind()
 
686
        self.assertContainsRe(branch.get_old_bound_location(), '\/branch2\/$')
 
687
 
 
688
 
 
689
class TestStrict(TestCaseWithBranch):
 
690
 
 
691
    def test_strict_history(self):
 
692
        tree1 = self.make_branch_and_tree('tree1')
 
693
        try:
 
694
            tree1.branch.set_append_revisions_only(True)
 
695
        except errors.UpgradeRequired:
 
696
            raise TestSkipped('Format does not support strict history')
 
697
        tree1.commit('empty commit')
 
698
        tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
 
699
        tree2.commit('empty commit 2')
 
700
        tree1.pull(tree2.branch)
 
701
        tree1.commit('empty commit 3')
 
702
        tree2.commit('empty commit 4')
 
703
        self.assertRaises(errors.DivergedBranches, tree1.pull, tree2.branch)
 
704
        tree2.merge_from_branch(tree1.branch)
 
705
        tree2.commit('empty commit 5')
 
706
        self.assertRaises(errors.AppendRevisionsOnlyViolation, tree1.pull,
 
707
                          tree2.branch)
 
708
        tree3 = tree1.bzrdir.sprout('tree3').open_workingtree()
 
709
        tree3.merge_from_branch(tree2.branch)
 
710
        tree3.commit('empty commit 6')
 
711
        tree2.pull(tree3.branch)