2
from StringIO import StringIO
4
from bzrlib.branch import Branch
5
from bzrlib.builtins import merge
6
from bzrlib.commit import commit
7
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
8
from bzrlib.merge import transform_tree, merge_inner
9
from bzrlib.osutils import pathjoin
10
from bzrlib.revision import common_ancestor
11
from bzrlib.tests import TestCaseWithTransport
12
from bzrlib.trace import (enable_test_log, disable_test_log)
13
from bzrlib.workingtree import WorkingTree
16
class TestMerge(TestCaseWithTransport):
17
"""Test appending more than one revision"""
19
def test_pending(self):
20
wt = self.make_branch_and_tree('.')
22
self.assertEquals(len(wt.pending_merges()), 0)
23
merge([u'.', -1], [None, None])
24
self.assertEquals(len(wt.pending_merges()), 0)
27
wt = self.make_branch_and_tree('.')
31
merge([u'.', 2], [u'.', 1])
33
def test_nocommits(self):
35
wt2 = self.make_branch_and_tree('branch2')
36
self.assertRaises(NoCommits, merge, ['branch2', -1],
40
def test_unrelated(self):
41
wt2 = self.test_nocommits()
43
self.assertRaises(UnrelatedBranches, merge, ['branch2', -1],
47
def test_pending_with_null(self):
48
"""When base is forced to revno 0, pending_merges is set"""
49
wt2 = self.test_unrelated()
50
wt1 = WorkingTree.open('.')
53
# merge all of branch 2 into branch 1 even though they
55
self.assertRaises(BzrCommandError, merge, ['branch2', -1],
56
['branch2', 0], reprocess=True, show_base=True)
57
merge(['branch2', -1], ['branch2', 0], reprocess=True)
58
self.assertEquals(len(wt1.pending_merges()), 1)
59
return (wt1, wt2.branch)
61
def test_two_roots(self):
62
"""Merge base is sane when two unrelated branches are merged"""
63
wt1, br2 = self.test_pending_with_null()
65
last = wt1.branch.last_revision()
66
self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last)
68
def test_create_rename(self):
69
"""Rename an inventory entry while creating the file"""
70
tree =self.make_branch_and_tree('.')
71
file('name1', 'wb').write('Hello')
73
tree.commit(message="hello")
74
tree.rename_one('name1', 'name2')
76
transform_tree(tree, tree.branch.basis_tree())
78
def test_layered_rename(self):
79
"""Rename both child and parent at same time"""
80
tree =self.make_branch_and_tree('.')
83
filename = pathjoin('dirname1', 'name1')
84
file(filename, 'wb').write('Hello')
86
tree.commit(message="hello")
87
filename2 = pathjoin('dirname1', 'name2')
88
tree.rename_one(filename, filename2)
89
tree.rename_one('dirname1', 'dirname2')
90
transform_tree(tree, tree.branch.basis_tree())
92
def test_ignore_zero_merge_inner(self):
93
# Test that merge_inner's ignore zero paramter is effective
94
tree_a =self.make_branch_and_tree('a')
95
tree_a.commit(message="hello")
96
dir_b = tree_a.bzrdir.sprout('b')
97
tree_b = dir_b.open_workingtree()
98
tree_a.commit(message="hello again")
100
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
101
this_tree=tree_b, ignore_zero=True)
102
log = self._get_log()
103
self.failUnless('All changes applied successfully.\n' not in log)
105
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
106
this_tree=tree_b, ignore_zero=False)
107
log = self._get_log()
108
self.failUnless('All changes applied successfully.\n' in log)