~ubuntu-branches/ubuntu/hardy/bzr/hardy-updates

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Etienne Goyer
  • Date: 2007-03-07 08:55:49 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20070307085549-2y0nzag1hotluiah
Tags: upstream-0.15~rc1
ImportĀ upstreamĀ versionĀ 0.15~rc1

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"])
 
96
        self.assertRaises(errors.ReservedId, br.append_revision, 'current:')
 
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)
90
118
 
91
119
    def test_fetch_revisions(self):
92
120
        """Test fetch-revision operation."""
212
240
        branch_d = branch_b.clone(repo_d.bzrdir)
213
241
        self.assertEqual(random_parent, branch_d.get_parent())
214
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
 
215
256
    def test_sprout_branch_nickname(self):
216
257
        # test the nick name is reset always
217
258
        raise TestSkipped('XXX branch sprouting is not yet tested..')
326
367
        branch.nick = u"\u1234"
327
368
        self.assertEqual(branch.nick, u"\u1234")
328
369
 
329
 
    def test_commit_nicks(self):
330
 
        """Nicknames are committed to the revision"""
331
 
        get_transport(self.get_url()).mkdir('bzr.dev')
332
 
        wt = self.make_branch_and_tree('bzr.dev')
333
 
        branch = wt.branch
334
 
        branch.nick = "My happy branch"
335
 
        wt.commit('My commit respect da nick.')
336
 
        committed = branch.repository.get_revision(branch.last_revision())
337
 
        self.assertEqual(committed.properties["branch-nick"], 
338
 
                         "My happy branch")
339
 
 
340
370
    def test_create_open_branch_uses_repository(self):
341
371
        try:
342
372
            repo = self.make_repository('.', shared=True)
587
617
        self.assertEqual("foo", self.get_branch().get_push_location())
588
618
 
589
619
    def test_set_push_location(self):
590
 
        from bzrlib.config import (locations_config_filename,
591
 
                                   ensure_config_dir_exists)
592
 
        ensure_config_dir_exists()
593
 
        fn = locations_config_filename()
594
620
        branch = self.get_branch()
595
621
        branch.set_push_location('foo')
596
 
        local_path = urlutils.local_path_from_url(branch.base[:-1])
597
 
        self.assertFileEqual("[%s]\n"
598
 
                             "push_location = foo\n"
599
 
                             "push_location:policy = norecurse" % local_path,
600
 
                             fn)
601
 
 
602
 
    # TODO RBC 20051029 test getting a push location from a branch in a 
603
 
    # recursive section - that is, it appends the branch name.
 
622
        self.assertEqual('foo', branch.get_push_location())
604
623
 
605
624
 
606
625
class TestFormat(TestCaseWithBranch):
641
660
                         branch.BranchFormat.find_format(opened_control))
642
661
 
643
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)