~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testmerge.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-08 18:36:26 UTC
  • mto: This revision was merged to the branch mainline in revision 1727.
  • Revision ID: john@arbash-meinel.com-20051108183626-71f8414338043265
Updating unified_diff to take a factory, using the new diff algorithm in the code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
1
3
from bzrlib.branch import Branch
2
4
from bzrlib.commit import commit
3
5
from bzrlib.selftest import TestCaseInTempDir
4
6
from bzrlib.merge import merge
5
 
from bzrlib.errors import UnrelatedBranches, NoCommits
6
 
import os
 
7
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
 
8
from bzrlib.revision import common_ancestor
 
9
from bzrlib.fetch import fetch
 
10
 
 
11
 
7
12
class TestMerge(TestCaseInTempDir):
8
13
    """Test appending more than one revision"""
9
14
    def test_pending(self):
10
 
        br = Branch(".", init=True)
 
15
        br = Branch.initialize(".")
11
16
        commit(br, "lala!")
12
17
        self.assertEquals(len(br.pending_merges()), 0)
13
18
        merge(['.', -1], [None, None])
16
21
    def test_nocommits(self):
17
22
        self.test_pending()
18
23
        os.mkdir('branch2')
19
 
        br2 = Branch('branch2', init=True)
 
24
        br2 = Branch.initialize('branch2')
20
25
        self.assertRaises(NoCommits, merge, ['branch2', -1], 
21
26
                          [None, None])
22
27
        return br2
24
29
    def test_unrelated(self):
25
30
        br2 = self.test_nocommits()
26
31
        commit(br2, "blah")
27
 
        merge, ['branch2', -1], [None, None]
28
32
        self.assertRaises(UnrelatedBranches, merge, ['branch2', -1], 
29
33
                          [None, None])
30
 
 
 
34
        return br2
 
35
 
 
36
    def test_pending_with_null(self):
 
37
        """When base is forced to revno 0, pending_merges is set"""
 
38
        br2 = self.test_unrelated()
 
39
        br1 = Branch.open('.')
 
40
        fetch(from_branch=br2, to_branch=br1)
 
41
        # merge all of branch 2 into branch 1 even though they 
 
42
        # are not related.
 
43
        self.assertRaises(BzrCommandError, merge, ['branch2', -1], 
 
44
                          ['branch2', 0], reprocess=True, show_base=True)
 
45
        merge(['branch2', -1], ['branch2', 0], reprocess=True)
 
46
        self.assertEquals(len(br1.pending_merges()), 1)
 
47
        return (br1, br2)
 
48
 
 
49
    def test_two_roots(self):
 
50
        """Merge base is sane when two unrelated branches are merged"""
 
51
        br1, br2 = self.test_pending_with_null()
 
52
        commit(br1, "blah")
 
53
        last = br1.last_revision()
 
54
        self.assertEquals(common_ancestor(last, last, br1), last)