1147
class TestMergeImplementation(object):
1149
def do_merge(self, target_tree, source_tree, **kwargs):
1150
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1151
target_tree, source_tree.last_revision(),
1152
other_branch=source_tree.branch)
1153
merger.merge_type=self.merge_type
1154
for name, value in kwargs.items():
1155
setattr(merger, name, value)
1158
def test_merge_specific_file(self):
1159
this_tree = self.make_branch_and_tree('this')
1160
this_tree.lock_write()
1161
self.addCleanup(this_tree.unlock)
1162
self.build_tree_contents([
1163
('this/file1', 'a\nb\n'),
1164
('this/file2', 'a\nb\n')
1166
this_tree.add(['file1', 'file2'])
1167
this_tree.commit('Added files')
1168
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
1169
self.build_tree_contents([
1170
('other/file1', 'a\nb\nc\n'),
1171
('other/file2', 'a\nb\nc\n')
1173
other_tree.commit('modified both')
1174
self.build_tree_contents([
1175
('this/file1', 'd\na\nb\n'),
1176
('this/file2', 'd\na\nb\n')
1178
this_tree.commit('modified both')
1179
self.do_merge(this_tree, other_tree, interesting_files=['file1'])
1180
self.assertFileEqual('d\na\nb\nc\n', 'this/file1')
1181
self.assertFileEqual('d\na\nb\n', 'this/file2')
1183
def test_merge_move_and_change(self):
1184
this_tree = self.make_branch_and_tree('this')
1185
this_tree.lock_write()
1186
self.addCleanup(this_tree.unlock)
1187
self.build_tree_contents([
1188
('this/file1', 'line 1\nline 2\nline 3\nline 4\n'),
1190
this_tree.add('file1',)
1191
this_tree.commit('Added file')
1192
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
1193
self.build_tree_contents([
1194
('other/file1', 'line 1\nline 2 to 2.1\nline 3\nline 4\n'),
1196
other_tree.commit('Changed 2 to 2.1')
1197
self.build_tree_contents([
1198
('this/file1', 'line 1\nline 3\nline 2\nline 4\n'),
1200
this_tree.commit('Swapped 2 & 3')
1201
self.do_merge(this_tree, other_tree)
1202
self.assertFileEqual('line 1\n'
1209
'>>>>>>> MERGE-SOURCE\n'
1210
'line 4\n', 'this/file1')
1212
def test_modify_conflicts_with_delete(self):
1213
# If one side deletes a line, and the other modifies that line, then
1214
# the modification should be considered a conflict
1215
builder = self.make_branch_builder('test')
1216
builder.start_series()
1217
builder.build_snapshot('BASE-id', None,
1218
[('add', ('', None, 'directory', None)),
1219
('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
1222
builder.build_snapshot('OTHER-id', ['BASE-id'],
1223
[('modify', ('foo-id', 'a\nc\nd\ne\n'))])
1224
# Modify 'b\n', add 'X\n'
1225
builder.build_snapshot('THIS-id', ['BASE-id'],
1226
[('modify', ('foo-id', 'a\nb2\nc\nd\nX\ne\n'))])
1227
builder.finish_series()
1228
branch = builder.get_branch()
1229
this_tree = branch.bzrdir.create_workingtree()
1230
this_tree.lock_write()
1231
self.addCleanup(this_tree.unlock)
1232
other_tree = this_tree.bzrdir.sprout('other', 'OTHER-id').open_workingtree()
1233
self.do_merge(this_tree, other_tree)
1234
if self.merge_type is _mod_merge.LCAMerger:
1235
self.expectFailure("lca merge doesn't track deleted lines",
1236
self.assertFileEqual,
1241
'>>>>>>> MERGE-SOURCE\n'
1247
self.assertFileEqual(
1252
'>>>>>>> MERGE-SOURCE\n'
1258
def get_limbodir_deletiondir(self, wt):
1259
transform = TreeTransform(wt)
1260
limbodir = transform._limbodir
1261
deletiondir = transform._deletiondir
1262
transform.finalize()
1263
return (limbodir, deletiondir)
1265
def test_merge_with_existing_limbo(self):
1266
wt = self.make_branch_and_tree('this')
1267
(limbodir, deletiondir) = self.get_limbodir_deletiondir(wt)
1269
self.assertRaises(errors.ExistingLimbo, self.do_merge, wt, wt)
1270
self.assertRaises(errors.LockError, wt.unlock)
1272
def test_merge_with_pending_deletion(self):
1273
wt = self.make_branch_and_tree('this')
1274
(limbodir, deletiondir) = self.get_limbodir_deletiondir(wt)
1275
os.mkdir(deletiondir)
1276
self.assertRaises(errors.ExistingPendingDeletion, self.do_merge, wt, wt)
1277
self.assertRaises(errors.LockError, wt.unlock)
1280
class TestMerge3Merge(TestCaseWithTransport, TestMergeImplementation):
1282
merge_type = _mod_merge.Merge3Merger
1285
class TestWeaveMerge(TestCaseWithTransport, TestMergeImplementation):
1287
merge_type = _mod_merge.WeaveMerger
1290
class TestLCAMerge(TestCaseWithTransport, TestMergeImplementation):
1292
merge_type = _mod_merge.LCAMerger
1294
def test_merge_move_and_change(self):
1295
self.expectFailure("lca merge doesn't conflict for move and change",
1296
super(TestLCAMerge, self).test_merge_move_and_change)
1299
1145
class LoggingMerger(object):
1300
1146
# These seem to be the required attributes
1301
1147
requires_base = False