1
# Copyright (C) 2005, 2006 by Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2
18
from StringIO import StringIO
20
from bzrlib import conflicts
4
21
from bzrlib.branch import Branch
5
22
from bzrlib.builtins import merge
6
from bzrlib.commit import commit
23
from bzrlib.conflicts import ConflictList, TextConflict
7
24
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
8
25
from bzrlib.merge import transform_tree, merge_inner
9
26
from bzrlib.osutils import pathjoin
19
36
def test_pending(self):
20
37
wt = self.make_branch_and_tree('.')
22
self.assertEquals(len(wt.pending_merges()), 0)
38
rev_a = wt.commit("lala!")
39
self.assertEqual([rev_a], wt.get_parent_ids())
23
40
merge([u'.', -1], [None, None])
24
self.assertEquals(len(wt.pending_merges()), 0)
41
self.assertEqual([rev_a], wt.get_parent_ids())
26
43
def test_undo(self):
27
44
wt = self.make_branch_and_tree('.')
47
def test_merge_one(self):
64
def test_merge_one_file(self):
65
"""Do a partial merge of a tree which should not affect tree parents."""
48
66
wt1 = self.make_branch_and_tree('branch1')
49
wt1.commit('empty commit')
67
tip = wt1.commit('empty commit')
50
68
wt2 = self.make_branch_and_tree('branch2')
51
69
wt2.pull(wt1.branch)
52
70
file('branch1/foo', 'wb').write('foo')
59
77
self.run_bzr('merge', '../branch1/foo')
60
78
self.failUnlessExists('foo')
61
79
self.failIfExists('bar')
62
wt2 = WorkingTree.open_containing('branch2')[0]
63
self.assertEqual(wt2.pending_merges(), [])
80
wt2 = WorkingTree.open('.') # opens branch2
81
self.assertEqual([tip], wt2.get_parent_ids())
65
83
def test_pending_with_null(self):
66
84
"""When base is forced to revno 0, pending_merges is set"""
67
85
wt2 = self.test_unrelated()
70
88
br1.fetch(wt2.branch)
71
89
# merge all of branch 2 into branch 1 even though they
73
self.assertRaises(BzrCommandError, merge, ['branch2', -1],
91
self.assertRaises(BzrCommandError, merge, ['branch2', -1],
74
92
['branch2', 0], reprocess=True, show_base=True)
75
93
merge(['branch2', -1], ['branch2', 0], reprocess=True)
76
self.assertEquals(len(wt1.pending_merges()), 1)
94
self.assertEqual([br1.last_revision(), wt2.branch.last_revision()],
77
96
return (wt1, wt2.branch)
79
98
def test_two_roots(self):
81
100
wt1, br2 = self.test_pending_with_null()
82
101
wt1.commit("blah")
83
102
last = wt1.branch.last_revision()
84
self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last)
103
self.assertEqual(common_ancestor(last, last, wt1.branch.repository), last)
86
105
def test_create_rename(self):
87
106
"""Rename an inventory entry while creating the file"""
108
127
transform_tree(tree, tree.branch.basis_tree())
110
129
def test_ignore_zero_merge_inner(self):
111
# Test that merge_inner's ignore zero paramter is effective
130
# Test that merge_inner's ignore zero parameter is effective
112
131
tree_a =self.make_branch_and_tree('a')
113
132
tree_a.commit(message="hello")
114
133
dir_b = tree_a.bzrdir.sprout('b')
124
143
this_tree=tree_b, ignore_zero=False)
125
144
log = self._get_log()
126
145
self.failUnless('All changes applied successfully.\n' in log)
147
def test_merge_inner_conflicts(self):
148
tree_a = self.make_branch_and_tree('a')
149
tree_a.set_conflicts(ConflictList([TextConflict('patha')]))
150
merge_inner(tree_a.branch, tree_a, tree_a, this_tree=tree_a)
151
self.assertEqual(1, len(tree_a.conflicts()))
153
def test_rmdir_conflict(self):
154
tree_a = self.make_branch_and_tree('a')
155
self.build_tree(['a/b/'])
156
tree_a.add('b', 'b-id')
157
tree_a.commit('added b')
158
base_tree = tree_a.basis_tree()
159
tree_z = tree_a.bzrdir.sprout('z').open_workingtree()
160
self.build_tree(['a/b/c'])
162
tree_a.commit('added c')
164
tree_z.commit('removed b')
165
merge_inner(tree_z.branch, tree_a, base_tree, this_tree=tree_z)
167
conflicts.MissingParent('Created directory', 'b', 'b-id'),
168
conflicts.UnversionedParent('Versioned directory', 'b', 'b-id')],
170
merge_inner(tree_a.branch, tree_z.basis_tree(), base_tree,
173
conflicts.DeletingParent('Not deleting', 'b', 'b-id'),
174
conflicts.UnversionedParent('Versioned directory', 'b', 'b-id')],