~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

merge fix for bug #177643

Show diffs side-by-side

added added

removed removed

Lines of Context:
288
288
        merger.do_merge()
289
289
        self.assertEqual(tree_a.get_parent_ids(), [tree_b.last_revision()])
290
290
 
 
291
    def prepare_cherrypick(self):
 
292
        """Prepare a pair of trees for cherrypicking tests.
 
293
 
 
294
        Both trees have a file, 'file'.
 
295
        rev1 sets content to 'a'.
 
296
        rev2b adds 'b'.
 
297
        rev3b adds 'c'.
 
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
 
300
        'c', but not 'b'.
 
301
        """
 
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
 
314
 
 
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
 
320
        merger.do_merge()
 
321
        self.assertFileEqual('c\na\n', 'this/file')
 
322
 
 
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)
 
329
 
 
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
 
335
        merger.do_merge()
 
336
 
291
337
 
292
338
class TestPlanMerge(TestCaseWithMemoryTransport):
293
339
 
368
414
                          ('killed-a', 'b\n'),
369
415
                          ('unchanged', 'g\n')],
370
416
                         list(plan))
 
417
 
 
418
    def test_subtract_plans(self):
 
419
        old_plan = [
 
420
        ('unchanged', 'a\n'),
 
421
        ('new-a', 'b\n'),
 
422
        ('killed-a', 'c\n'),
 
423
        ('new-b', 'd\n'),
 
424
        ('new-b', 'e\n'),
 
425
        ('killed-b', 'f\n'),
 
426
        ('killed-b', 'g\n'),
 
427
        ]
 
428
        new_plan = [
 
429
        ('unchanged', 'a\n'),
 
430
        ('new-a', 'b\n'),
 
431
        ('killed-a', 'c\n'),
 
432
        ('new-b', 'd\n'),
 
433
        ('new-b', 'h\n'),
 
434
        ('killed-b', 'f\n'),
 
435
        ('killed-b', 'i\n'),
 
436
        ]
 
437
        subtracted_plan = [
 
438
        ('unchanged', 'a\n'),
 
439
        ('new-a', 'b\n'),
 
440
        ('killed-a', 'c\n'),
 
441
        ('new-b', 'h\n'),
 
442
        ('unchanged', 'f\n'),
 
443
        ('killed-b', 'i\n'),
 
444
        ]
 
445
        self.assertEqual(subtracted_plan,
 
446
            list(_PlanMerge._subtract_plans(old_plan, new_plan)))
 
447
 
 
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'),
 
455
                          ('new-b', 'f\n'),
 
456
                          ('unchanged', 'b\n'),
 
457
                          ('killed-b', 'c\n'),
 
458
                          ('new-a', 'd\n')
 
459
                         ], list(plan))