3
from bzrlib.branch import Branch
4
from bzrlib.commit import commit
5
from bzrlib.selftest import TestCaseInTempDir
6
from bzrlib.merge import merge
7
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
8
from bzrlib.revision import common_ancestor
9
from bzrlib.fetch import fetch
12
class TestMerge(TestCaseInTempDir):
13
"""Test appending more than one revision"""
14
def test_pending(self):
15
br = Branch.initialize(".")
17
self.assertEquals(len(br.working_tree().pending_merges()), 0)
18
merge(['.', -1], [None, None])
19
self.assertEquals(len(br.working_tree().pending_merges()), 0)
21
def test_nocommits(self):
24
br2 = Branch.initialize('branch2')
25
self.assertRaises(NoCommits, merge, ['branch2', -1],
29
def test_unrelated(self):
30
br2 = self.test_nocommits()
32
self.assertRaises(UnrelatedBranches, merge, ['branch2', -1],
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
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.working_tree().pending_merges()), 1)
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()
53
last = br1.last_revision()
54
self.assertEquals(common_ancestor(last, last, br1), last)