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)
26
def test_nocommits(self):
28
wt2 = self.make_branch_and_tree('branch2')
29
self.assertRaises(NoCommits, merge, ['branch2', -1],
33
def test_unrelated(self):
34
wt2 = self.test_nocommits()
36
self.assertRaises(UnrelatedBranches, merge, ['branch2', -1],
40
def test_pending_with_null(self):
41
"""When base is forced to revno 0, pending_merges is set"""
42
wt2 = self.test_unrelated()
43
wt1 = WorkingTree.open('.')
46
# merge all of branch 2 into branch 1 even though they
48
self.assertRaises(BzrCommandError, merge, ['branch2', -1],
49
['branch2', 0], reprocess=True, show_base=True)
50
merge(['branch2', -1], ['branch2', 0], reprocess=True)
51
self.assertEquals(len(wt1.pending_merges()), 1)
52
return (wt1, wt2.branch)
54
def test_two_roots(self):
55
"""Merge base is sane when two unrelated branches are merged"""
56
wt1, br2 = self.test_pending_with_null()
58
last = wt1.branch.last_revision()
59
self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last)
61
def test_create_rename(self):
62
"""Rename an inventory entry while creating the file"""
63
tree =self.make_branch_and_tree('.')
64
file('name1', 'wb').write('Hello')
66
tree.commit(message="hello")
67
tree.rename_one('name1', 'name2')
69
transform_tree(tree, tree.branch.basis_tree())
71
def test_layered_rename(self):
72
"""Rename both child and parent at same time"""
73
tree =self.make_branch_and_tree('.')
76
filename = pathjoin('dirname1', 'name1')
77
file(filename, 'wb').write('Hello')
79
tree.commit(message="hello")
80
filename2 = pathjoin('dirname1', 'name2')
81
tree.rename_one(filename, filename2)
82
tree.rename_one('dirname1', 'dirname2')
83
transform_tree(tree, tree.branch.basis_tree())
85
def test_ignore_zero_merge_inner(self):
86
# Test that merge_inner's ignore zero paramter is effective
87
tree_a =self.make_branch_and_tree('a')
88
tree_a.commit(message="hello")
89
dir_b = tree_a.bzrdir.sprout('b')
90
tree_b = dir_b.open_workingtree()
91
tree_a.commit(message="hello again")
93
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
94
this_tree=tree_b, ignore_zero=True)
95
lines = self._get_log().splitlines(True)[-1]
96
self.failUnless('All changes applied successfully.\n' not in lines)
98
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
99
this_tree=tree_b, ignore_zero=False)
100
lines = self._get_log().splitlines(True)[-1]
101
self.failUnless('All changes applied successfully.\n' in lines)