1
# Copyright (C) 2009 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Implementation tests for bzrlib.merge.Merger."""
27
from bzrlib.tests import (
29
TestCaseWithTransport,
31
from bzrlib.transform import TreeTransform
35
def load_tests(standard_tests, module, loader):
36
"""Multiply tests for tranport implementations."""
37
result = loader.suiteClass()
39
(name, {'merge_type': merger})
40
for name, merger in option._merge_type_registry.items()]
41
return multiply_tests(standard_tests, scenarios, result)
44
class TestMergeImplementation(TestCaseWithTransport):
46
def do_merge(self, target_tree, source_tree, **kwargs):
47
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
48
target_tree, source_tree.last_revision(),
49
other_branch=source_tree.branch)
50
merger.merge_type=self.merge_type
51
for name, value in kwargs.items():
52
setattr(merger, name, value)
55
def test_merge_specific_file(self):
56
this_tree = self.make_branch_and_tree('this')
57
this_tree.lock_write()
58
self.addCleanup(this_tree.unlock)
59
self.build_tree_contents([
60
('this/file1', 'a\nb\n'),
61
('this/file2', 'a\nb\n')
63
this_tree.add(['file1', 'file2'])
64
this_tree.commit('Added files')
65
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
66
self.build_tree_contents([
67
('other/file1', 'a\nb\nc\n'),
68
('other/file2', 'a\nb\nc\n')
70
other_tree.commit('modified both')
71
self.build_tree_contents([
72
('this/file1', 'd\na\nb\n'),
73
('this/file2', 'd\na\nb\n')
75
this_tree.commit('modified both')
76
self.do_merge(this_tree, other_tree, interesting_files=['file1'])
77
self.assertFileEqual('d\na\nb\nc\n', 'this/file1')
78
self.assertFileEqual('d\na\nb\n', 'this/file2')
80
def test_merge_move_and_change(self):
81
this_tree = self.make_branch_and_tree('this')
82
this_tree.lock_write()
83
self.addCleanup(this_tree.unlock)
84
self.build_tree_contents([
85
('this/file1', 'line 1\nline 2\nline 3\nline 4\n'),
87
this_tree.add('file1',)
88
this_tree.commit('Added file')
89
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
90
self.build_tree_contents([
91
('other/file1', 'line 1\nline 2 to 2.1\nline 3\nline 4\n'),
93
other_tree.commit('Changed 2 to 2.1')
94
self.build_tree_contents([
95
('this/file1', 'line 1\nline 3\nline 2\nline 4\n'),
97
this_tree.commit('Swapped 2 & 3')
98
self.do_merge(this_tree, other_tree)
99
if self.merge_type is _mod_merge.LCAMerger:
101
"lca merge doesn't conflict for move and change",
102
self.assertFileEqual,
110
'>>>>>>> MERGE-SOURCE\n'
111
'line 4\n', 'this/file1')
113
self.assertFileEqual('line 1\n'
120
'>>>>>>> MERGE-SOURCE\n'
121
'line 4\n', 'this/file1')
123
def test_modify_conflicts_with_delete(self):
124
# If one side deletes a line, and the other modifies that line, then
125
# the modification should be considered a conflict
126
builder = self.make_branch_builder('test')
127
builder.start_series()
128
builder.build_snapshot('BASE-id', None,
129
[('add', ('', None, 'directory', None)),
130
('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
133
builder.build_snapshot('OTHER-id', ['BASE-id'],
134
[('modify', ('foo-id', 'a\nc\nd\ne\n'))])
135
# Modify 'b\n', add 'X\n'
136
builder.build_snapshot('THIS-id', ['BASE-id'],
137
[('modify', ('foo-id', 'a\nb2\nc\nd\nX\ne\n'))])
138
builder.finish_series()
139
branch = builder.get_branch()
140
this_tree = branch.bzrdir.create_workingtree()
141
this_tree.lock_write()
142
self.addCleanup(this_tree.unlock)
143
other_tree = this_tree.bzrdir.sprout('other', 'OTHER-id').open_workingtree()
144
self.do_merge(this_tree, other_tree)
145
if self.merge_type is _mod_merge.LCAMerger:
146
self.expectFailure("lca merge doesn't track deleted lines",
147
self.assertFileEqual,
152
'>>>>>>> MERGE-SOURCE\n'
158
self.assertFileEqual(
163
'>>>>>>> MERGE-SOURCE\n'
169
def get_limbodir_deletiondir(self, wt):
170
transform = TreeTransform(wt)
171
limbodir = transform._limbodir
172
deletiondir = transform._deletiondir
174
return (limbodir, deletiondir)
176
def test_merge_with_existing_limbo(self):
177
wt = self.make_branch_and_tree('this')
178
(limbodir, deletiondir) = self.get_limbodir_deletiondir(wt)
180
self.assertRaises(errors.ExistingLimbo, self.do_merge, wt, wt)
181
self.assertRaises(errors.LockError, wt.unlock)
183
def test_merge_with_pending_deletion(self):
184
wt = self.make_branch_and_tree('this')
185
(limbodir, deletiondir) = self.get_limbodir_deletiondir(wt)
186
os.mkdir(deletiondir)
187
self.assertRaises(errors.ExistingPendingDeletion, self.do_merge, wt, wt)
188
self.assertRaises(errors.LockError, wt.unlock)