3
from bzrlib.branch import Branch
4
from bzrlib.builtins import merge
5
from bzrlib.commit import commit
6
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
7
from bzrlib.merge import transform_tree
8
from bzrlib.osutils import pathjoin
9
from bzrlib.revision import common_ancestor
10
from bzrlib.tests import TestCaseWithTransport
11
from bzrlib.workingtree import WorkingTree
14
class TestMerge(TestCaseWithTransport):
15
"""Test appending more than one revision"""
17
def test_pending(self):
18
wt = self.make_branch_and_tree('.')
20
self.assertEquals(len(wt.pending_merges()), 0)
21
merge([u'.', -1], [None, None])
22
self.assertEquals(len(wt.pending_merges()), 0)
24
def test_nocommits(self):
26
wt2 = self.make_branch_and_tree('branch2')
27
self.assertRaises(NoCommits, merge, ['branch2', -1],
31
def test_unrelated(self):
32
wt2 = self.test_nocommits()
34
self.assertRaises(UnrelatedBranches, merge, ['branch2', -1],
38
def test_pending_with_null(self):
39
"""When base is forced to revno 0, pending_merges is set"""
40
wt2 = self.test_unrelated()
41
wt1 = WorkingTree.open('.')
44
# merge all of branch 2 into branch 1 even though they
46
self.assertRaises(BzrCommandError, merge, ['branch2', -1],
47
['branch2', 0], reprocess=True, show_base=True)
48
merge(['branch2', -1], ['branch2', 0], reprocess=True)
49
self.assertEquals(len(wt1.pending_merges()), 1)
50
return (wt1, wt2.branch)
52
def test_two_roots(self):
53
"""Merge base is sane when two unrelated branches are merged"""
54
wt1, br2 = self.test_pending_with_null()
56
last = wt1.branch.last_revision()
57
self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last)
59
def test_create_rename(self):
60
"""Rename an inventory entry while creating the file"""
61
tree =self.make_branch_and_tree('.')
62
file('name1', 'wb').write('Hello')
64
tree.commit(message="hello")
65
tree.rename_one('name1', 'name2')
67
transform_tree(tree, tree.branch.basis_tree())
69
def test_layered_rename(self):
70
"""Rename both child and parent at same time"""
71
tree =self.make_branch_and_tree('.')
74
filename = pathjoin('dirname1', 'name1')
75
file(filename, 'wb').write('Hello')
77
tree.commit(message="hello")
78
filename2 = pathjoin('dirname1', 'name2')
79
tree.rename_one(filename, filename2)
80
tree.rename_one('dirname1', 'dirname2')
81
transform_tree(tree, tree.branch.basis_tree())