357
334
merger.merge_type = _mod_merge.Merge3Merger
358
335
merger.do_merge()
360
def test_merge3_will_detect_cherrypick(self):
361
this_tree = self.make_branch_and_tree('this')
362
self.build_tree_contents([('this/file', "a\n")])
363
this_tree.add('file')
364
this_tree.commit('rev1')
365
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
366
self.build_tree_contents([('other/file', "a\nb\n")])
367
other_tree.commit('rev2b', rev_id='rev2b')
368
self.build_tree_contents([('other/file', "a\nb\nc\n")])
369
other_tree.commit('rev3b', rev_id='rev3b')
370
this_tree.lock_write()
371
self.addCleanup(this_tree.unlock)
373
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
374
this_tree, 'rev3b', 'rev2b', other_tree.branch)
375
merger.merge_type = _mod_merge.Merge3Merger
377
self.assertFileEqual('a\n'
381
'>>>>>>> MERGE-SOURCE\n',
384
def test_make_merger(self):
385
this_tree = self.make_branch_and_tree('this')
386
this_tree.commit('rev1', rev_id='rev1')
387
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
388
this_tree.commit('rev2', rev_id='rev2a')
389
other_tree.commit('rev2', rev_id='rev2b')
390
this_tree.lock_write()
391
self.addCleanup(this_tree.unlock)
392
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress,
393
this_tree, 'rev2b', other_branch=other_tree.branch)
394
merger.merge_type = _mod_merge.Merge3Merger
395
tree_merger = merger.make_merger()
396
self.assertIs(_mod_merge.Merge3Merger, tree_merger.__class__)
397
self.assertEqual('rev2b', tree_merger.other_tree.get_revision_id())
398
self.assertEqual('rev1', tree_merger.base_tree.get_revision_id())
400
def test_make_preview_transform(self):
401
this_tree = self.make_branch_and_tree('this')
402
self.build_tree_contents([('this/file', '1\n')])
403
this_tree.add('file', 'file-id')
404
this_tree.commit('rev1', rev_id='rev1')
405
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
406
self.build_tree_contents([('this/file', '1\n2a\n')])
407
this_tree.commit('rev2', rev_id='rev2a')
408
self.build_tree_contents([('other/file', '2b\n1\n')])
409
other_tree.commit('rev2', rev_id='rev2b')
410
this_tree.lock_write()
411
self.addCleanup(this_tree.unlock)
412
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
413
this_tree, 'rev2b', other_branch=other_tree.branch)
414
merger.merge_type = _mod_merge.Merge3Merger
415
tree_merger = merger.make_merger()
416
tt = tree_merger.make_preview_transform()
417
self.addCleanup(tt.finalize)
418
preview_tree = tt.get_preview_tree()
419
tree_file = this_tree.get_file('file-id')
421
self.assertEqual('1\n2a\n', tree_file.read())
424
preview_file = preview_tree.get_file('file-id')
426
self.assertEqual('2b\n1\n2a\n', preview_file.read())
430
def test_do_merge(self):
431
this_tree = self.make_branch_and_tree('this')
432
self.build_tree_contents([('this/file', '1\n')])
433
this_tree.add('file', 'file-id')
434
this_tree.commit('rev1', rev_id='rev1')
435
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
436
self.build_tree_contents([('this/file', '1\n2a\n')])
437
this_tree.commit('rev2', rev_id='rev2a')
438
self.build_tree_contents([('other/file', '2b\n1\n')])
439
other_tree.commit('rev2', rev_id='rev2b')
440
this_tree.lock_write()
441
self.addCleanup(this_tree.unlock)
442
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
443
this_tree, 'rev2b', other_branch=other_tree.branch)
444
merger.merge_type = _mod_merge.Merge3Merger
445
tree_merger = merger.make_merger()
446
tt = tree_merger.do_merge()
447
tree_file = this_tree.get_file('file-id')
449
self.assertEqual('2b\n1\n2a\n', tree_file.read())
453
def test_merge_add_into_deleted_root(self):
454
# Yes, people actually do this. And report bugs if it breaks.
455
source = self.make_branch_and_tree('source', format='rich-root-pack')
456
self.build_tree(['source/foo/'])
457
source.add('foo', 'foo-id')
458
source.commit('Add foo')
459
target = source.bzrdir.sprout('target').open_workingtree()
460
subtree = target.extract('foo-id')
461
subtree.commit('Delete root')
462
self.build_tree(['source/bar'])
463
source.add('bar', 'bar-id')
464
source.commit('Add bar')
465
subtree.merge_from_branch(source.branch)
468
338
class TestPlanMerge(TestCaseWithMemoryTransport):
471
341
TestCaseWithMemoryTransport.setUp(self)
472
mapper = versionedfile.PrefixMapper()
473
factory = knit.make_file_factory(True, mapper)
474
self.vf = factory(self.get_transport())
475
self.plan_merge_vf = versionedfile._PlanMergeVersionedFile('root')
476
self.plan_merge_vf.fallback_versionedfiles.append(self.vf)
478
def add_version(self, key, parents, text):
479
self.vf.add_lines(key, parents, [c+'\n' for c in text])
481
def add_rev(self, prefix, revision_id, parents, text):
482
self.add_version((prefix, revision_id), [(prefix, p) for p in parents],
485
def add_uncommitted_version(self, key, parents, text):
486
self.plan_merge_vf.add_lines(key, parents,
342
self.vf = knit.KnitVersionedFile('root', self.get_transport(),
344
self.plan_merge_vf = versionedfile._PlanMergeVersionedFile('root',
347
def add_version(self, version_id, parents, text):
348
self.vf.add_lines(version_id, parents, [c+'\n' for c in text])
350
def add_uncommitted_version(self, version_id, parents, text):
351
self.plan_merge_vf.add_lines(version_id, parents,
487
352
[c+'\n' for c in text])
489
354
def setup_plan_merge(self):
490
self.add_rev('root', 'A', [], 'abc')
491
self.add_rev('root', 'B', ['A'], 'acehg')
492
self.add_rev('root', 'C', ['A'], 'fabg')
493
return _PlanMerge('B', 'C', self.plan_merge_vf, ('root',))
355
self.add_version('A', [], 'abc')
356
self.add_version('B', ['A'], 'acehg')
357
self.add_version('C', ['A'], 'fabg')
358
return _PlanMerge('B', 'C', self.plan_merge_vf)
495
360
def setup_plan_merge_uncommitted(self):
496
self.add_version(('root', 'A'), [], 'abc')
497
self.add_uncommitted_version(('root', 'B:'), [('root', 'A')], 'acehg')
498
self.add_uncommitted_version(('root', 'C:'), [('root', 'A')], 'fabg')
499
return _PlanMerge('B:', 'C:', self.plan_merge_vf, ('root',))
361
self.add_version('A', [], 'abc')
362
self.add_uncommitted_version('B:', ['A'], 'acehg')
363
self.add_uncommitted_version('C:', ['A'], 'fabg')
364
return _PlanMerge('B:', 'C:', self.plan_merge_vf)
501
366
def test_unique_lines(self):
502
367
plan = self.setup_plan_merge()
504
369
plan._get_matching_blocks('B', 'C')),
505
370
([1, 2, 3], [0, 2]))
372
def test_find_new(self):
373
plan = self.setup_plan_merge()
374
self.assertEqual(set([2, 3, 4]), plan._find_new('B'))
375
self.assertEqual(set([0, 3]), plan._find_new('C'))
377
def test_find_new2(self):
378
self.add_version('A', [], 'abc')
379
self.add_version('B', ['A'], 'abcde')
380
self.add_version('C', ['A'], 'abcefg')
381
self.add_version('D', ['A', 'B', 'C'], 'abcdegh')
382
my_plan = _PlanMerge('B', 'D', self.plan_merge_vf)
383
self.assertEqual(set([5, 6]), my_plan._find_new('D'))
384
self.assertEqual(set(), my_plan._find_new('A'))
386
def test_find_new_no_ancestors(self):
387
self.add_version('A', [], 'abc')
388
self.add_version('B', [], 'xyz')
389
my_plan = _PlanMerge('A', 'B', self.vf)
390
self.assertEqual(set([0, 1, 2]), my_plan._find_new('A'))
507
392
def test_plan_merge(self):
508
393
self.setup_plan_merge()
509
394
plan = self.plan_merge_vf.plan_merge('B', 'C')
510
395
self.assertEqual([
511
396
('new-b', 'f\n'),
512
397
('unchanged', 'a\n'),
514
398
('killed-b', 'c\n'),
515
399
('new-a', 'e\n'),
516
400
('new-a', 'h\n'),
521
def test_plan_merge_cherrypick(self):
522
self.add_rev('root', 'A', [], 'abc')
523
self.add_rev('root', 'B', ['A'], 'abcde')
524
self.add_rev('root', 'C', ['A'], 'abcefg')
525
self.add_rev('root', 'D', ['A', 'B', 'C'], 'abcdegh')
526
my_plan = _PlanMerge('B', 'D', self.plan_merge_vf, ('root',))
527
# We shortcut when one text supersedes the other in the per-file graph.
528
# We don't actually need to compare the texts at this point.
537
list(my_plan.plan_merge()))
539
def test_plan_merge_no_common_ancestor(self):
540
self.add_rev('root', 'A', [], 'abc')
541
self.add_rev('root', 'B', [], 'xyz')
542
my_plan = _PlanMerge('A', 'B', self.plan_merge_vf, ('root',))
550
list(my_plan.plan_merge()))
552
def test_plan_merge_tail_ancestors(self):
553
# The graph looks like this:
554
# A # Common to all ancestors
556
# B C # Ancestors of E, only common to one side
558
# D E F # D, F are unique to G, H respectively
559
# |/ \| # E is the LCA for G & H, and the unique LCA for
564
# I J # criss-cross merge of G, H
566
# In this situation, a simple pruning of ancestors of E will leave D &
567
# F "dangling", which looks like they introduce lines different from
568
# the ones in E, but in actuality C&B introduced the lines, and they
569
# are already present in E
571
# Introduce the base text
572
self.add_rev('root', 'A', [], 'abc')
573
# Introduces a new line B
574
self.add_rev('root', 'B', ['A'], 'aBbc')
575
# Introduces a new line C
576
self.add_rev('root', 'C', ['A'], 'abCc')
577
# Introduce new line D
578
self.add_rev('root', 'D', ['B'], 'DaBbc')
579
# Merges B and C by just incorporating both
580
self.add_rev('root', 'E', ['B', 'C'], 'aBbCc')
581
# Introduce new line F
582
self.add_rev('root', 'F', ['C'], 'abCcF')
583
# Merge D & E by just combining the texts
584
self.add_rev('root', 'G', ['D', 'E'], 'DaBbCc')
585
# Merge F & E by just combining the texts
586
self.add_rev('root', 'H', ['F', 'E'], 'aBbCcF')
587
# Merge G & H by just combining texts
588
self.add_rev('root', 'I', ['G', 'H'], 'DaBbCcF')
589
# Merge G & H but supersede an old line in B
590
self.add_rev('root', 'J', ['H', 'G'], 'DaJbCcF')
591
plan = self.plan_merge_vf.plan_merge('I', 'J')
593
('unchanged', 'D\n'),
594
('unchanged', 'a\n'),
597
('unchanged', 'b\n'),
598
('unchanged', 'C\n'),
599
('unchanged', 'c\n'),
600
('unchanged', 'F\n')],
603
def test_plan_merge_tail_triple_ancestors(self):
604
# The graph looks like this:
605
# A # Common to all ancestors
607
# B C # Ancestors of E, only common to one side
609
# D E F # D, F are unique to G, H respectively
610
# |/|\| # E is the LCA for G & H, and the unique LCA for
612
# |\ /| # Q is just an extra node which is merged into both
615
# I J # criss-cross merge of G, H
617
# This is the same as the test_plan_merge_tail_ancestors, except we add
618
# a third LCA that doesn't add new lines, but will trigger our more
619
# involved ancestry logic
621
self.add_rev('root', 'A', [], 'abc')
622
self.add_rev('root', 'B', ['A'], 'aBbc')
623
self.add_rev('root', 'C', ['A'], 'abCc')
624
self.add_rev('root', 'D', ['B'], 'DaBbc')
625
self.add_rev('root', 'E', ['B', 'C'], 'aBbCc')
626
self.add_rev('root', 'F', ['C'], 'abCcF')
627
self.add_rev('root', 'G', ['D', 'E'], 'DaBbCc')
628
self.add_rev('root', 'H', ['F', 'E'], 'aBbCcF')
629
self.add_rev('root', 'Q', ['E'], 'aBbCc')
630
self.add_rev('root', 'I', ['G', 'Q', 'H'], 'DaBbCcF')
631
# Merge G & H but supersede an old line in B
632
self.add_rev('root', 'J', ['H', 'Q', 'G'], 'DaJbCcF')
633
plan = self.plan_merge_vf.plan_merge('I', 'J')
635
('unchanged', 'D\n'),
636
('unchanged', 'a\n'),
639
('unchanged', 'b\n'),
640
('unchanged', 'C\n'),
641
('unchanged', 'c\n'),
642
('unchanged', 'F\n')],
645
def test_plan_merge_2_tail_triple_ancestors(self):
646
# The graph looks like this:
647
# A B # 2 tails going back to NULL
649
# D E F # D, is unique to G, F to H
650
# |/|\| # E is the LCA for G & H, and the unique LCA for
652
# |\ /| # Q is just an extra node which is merged into both
655
# I J # criss-cross merge of G, H (and Q)
658
# This is meant to test after hitting a 3-way LCA, and multiple tail
659
# ancestors (only have NULL_REVISION in common)
661
self.add_rev('root', 'A', [], 'abc')
662
self.add_rev('root', 'B', [], 'def')
663
self.add_rev('root', 'D', ['A'], 'Dabc')
664
self.add_rev('root', 'E', ['A', 'B'], 'abcdef')
665
self.add_rev('root', 'F', ['B'], 'defF')
666
self.add_rev('root', 'G', ['D', 'E'], 'Dabcdef')
667
self.add_rev('root', 'H', ['F', 'E'], 'abcdefF')
668
self.add_rev('root', 'Q', ['E'], 'abcdef')
669
self.add_rev('root', 'I', ['G', 'Q', 'H'], 'DabcdefF')
670
# Merge G & H but supersede an old line in B
671
self.add_rev('root', 'J', ['H', 'Q', 'G'], 'DabcdJfF')
672
plan = self.plan_merge_vf.plan_merge('I', 'J')
674
('unchanged', 'D\n'),
675
('unchanged', 'a\n'),
676
('unchanged', 'b\n'),
677
('unchanged', 'c\n'),
678
('unchanged', 'd\n'),
681
('unchanged', 'f\n'),
682
('unchanged', 'F\n')],
402
('unchanged', 'g\n')],
685
405
def test_plan_merge_uncommitted_files(self):
688
408
self.assertEqual([
689
409
('new-b', 'f\n'),
690
410
('unchanged', 'a\n'),
692
411
('killed-b', 'c\n'),
693
412
('new-a', 'e\n'),
694
413
('new-a', 'h\n'),
699
def test_plan_merge_insert_order(self):
700
"""Weave merges are sensitive to the order of insertion.
702
Specifically for overlapping regions, it effects which region gets put
703
'first'. And when a user resolves an overlapping merge, if they use the
704
same ordering, then the lines match the parents, if they don't only
705
*some* of the lines match.
707
self.add_rev('root', 'A', [], 'abcdef')
708
self.add_rev('root', 'B', ['A'], 'abwxcdef')
709
self.add_rev('root', 'C', ['A'], 'abyzcdef')
710
# Merge, and resolve the conflict by adding *both* sets of lines
711
# If we get the ordering wrong, these will look like new lines in D,
712
# rather than carried over from B, C
713
self.add_rev('root', 'D', ['B', 'C'],
715
# Supersede the lines in B and delete the lines in C, which will
716
# conflict if they are treated as being in D
717
self.add_rev('root', 'E', ['C', 'B'],
719
# Same thing for the lines in C
720
self.add_rev('root', 'F', ['C'], 'abpqcdef')
721
plan = self.plan_merge_vf.plan_merge('D', 'E')
723
('unchanged', 'a\n'),
724
('unchanged', 'b\n'),
731
('unchanged', 'c\n'),
732
('unchanged', 'd\n'),
733
('unchanged', 'e\n'),
734
('unchanged', 'f\n')],
736
plan = self.plan_merge_vf.plan_merge('E', 'D')
737
# Going in the opposite direction shows the effect of the opposite plan
739
('unchanged', 'a\n'),
740
('unchanged', 'b\n'),
745
('killed-both', 'w\n'),
746
('killed-both', 'x\n'),
749
('unchanged', 'c\n'),
750
('unchanged', 'd\n'),
751
('unchanged', 'e\n'),
752
('unchanged', 'f\n')],
755
def test_plan_merge_criss_cross(self):
756
# This is specificly trying to trigger problems when using limited
757
# ancestry and weaves. The ancestry graph looks like:
758
# XX unused ancestor, should not show up in the weave
762
# B \ Introduces a line 'foo'
764
# C D E C & D both have 'foo', E has different changes
768
# F G All of C, D, E are merged into F and G, so they are
769
# all common ancestors.
771
# The specific issue with weaves:
772
# B introduced a text ('foo') that is present in both C and D.
773
# If we do not include B (because it isn't an ancestor of E), then
774
# the A=>C and A=>D look like both sides independently introduce the
775
# text ('foo'). If F does not modify the text, it would still appear
776
# to have deleted on of the versions from C or D. If G then modifies
777
# 'foo', it should appear as superseding the value in F (since it
778
# came from B), rather than conflict because of the resolution during
780
self.add_rev('root', 'XX', [], 'qrs')
781
self.add_rev('root', 'A', ['XX'], 'abcdef')
782
self.add_rev('root', 'B', ['A'], 'axcdef')
783
self.add_rev('root', 'C', ['B'], 'axcdefg')
784
self.add_rev('root', 'D', ['B'], 'haxcdef')
785
self.add_rev('root', 'E', ['A'], 'abcdyf')
786
# Simple combining of all texts
787
self.add_rev('root', 'F', ['C', 'D', 'E'], 'haxcdyfg')
788
# combine and supersede 'x'
789
self.add_rev('root', 'G', ['C', 'D', 'E'], 'hazcdyfg')
790
plan = self.plan_merge_vf.plan_merge('F', 'G')
792
('unchanged', 'h\n'),
793
('unchanged', 'a\n'),
794
('killed-base', 'b\n'),
797
('unchanged', 'c\n'),
798
('unchanged', 'd\n'),
799
('killed-base', 'e\n'),
800
('unchanged', 'y\n'),
801
('unchanged', 'f\n'),
802
415
('unchanged', 'g\n')],
805
def assertRemoveExternalReferences(self, filtered_parent_map,
806
child_map, tails, parent_map):
807
"""Assert results for _PlanMerge._remove_external_references."""
808
(act_filtered_parent_map, act_child_map,
809
act_tails) = _PlanMerge._remove_external_references(parent_map)
811
# The parent map *should* preserve ordering, but the ordering of
812
# children is not strictly defined
813
# child_map = dict((k, sorted(children))
814
# for k, children in child_map.iteritems())
815
# act_child_map = dict(k, sorted(children)
816
# for k, children in act_child_map.iteritems())
817
self.assertEqual(filtered_parent_map, act_filtered_parent_map)
818
self.assertEqual(child_map, act_child_map)
819
self.assertEqual(sorted(tails), sorted(act_tails))
821
def test__remove_external_references(self):
822
# First, nothing to remove
823
self.assertRemoveExternalReferences({3: [2], 2: [1], 1: []},
824
{1: [2], 2: [3], 3: []}, [1], {3: [2], 2: [1], 1: []})
825
# The reverse direction
826
self.assertRemoveExternalReferences({1: [2], 2: [3], 3: []},
827
{3: [2], 2: [1], 1: []}, [3], {1: [2], 2: [3], 3: []})
829
self.assertRemoveExternalReferences({3: [2], 2: [1], 1: []},
830
{1: [2], 2: [3], 3: []}, [1], {3: [2, 4], 2: [1, 5], 1: [6]})
832
self.assertRemoveExternalReferences(
833
{4: [2, 3], 3: [], 2: [1], 1: []},
834
{1: [2], 2: [4], 3: [4], 4: []},
836
{4: [2, 3], 3: [5], 2: [1], 1: [6]})
838
self.assertRemoveExternalReferences(
839
{1: [3], 2: [3, 4], 3: [], 4: []},
840
{1: [], 2: [], 3: [1, 2], 4: [2]},
842
{1: [3], 2: [3, 4], 3: [5], 4: []})
844
def assertPruneTails(self, pruned_map, tails, parent_map):
846
for key, parent_keys in parent_map.iteritems():
847
child_map.setdefault(key, [])
848
for pkey in parent_keys:
849
child_map.setdefault(pkey, []).append(key)
850
_PlanMerge._prune_tails(parent_map, child_map, tails)
851
self.assertEqual(pruned_map, parent_map)
853
def test__prune_tails(self):
854
# Nothing requested to prune
855
self.assertPruneTails({1: [], 2: [], 3: []}, [],
856
{1: [], 2: [], 3: []})
857
# Prune a single entry
858
self.assertPruneTails({1: [], 3: []}, [2],
859
{1: [], 2: [], 3: []})
861
self.assertPruneTails({1: []}, [3],
862
{1: [], 2: [3], 3: []})
863
# Prune a chain with a diamond
864
self.assertPruneTails({1: []}, [5],
865
{1: [], 2: [3, 4], 3: [5], 4: [5], 5: []})
866
# Prune a partial chain
867
self.assertPruneTails({1: [6], 6:[]}, [5],
868
{1: [2, 6], 2: [3, 4], 3: [5], 4: [5], 5: [],
870
# Prune a chain with multiple tips, that pulls out intermediates
871
self.assertPruneTails({1:[3], 3:[]}, [4, 5],
872
{1: [2, 3], 2: [4, 5], 3: [], 4:[], 5:[]})
873
self.assertPruneTails({1:[3], 3:[]}, [5, 4],
874
{1: [2, 3], 2: [4, 5], 3: [], 4:[], 5:[]})
876
418
def test_subtract_plans(self):
878
420
('unchanged', 'a\n'),
918
457
('killed-b', 'c\n'),
922
def test_plan_lca_merge(self):
923
self.setup_plan_merge()
924
plan = self.plan_merge_vf.plan_lca_merge('B', 'C')
927
('unchanged', 'a\n'),
932
('unchanged', 'g\n')],
935
def test_plan_lca_merge_uncommitted_files(self):
936
self.setup_plan_merge_uncommitted()
937
plan = self.plan_merge_vf.plan_lca_merge('B:', 'C:')
940
('unchanged', 'a\n'),
945
('unchanged', 'g\n')],
948
def test_plan_lca_merge_with_base(self):
949
self.setup_merge_with_base()
950
plan = self.plan_merge_vf.plan_lca_merge('THIS', 'OTHER', 'BASE')
951
self.assertEqual([('unchanged', 'a\n'),
953
('unchanged', 'b\n'),
958
def test_plan_lca_merge_with_criss_cross(self):
959
self.add_version(('root', 'ROOT'), [], 'abc')
960
# each side makes a change
961
self.add_version(('root', 'REV1'), [('root', 'ROOT')], 'abcd')
962
self.add_version(('root', 'REV2'), [('root', 'ROOT')], 'abce')
963
# both sides merge, discarding others' changes
964
self.add_version(('root', 'LCA1'),
965
[('root', 'REV1'), ('root', 'REV2')], 'abcd')
966
self.add_version(('root', 'LCA2'),
967
[('root', 'REV1'), ('root', 'REV2')], 'fabce')
968
plan = self.plan_merge_vf.plan_lca_merge('LCA1', 'LCA2')
969
self.assertEqual([('new-b', 'f\n'),
970
('unchanged', 'a\n'),
971
('unchanged', 'b\n'),
972
('unchanged', 'c\n'),
973
('conflicted-a', 'd\n'),
974
('conflicted-b', 'e\n'),
977
def test_plan_lca_merge_with_null(self):
978
self.add_version(('root', 'A'), [], 'ab')
979
self.add_version(('root', 'B'), [], 'bc')
980
plan = self.plan_merge_vf.plan_lca_merge('A', 'B')
981
self.assertEqual([('new-a', 'a\n'),
982
('unchanged', 'b\n'),
986
def test_plan_merge_with_delete_and_change(self):
987
self.add_rev('root', 'C', [], 'a')
988
self.add_rev('root', 'A', ['C'], 'b')
989
self.add_rev('root', 'B', ['C'], '')
990
plan = self.plan_merge_vf.plan_merge('A', 'B')
991
self.assertEqual([('killed-both', 'a\n'),
995
def test_plan_merge_with_move_and_change(self):
996
self.add_rev('root', 'C', [], 'abcd')
997
self.add_rev('root', 'A', ['C'], 'acbd')
998
self.add_rev('root', 'B', ['C'], 'aBcd')
999
plan = self.plan_merge_vf.plan_merge('A', 'B')
1000
self.assertEqual([('unchanged', 'a\n'),
1002
('killed-b', 'b\n'),
1004
('killed-a', 'c\n'),
1005
('unchanged', 'd\n'),
1009
class TestMergeImplementation(object):
1011
def do_merge(self, target_tree, source_tree, **kwargs):
1012
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1013
target_tree, source_tree.last_revision(),
1014
other_branch=source_tree.branch)
1015
merger.merge_type=self.merge_type
1016
for name, value in kwargs.items():
1017
setattr(merger, name, value)
1020
def test_merge_specific_file(self):
1021
this_tree = self.make_branch_and_tree('this')
1022
this_tree.lock_write()
1023
self.addCleanup(this_tree.unlock)
1024
self.build_tree_contents([
1025
('this/file1', 'a\nb\n'),
1026
('this/file2', 'a\nb\n')
1028
this_tree.add(['file1', 'file2'])
1029
this_tree.commit('Added files')
1030
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
1031
self.build_tree_contents([
1032
('other/file1', 'a\nb\nc\n'),
1033
('other/file2', 'a\nb\nc\n')
1035
other_tree.commit('modified both')
1036
self.build_tree_contents([
1037
('this/file1', 'd\na\nb\n'),
1038
('this/file2', 'd\na\nb\n')
1040
this_tree.commit('modified both')
1041
self.do_merge(this_tree, other_tree, interesting_files=['file1'])
1042
self.assertFileEqual('d\na\nb\nc\n', 'this/file1')
1043
self.assertFileEqual('d\na\nb\n', 'this/file2')
1045
def test_merge_move_and_change(self):
1046
this_tree = self.make_branch_and_tree('this')
1047
this_tree.lock_write()
1048
self.addCleanup(this_tree.unlock)
1049
self.build_tree_contents([
1050
('this/file1', 'line 1\nline 2\nline 3\nline 4\n'),
1052
this_tree.add('file1',)
1053
this_tree.commit('Added file')
1054
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
1055
self.build_tree_contents([
1056
('other/file1', 'line 1\nline 2 to 2.1\nline 3\nline 4\n'),
1058
other_tree.commit('Changed 2 to 2.1')
1059
self.build_tree_contents([
1060
('this/file1', 'line 1\nline 3\nline 2\nline 4\n'),
1062
this_tree.commit('Swapped 2 & 3')
1063
self.do_merge(this_tree, other_tree)
1064
self.assertFileEqual('line 1\n'
1071
'>>>>>>> MERGE-SOURCE\n'
1072
'line 4\n', 'this/file1')
1075
class TestMerge3Merge(TestCaseWithTransport, TestMergeImplementation):
1077
merge_type = _mod_merge.Merge3Merger
1080
class TestWeaveMerge(TestCaseWithTransport, TestMergeImplementation):
1082
merge_type = _mod_merge.WeaveMerger
1085
class TestLCAMerge(TestCaseWithTransport, TestMergeImplementation):
1087
merge_type = _mod_merge.LCAMerger
1089
def test_merge_move_and_change(self):
1090
self.expectFailure("lca merge doesn't conflict for move and change",
1091
super(TestLCAMerge, self).test_merge_move_and_change)