288
288
merger.do_merge()
289
289
self.assertEqual(tree_a.get_parent_ids(), [tree_b.last_revision()])
291
def prepare_cherrypick(self):
292
"""Prepare a pair of trees for cherrypicking tests.
294
Both trees have a file, 'file'.
295
rev1 sets content to 'a'.
298
A full merge of rev2b and rev3b into this_tree would add both 'b' and
299
'c'. A successful cherrypick of rev2b-rev3b into this_tree will add
302
this_tree = self.make_branch_and_tree('this')
303
self.build_tree_contents([('this/file', "a\n")])
304
this_tree.add('file')
305
this_tree.commit('rev1')
306
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
307
self.build_tree_contents([('other/file', "a\nb\n")])
308
other_tree.commit('rev2b', rev_id='rev2b')
309
self.build_tree_contents([('other/file', "c\na\nb\n")])
310
other_tree.commit('rev3b', rev_id='rev3b')
311
this_tree.lock_write()
312
self.addCleanup(this_tree.unlock)
313
return this_tree, other_tree
315
def test_weave_cherrypick(self):
316
this_tree, other_tree = self.prepare_cherrypick()
317
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
318
this_tree, 'rev3b', 'rev2b', other_tree.branch)
319
merger.merge_type = _mod_merge.WeaveMerger
321
self.assertFileEqual('c\na\n', 'this/file')
323
def test_weave_cannot_reverse_cherrypick(self):
324
this_tree, other_tree = self.prepare_cherrypick()
325
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
326
this_tree, 'rev2b', 'rev3b', other_tree.branch)
327
merger.merge_type = _mod_merge.WeaveMerger
328
self.assertRaises(errors.CannotReverseCherrypick, merger.do_merge)
330
def test_merge3_can_reverse_cherrypick(self):
331
this_tree, other_tree = self.prepare_cherrypick()
332
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
333
this_tree, 'rev2b', 'rev3b', other_tree.branch)
334
merger.merge_type = _mod_merge.Merge3Merger
292
338
class TestPlanMerge(TestCaseWithMemoryTransport):
368
414
('killed-a', 'b\n'),
369
415
('unchanged', 'g\n')],
418
def test_subtract_plans(self):
420
('unchanged', 'a\n'),
429
('unchanged', 'a\n'),
438
('unchanged', 'a\n'),
442
('unchanged', 'f\n'),
445
self.assertEqual(subtracted_plan,
446
list(_PlanMerge._subtract_plans(old_plan, new_plan)))
448
def test_plan_merge_with_base(self):
449
self.add_version('COMMON', [], 'abc')
450
self.add_version('THIS', ['COMMON'], 'abcd')
451
self.add_version('BASE', ['COMMON'], 'eabc')
452
self.add_version('OTHER', ['BASE'], 'eafb')
453
plan = self.plan_merge_vf.plan_merge('THIS', 'OTHER', 'BASE')
454
self.assertEqual([('unchanged', 'a\n'),
456
('unchanged', 'b\n'),