~bzr-pqm/bzr/bzr.dev

974.1.56 by aaron.bentley at utoronto
Added merge test
1
from bzrlib.branch import Branch
2
from bzrlib.commit import commit
3
from bzrlib.selftest import TestCaseInTempDir
4
from bzrlib.merge import merge
974.1.80 by Aaron Bentley
Improved merge error handling and testing
5
from bzrlib.errors import UnrelatedBranches, NoCommits
974.1.89 by Aaron Bentley
Fixed merging with multiple roots, by using null as graph root.
6
from bzrlib.revision import common_ancestor
974.1.80 by Aaron Bentley
Improved merge error handling and testing
7
import os
974.1.56 by aaron.bentley at utoronto
Added merge test
8
class TestMerge(TestCaseInTempDir):
9
    """Test appending more than one revision"""
10
    def test_pending(self):
1185.2.19 by Lalo Martins
made tests pass again, after merge from integration
11
        br = Branch.initialize(".")
974.1.56 by aaron.bentley at utoronto
Added merge test
12
        commit(br, "lala!")
13
        self.assertEquals(len(br.pending_merges()), 0)
14
        merge(['.', -1], [None, None])
15
        self.assertEquals(len(br.pending_merges()), 0)
974.1.80 by Aaron Bentley
Improved merge error handling and testing
16
17
    def test_nocommits(self):
18
        self.test_pending()
19
        os.mkdir('branch2')
1185.2.19 by Lalo Martins
made tests pass again, after merge from integration
20
        br2 = Branch.initialize('branch2')
974.1.80 by Aaron Bentley
Improved merge error handling and testing
21
        self.assertRaises(NoCommits, merge, ['branch2', -1], 
22
                          [None, None])
23
        return br2
24
25
    def test_unrelated(self):
26
        br2 = self.test_nocommits()
27
        commit(br2, "blah")
28
        self.assertRaises(UnrelatedBranches, merge, ['branch2', -1], 
29
                          [None, None])
974.1.88 by Aaron Bentley
Set a pending_merge if the merge base is forced to revno 0
30
        return br2
974.1.80 by Aaron Bentley
Improved merge error handling and testing
31
974.1.88 by Aaron Bentley
Set a pending_merge if the merge base is forced to revno 0
32
    def test_pending_with_null(self):
33
        """When base is forced to revno 0, pending_merges is set"""
34
        br2 = self.test_unrelated()
974.1.91 by Aaron Bentley
Merged latest from mpool
35
        br1 = Branch.open('.')
974.1.88 by Aaron Bentley
Set a pending_merge if the merge base is forced to revno 0
36
        merge(['branch2', -1], ['branch2', 0])
37
        self.assertEquals(len(br1.pending_merges()), 1)
38
        return (br1, br2)
974.1.89 by Aaron Bentley
Fixed merging with multiple roots, by using null as graph root.
39
40
    def test_two_roots(self):
41
        """Merge base is sane when two unrelated branches are merged"""
42
        br1, br2 = self.test_pending_with_null()
43
        commit(br1, "blah")
44
        last = br1.last_patch()
45
        self.assertEquals(common_ancestor(last, last, br1), last)