236
247
self.assertEqual(tree_b.conflicts(),
237
248
[conflicts.ContentsConflict('file',
238
249
file_id='file-id')])
240
251
def test_merge_type_registry(self):
241
252
merge_type_option = option.Option.OPTIONS['merge-type']
242
self.assertFalse('merge4' in [x[0] for x in
253
self.assertFalse('merge4' in [x[0] for x in
243
254
merge_type_option.iter_switches()])
244
255
registry = _mod_merge.get_merge_type_registry()
245
256
registry.register_lazy('merge4', 'bzrlib.merge', 'Merge4Merger',
246
257
'time-travelling merge')
247
self.assertTrue('merge4' in [x[0] for x in
258
self.assertTrue('merge4' in [x[0] for x in
248
259
merge_type_option.iter_switches()])
249
260
registry.remove('merge4')
250
self.assertFalse('merge4' in [x[0] for x in
261
self.assertFalse('merge4' in [x[0] for x in
251
262
merge_type_option.iter_switches()])
264
def test_merge_other_moves_we_deleted(self):
265
tree_a = self.make_branch_and_tree('A')
267
self.addCleanup(tree_a.unlock)
268
self.build_tree(['A/a'])
270
tree_a.commit('1', rev_id='rev-1')
272
tree_a.rename_one('a', 'b')
274
bzrdir_b = tree_a.bzrdir.sprout('B', revision_id='rev-1')
275
tree_b = bzrdir_b.open_workingtree()
277
self.addCleanup(tree_b.unlock)
281
tree_b.merge_from_branch(tree_a.branch)
282
except AttributeError:
283
self.fail('tried to join a path when name was None')
285
def test_merge_uncommitted_otherbasis_ancestor_of_thisbasis(self):
286
tree_a = self.make_branch_and_tree('a')
287
self.build_tree(['a/file_1', 'a/file_2'])
288
tree_a.add(['file_1'])
289
tree_a.commit('commit 1')
290
tree_a.add(['file_2'])
291
tree_a.commit('commit 2')
292
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
293
tree_b.rename_one('file_1', 'renamed')
294
merger = _mod_merge.Merger.from_uncommitted(tree_a, tree_b,
295
progress.DummyProgress())
296
merger.merge_type = _mod_merge.Merge3Merger
298
self.assertEqual(tree_a.get_parent_ids(), [tree_b.last_revision()])
300
def test_merge_uncommitted_otherbasis_ancestor_of_thisbasis_weave(self):
301
tree_a = self.make_branch_and_tree('a')
302
self.build_tree(['a/file_1', 'a/file_2'])
303
tree_a.add(['file_1'])
304
tree_a.commit('commit 1')
305
tree_a.add(['file_2'])
306
tree_a.commit('commit 2')
307
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
308
tree_b.rename_one('file_1', 'renamed')
309
merger = _mod_merge.Merger.from_uncommitted(tree_a, tree_b,
310
progress.DummyProgress())
311
merger.merge_type = _mod_merge.WeaveMerger
313
self.assertEqual(tree_a.get_parent_ids(), [tree_b.last_revision()])
315
def test_Merger_defaults_to_DummyProgress(self):
316
branch = self.make_branch('branch')
317
merger = _mod_merge.Merger(branch, pb=None)
318
self.assertIsInstance(merger._pb, progress.DummyProgress)
320
def prepare_cherrypick(self):
321
"""Prepare a pair of trees for cherrypicking tests.
323
Both trees have a file, 'file'.
324
rev1 sets content to 'a'.
327
A full merge of rev2b and rev3b into this_tree would add both 'b' and
328
'c'. A successful cherrypick of rev2b-rev3b into this_tree will add
331
this_tree = self.make_branch_and_tree('this')
332
self.build_tree_contents([('this/file', "a\n")])
333
this_tree.add('file')
334
this_tree.commit('rev1')
335
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
336
self.build_tree_contents([('other/file', "a\nb\n")])
337
other_tree.commit('rev2b', rev_id='rev2b')
338
self.build_tree_contents([('other/file', "c\na\nb\n")])
339
other_tree.commit('rev3b', rev_id='rev3b')
340
this_tree.lock_write()
341
self.addCleanup(this_tree.unlock)
342
return this_tree, other_tree
344
def test_weave_cherrypick(self):
345
this_tree, other_tree = self.prepare_cherrypick()
346
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
347
this_tree, 'rev3b', 'rev2b', other_tree.branch)
348
merger.merge_type = _mod_merge.WeaveMerger
350
self.assertFileEqual('c\na\n', 'this/file')
352
def test_weave_cannot_reverse_cherrypick(self):
353
this_tree, other_tree = self.prepare_cherrypick()
354
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
355
this_tree, 'rev2b', 'rev3b', other_tree.branch)
356
merger.merge_type = _mod_merge.WeaveMerger
357
self.assertRaises(errors.CannotReverseCherrypick, merger.do_merge)
359
def test_merge3_can_reverse_cherrypick(self):
360
this_tree, other_tree = self.prepare_cherrypick()
361
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
362
this_tree, 'rev2b', 'rev3b', other_tree.branch)
363
merger.merge_type = _mod_merge.Merge3Merger
366
def test_merge3_will_detect_cherrypick(self):
367
this_tree = self.make_branch_and_tree('this')
368
self.build_tree_contents([('this/file', "a\n")])
369
this_tree.add('file')
370
this_tree.commit('rev1')
371
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
372
self.build_tree_contents([('other/file', "a\nb\n")])
373
other_tree.commit('rev2b', rev_id='rev2b')
374
self.build_tree_contents([('other/file', "a\nb\nc\n")])
375
other_tree.commit('rev3b', rev_id='rev3b')
376
this_tree.lock_write()
377
self.addCleanup(this_tree.unlock)
379
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
380
this_tree, 'rev3b', 'rev2b', other_tree.branch)
381
merger.merge_type = _mod_merge.Merge3Merger
383
self.assertFileEqual('a\n'
387
'>>>>>>> MERGE-SOURCE\n',
390
def test_make_merger(self):
391
this_tree = self.make_branch_and_tree('this')
392
this_tree.commit('rev1', rev_id='rev1')
393
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
394
this_tree.commit('rev2', rev_id='rev2a')
395
other_tree.commit('rev2', rev_id='rev2b')
396
this_tree.lock_write()
397
self.addCleanup(this_tree.unlock)
398
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress,
399
this_tree, 'rev2b', other_branch=other_tree.branch)
400
merger.merge_type = _mod_merge.Merge3Merger
401
tree_merger = merger.make_merger()
402
self.assertIs(_mod_merge.Merge3Merger, tree_merger.__class__)
403
self.assertEqual('rev2b', tree_merger.other_tree.get_revision_id())
404
self.assertEqual('rev1', tree_merger.base_tree.get_revision_id())
406
def test_make_preview_transform(self):
407
this_tree = self.make_branch_and_tree('this')
408
self.build_tree_contents([('this/file', '1\n')])
409
this_tree.add('file', 'file-id')
410
this_tree.commit('rev1', rev_id='rev1')
411
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
412
self.build_tree_contents([('this/file', '1\n2a\n')])
413
this_tree.commit('rev2', rev_id='rev2a')
414
self.build_tree_contents([('other/file', '2b\n1\n')])
415
other_tree.commit('rev2', rev_id='rev2b')
416
this_tree.lock_write()
417
self.addCleanup(this_tree.unlock)
418
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
419
this_tree, 'rev2b', other_branch=other_tree.branch)
420
merger.merge_type = _mod_merge.Merge3Merger
421
tree_merger = merger.make_merger()
422
tt = tree_merger.make_preview_transform()
423
self.addCleanup(tt.finalize)
424
preview_tree = tt.get_preview_tree()
425
tree_file = this_tree.get_file('file-id')
427
self.assertEqual('1\n2a\n', tree_file.read())
430
preview_file = preview_tree.get_file('file-id')
432
self.assertEqual('2b\n1\n2a\n', preview_file.read())
436
def test_do_merge(self):
437
this_tree = self.make_branch_and_tree('this')
438
self.build_tree_contents([('this/file', '1\n')])
439
this_tree.add('file', 'file-id')
440
this_tree.commit('rev1', rev_id='rev1')
441
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
442
self.build_tree_contents([('this/file', '1\n2a\n')])
443
this_tree.commit('rev2', rev_id='rev2a')
444
self.build_tree_contents([('other/file', '2b\n1\n')])
445
other_tree.commit('rev2', rev_id='rev2b')
446
this_tree.lock_write()
447
self.addCleanup(this_tree.unlock)
448
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
449
this_tree, 'rev2b', other_branch=other_tree.branch)
450
merger.merge_type = _mod_merge.Merge3Merger
451
tree_merger = merger.make_merger()
452
tt = tree_merger.do_merge()
453
tree_file = this_tree.get_file('file-id')
455
self.assertEqual('2b\n1\n2a\n', tree_file.read())
459
def test_merge_add_into_deleted_root(self):
460
# Yes, people actually do this. And report bugs if it breaks.
461
source = self.make_branch_and_tree('source', format='rich-root-pack')
462
self.build_tree(['source/foo/'])
463
source.add('foo', 'foo-id')
464
source.commit('Add foo')
465
target = source.bzrdir.sprout('target').open_workingtree()
466
subtree = target.extract('foo-id')
467
subtree.commit('Delete root')
468
self.build_tree(['source/bar'])
469
source.add('bar', 'bar-id')
470
source.commit('Add bar')
471
subtree.merge_from_branch(source.branch)
473
def test_merge_joined_branch(self):
474
source = self.make_branch_and_tree('source', format='rich-root-pack')
475
self.build_tree(['source/foo'])
477
source.commit('Add foo')
478
target = self.make_branch_and_tree('target', format='rich-root-pack')
479
self.build_tree(['target/bla'])
481
target.commit('Add bla')
482
nested = source.bzrdir.sprout('target/subtree').open_workingtree()
483
target.subsume(nested)
484
target.commit('Join nested')
485
self.build_tree(['source/bar'])
487
source.commit('Add bar')
488
target.merge_from_branch(source.branch)
489
target.commit('Merge source')
492
class TestPlanMerge(TestCaseWithMemoryTransport):
495
TestCaseWithMemoryTransport.setUp(self)
496
mapper = versionedfile.PrefixMapper()
497
factory = knit.make_file_factory(True, mapper)
498
self.vf = factory(self.get_transport())
499
self.plan_merge_vf = versionedfile._PlanMergeVersionedFile('root')
500
self.plan_merge_vf.fallback_versionedfiles.append(self.vf)
502
def add_version(self, key, parents, text):
503
self.vf.add_lines(key, parents, [c+'\n' for c in text])
505
def add_rev(self, prefix, revision_id, parents, text):
506
self.add_version((prefix, revision_id), [(prefix, p) for p in parents],
509
def add_uncommitted_version(self, key, parents, text):
510
self.plan_merge_vf.add_lines(key, parents,
511
[c+'\n' for c in text])
513
def setup_plan_merge(self):
514
self.add_rev('root', 'A', [], 'abc')
515
self.add_rev('root', 'B', ['A'], 'acehg')
516
self.add_rev('root', 'C', ['A'], 'fabg')
517
return _PlanMerge('B', 'C', self.plan_merge_vf, ('root',))
519
def setup_plan_merge_uncommitted(self):
520
self.add_version(('root', 'A'), [], 'abc')
521
self.add_uncommitted_version(('root', 'B:'), [('root', 'A')], 'acehg')
522
self.add_uncommitted_version(('root', 'C:'), [('root', 'A')], 'fabg')
523
return _PlanMerge('B:', 'C:', self.plan_merge_vf, ('root',))
525
def test_unique_lines(self):
526
plan = self.setup_plan_merge()
527
self.assertEqual(plan._unique_lines(
528
plan._get_matching_blocks('B', 'C')),
531
def test_plan_merge(self):
532
self.setup_plan_merge()
533
plan = self.plan_merge_vf.plan_merge('B', 'C')
536
('unchanged', 'a\n'),
545
def test_plan_merge_cherrypick(self):
546
self.add_rev('root', 'A', [], 'abc')
547
self.add_rev('root', 'B', ['A'], 'abcde')
548
self.add_rev('root', 'C', ['A'], 'abcefg')
549
self.add_rev('root', 'D', ['A', 'B', 'C'], 'abcdegh')
550
my_plan = _PlanMerge('B', 'D', self.plan_merge_vf, ('root',))
551
# We shortcut when one text supersedes the other in the per-file graph.
552
# We don't actually need to compare the texts at this point.
561
list(my_plan.plan_merge()))
563
def test_plan_merge_no_common_ancestor(self):
564
self.add_rev('root', 'A', [], 'abc')
565
self.add_rev('root', 'B', [], 'xyz')
566
my_plan = _PlanMerge('A', 'B', self.plan_merge_vf, ('root',))
574
list(my_plan.plan_merge()))
576
def test_plan_merge_tail_ancestors(self):
577
# The graph looks like this:
578
# A # Common to all ancestors
580
# B C # Ancestors of E, only common to one side
582
# D E F # D, F are unique to G, H respectively
583
# |/ \| # E is the LCA for G & H, and the unique LCA for
588
# I J # criss-cross merge of G, H
590
# In this situation, a simple pruning of ancestors of E will leave D &
591
# F "dangling", which looks like they introduce lines different from
592
# the ones in E, but in actuality C&B introduced the lines, and they
593
# are already present in E
595
# Introduce the base text
596
self.add_rev('root', 'A', [], 'abc')
597
# Introduces a new line B
598
self.add_rev('root', 'B', ['A'], 'aBbc')
599
# Introduces a new line C
600
self.add_rev('root', 'C', ['A'], 'abCc')
601
# Introduce new line D
602
self.add_rev('root', 'D', ['B'], 'DaBbc')
603
# Merges B and C by just incorporating both
604
self.add_rev('root', 'E', ['B', 'C'], 'aBbCc')
605
# Introduce new line F
606
self.add_rev('root', 'F', ['C'], 'abCcF')
607
# Merge D & E by just combining the texts
608
self.add_rev('root', 'G', ['D', 'E'], 'DaBbCc')
609
# Merge F & E by just combining the texts
610
self.add_rev('root', 'H', ['F', 'E'], 'aBbCcF')
611
# Merge G & H by just combining texts
612
self.add_rev('root', 'I', ['G', 'H'], 'DaBbCcF')
613
# Merge G & H but supersede an old line in B
614
self.add_rev('root', 'J', ['H', 'G'], 'DaJbCcF')
615
plan = self.plan_merge_vf.plan_merge('I', 'J')
617
('unchanged', 'D\n'),
618
('unchanged', 'a\n'),
621
('unchanged', 'b\n'),
622
('unchanged', 'C\n'),
623
('unchanged', 'c\n'),
624
('unchanged', 'F\n')],
627
def test_plan_merge_tail_triple_ancestors(self):
628
# The graph looks like this:
629
# A # Common to all ancestors
631
# B C # Ancestors of E, only common to one side
633
# D E F # D, F are unique to G, H respectively
634
# |/|\| # E is the LCA for G & H, and the unique LCA for
636
# |\ /| # Q is just an extra node which is merged into both
639
# I J # criss-cross merge of G, H
641
# This is the same as the test_plan_merge_tail_ancestors, except we add
642
# a third LCA that doesn't add new lines, but will trigger our more
643
# involved ancestry logic
645
self.add_rev('root', 'A', [], 'abc')
646
self.add_rev('root', 'B', ['A'], 'aBbc')
647
self.add_rev('root', 'C', ['A'], 'abCc')
648
self.add_rev('root', 'D', ['B'], 'DaBbc')
649
self.add_rev('root', 'E', ['B', 'C'], 'aBbCc')
650
self.add_rev('root', 'F', ['C'], 'abCcF')
651
self.add_rev('root', 'G', ['D', 'E'], 'DaBbCc')
652
self.add_rev('root', 'H', ['F', 'E'], 'aBbCcF')
653
self.add_rev('root', 'Q', ['E'], 'aBbCc')
654
self.add_rev('root', 'I', ['G', 'Q', 'H'], 'DaBbCcF')
655
# Merge G & H but supersede an old line in B
656
self.add_rev('root', 'J', ['H', 'Q', 'G'], 'DaJbCcF')
657
plan = self.plan_merge_vf.plan_merge('I', 'J')
659
('unchanged', 'D\n'),
660
('unchanged', 'a\n'),
663
('unchanged', 'b\n'),
664
('unchanged', 'C\n'),
665
('unchanged', 'c\n'),
666
('unchanged', 'F\n')],
669
def test_plan_merge_2_tail_triple_ancestors(self):
670
# The graph looks like this:
671
# A B # 2 tails going back to NULL
673
# D E F # D, is unique to G, F to H
674
# |/|\| # E is the LCA for G & H, and the unique LCA for
676
# |\ /| # Q is just an extra node which is merged into both
679
# I J # criss-cross merge of G, H (and Q)
682
# This is meant to test after hitting a 3-way LCA, and multiple tail
683
# ancestors (only have NULL_REVISION in common)
685
self.add_rev('root', 'A', [], 'abc')
686
self.add_rev('root', 'B', [], 'def')
687
self.add_rev('root', 'D', ['A'], 'Dabc')
688
self.add_rev('root', 'E', ['A', 'B'], 'abcdef')
689
self.add_rev('root', 'F', ['B'], 'defF')
690
self.add_rev('root', 'G', ['D', 'E'], 'Dabcdef')
691
self.add_rev('root', 'H', ['F', 'E'], 'abcdefF')
692
self.add_rev('root', 'Q', ['E'], 'abcdef')
693
self.add_rev('root', 'I', ['G', 'Q', 'H'], 'DabcdefF')
694
# Merge G & H but supersede an old line in B
695
self.add_rev('root', 'J', ['H', 'Q', 'G'], 'DabcdJfF')
696
plan = self.plan_merge_vf.plan_merge('I', 'J')
698
('unchanged', 'D\n'),
699
('unchanged', 'a\n'),
700
('unchanged', 'b\n'),
701
('unchanged', 'c\n'),
702
('unchanged', 'd\n'),
705
('unchanged', 'f\n'),
706
('unchanged', 'F\n')],
709
def test_plan_merge_uncommitted_files(self):
710
self.setup_plan_merge_uncommitted()
711
plan = self.plan_merge_vf.plan_merge('B:', 'C:')
714
('unchanged', 'a\n'),
723
def test_plan_merge_insert_order(self):
724
"""Weave merges are sensitive to the order of insertion.
726
Specifically for overlapping regions, it effects which region gets put
727
'first'. And when a user resolves an overlapping merge, if they use the
728
same ordering, then the lines match the parents, if they don't only
729
*some* of the lines match.
731
self.add_rev('root', 'A', [], 'abcdef')
732
self.add_rev('root', 'B', ['A'], 'abwxcdef')
733
self.add_rev('root', 'C', ['A'], 'abyzcdef')
734
# Merge, and resolve the conflict by adding *both* sets of lines
735
# If we get the ordering wrong, these will look like new lines in D,
736
# rather than carried over from B, C
737
self.add_rev('root', 'D', ['B', 'C'],
739
# Supersede the lines in B and delete the lines in C, which will
740
# conflict if they are treated as being in D
741
self.add_rev('root', 'E', ['C', 'B'],
743
# Same thing for the lines in C
744
self.add_rev('root', 'F', ['C'], 'abpqcdef')
745
plan = self.plan_merge_vf.plan_merge('D', 'E')
747
('unchanged', 'a\n'),
748
('unchanged', 'b\n'),
755
('unchanged', 'c\n'),
756
('unchanged', 'd\n'),
757
('unchanged', 'e\n'),
758
('unchanged', 'f\n')],
760
plan = self.plan_merge_vf.plan_merge('E', 'D')
761
# Going in the opposite direction shows the effect of the opposite plan
763
('unchanged', 'a\n'),
764
('unchanged', 'b\n'),
769
('killed-both', 'w\n'),
770
('killed-both', 'x\n'),
773
('unchanged', 'c\n'),
774
('unchanged', 'd\n'),
775
('unchanged', 'e\n'),
776
('unchanged', 'f\n')],
779
def test_plan_merge_criss_cross(self):
780
# This is specificly trying to trigger problems when using limited
781
# ancestry and weaves. The ancestry graph looks like:
782
# XX unused ancestor, should not show up in the weave
786
# B \ Introduces a line 'foo'
788
# C D E C & D both have 'foo', E has different changes
792
# F G All of C, D, E are merged into F and G, so they are
793
# all common ancestors.
795
# The specific issue with weaves:
796
# B introduced a text ('foo') that is present in both C and D.
797
# If we do not include B (because it isn't an ancestor of E), then
798
# the A=>C and A=>D look like both sides independently introduce the
799
# text ('foo'). If F does not modify the text, it would still appear
800
# to have deleted on of the versions from C or D. If G then modifies
801
# 'foo', it should appear as superseding the value in F (since it
802
# came from B), rather than conflict because of the resolution during
804
self.add_rev('root', 'XX', [], 'qrs')
805
self.add_rev('root', 'A', ['XX'], 'abcdef')
806
self.add_rev('root', 'B', ['A'], 'axcdef')
807
self.add_rev('root', 'C', ['B'], 'axcdefg')
808
self.add_rev('root', 'D', ['B'], 'haxcdef')
809
self.add_rev('root', 'E', ['A'], 'abcdyf')
810
# Simple combining of all texts
811
self.add_rev('root', 'F', ['C', 'D', 'E'], 'haxcdyfg')
812
# combine and supersede 'x'
813
self.add_rev('root', 'G', ['C', 'D', 'E'], 'hazcdyfg')
814
plan = self.plan_merge_vf.plan_merge('F', 'G')
816
('unchanged', 'h\n'),
817
('unchanged', 'a\n'),
818
('killed-base', 'b\n'),
821
('unchanged', 'c\n'),
822
('unchanged', 'd\n'),
823
('killed-base', 'e\n'),
824
('unchanged', 'y\n'),
825
('unchanged', 'f\n'),
826
('unchanged', 'g\n')],
829
def assertRemoveExternalReferences(self, filtered_parent_map,
830
child_map, tails, parent_map):
831
"""Assert results for _PlanMerge._remove_external_references."""
832
(act_filtered_parent_map, act_child_map,
833
act_tails) = _PlanMerge._remove_external_references(parent_map)
835
# The parent map *should* preserve ordering, but the ordering of
836
# children is not strictly defined
837
# child_map = dict((k, sorted(children))
838
# for k, children in child_map.iteritems())
839
# act_child_map = dict(k, sorted(children)
840
# for k, children in act_child_map.iteritems())
841
self.assertEqual(filtered_parent_map, act_filtered_parent_map)
842
self.assertEqual(child_map, act_child_map)
843
self.assertEqual(sorted(tails), sorted(act_tails))
845
def test__remove_external_references(self):
846
# First, nothing to remove
847
self.assertRemoveExternalReferences({3: [2], 2: [1], 1: []},
848
{1: [2], 2: [3], 3: []}, [1], {3: [2], 2: [1], 1: []})
849
# The reverse direction
850
self.assertRemoveExternalReferences({1: [2], 2: [3], 3: []},
851
{3: [2], 2: [1], 1: []}, [3], {1: [2], 2: [3], 3: []})
853
self.assertRemoveExternalReferences({3: [2], 2: [1], 1: []},
854
{1: [2], 2: [3], 3: []}, [1], {3: [2, 4], 2: [1, 5], 1: [6]})
856
self.assertRemoveExternalReferences(
857
{4: [2, 3], 3: [], 2: [1], 1: []},
858
{1: [2], 2: [4], 3: [4], 4: []},
860
{4: [2, 3], 3: [5], 2: [1], 1: [6]})
862
self.assertRemoveExternalReferences(
863
{1: [3], 2: [3, 4], 3: [], 4: []},
864
{1: [], 2: [], 3: [1, 2], 4: [2]},
866
{1: [3], 2: [3, 4], 3: [5], 4: []})
868
def assertPruneTails(self, pruned_map, tails, parent_map):
870
for key, parent_keys in parent_map.iteritems():
871
child_map.setdefault(key, [])
872
for pkey in parent_keys:
873
child_map.setdefault(pkey, []).append(key)
874
_PlanMerge._prune_tails(parent_map, child_map, tails)
875
self.assertEqual(pruned_map, parent_map)
877
def test__prune_tails(self):
878
# Nothing requested to prune
879
self.assertPruneTails({1: [], 2: [], 3: []}, [],
880
{1: [], 2: [], 3: []})
881
# Prune a single entry
882
self.assertPruneTails({1: [], 3: []}, [2],
883
{1: [], 2: [], 3: []})
885
self.assertPruneTails({1: []}, [3],
886
{1: [], 2: [3], 3: []})
887
# Prune a chain with a diamond
888
self.assertPruneTails({1: []}, [5],
889
{1: [], 2: [3, 4], 3: [5], 4: [5], 5: []})
890
# Prune a partial chain
891
self.assertPruneTails({1: [6], 6:[]}, [5],
892
{1: [2, 6], 2: [3, 4], 3: [5], 4: [5], 5: [],
894
# Prune a chain with multiple tips, that pulls out intermediates
895
self.assertPruneTails({1:[3], 3:[]}, [4, 5],
896
{1: [2, 3], 2: [4, 5], 3: [], 4:[], 5:[]})
897
self.assertPruneTails({1:[3], 3:[]}, [5, 4],
898
{1: [2, 3], 2: [4, 5], 3: [], 4:[], 5:[]})
900
def test_subtract_plans(self):
902
('unchanged', 'a\n'),
911
('unchanged', 'a\n'),
920
('unchanged', 'a\n'),
924
('unchanged', 'f\n'),
927
self.assertEqual(subtracted_plan,
928
list(_PlanMerge._subtract_plans(old_plan, new_plan)))
930
def setup_merge_with_base(self):
931
self.add_rev('root', 'COMMON', [], 'abc')
932
self.add_rev('root', 'THIS', ['COMMON'], 'abcd')
933
self.add_rev('root', 'BASE', ['COMMON'], 'eabc')
934
self.add_rev('root', 'OTHER', ['BASE'], 'eafb')
936
def test_plan_merge_with_base(self):
937
self.setup_merge_with_base()
938
plan = self.plan_merge_vf.plan_merge('THIS', 'OTHER', 'BASE')
939
self.assertEqual([('unchanged', 'a\n'),
941
('unchanged', 'b\n'),
946
def test_plan_lca_merge(self):
947
self.setup_plan_merge()
948
plan = self.plan_merge_vf.plan_lca_merge('B', 'C')
951
('unchanged', 'a\n'),
956
('unchanged', 'g\n')],
959
def test_plan_lca_merge_uncommitted_files(self):
960
self.setup_plan_merge_uncommitted()
961
plan = self.plan_merge_vf.plan_lca_merge('B:', 'C:')
964
('unchanged', 'a\n'),
969
('unchanged', 'g\n')],
972
def test_plan_lca_merge_with_base(self):
973
self.setup_merge_with_base()
974
plan = self.plan_merge_vf.plan_lca_merge('THIS', 'OTHER', 'BASE')
975
self.assertEqual([('unchanged', 'a\n'),
977
('unchanged', 'b\n'),
982
def test_plan_lca_merge_with_criss_cross(self):
983
self.add_version(('root', 'ROOT'), [], 'abc')
984
# each side makes a change
985
self.add_version(('root', 'REV1'), [('root', 'ROOT')], 'abcd')
986
self.add_version(('root', 'REV2'), [('root', 'ROOT')], 'abce')
987
# both sides merge, discarding others' changes
988
self.add_version(('root', 'LCA1'),
989
[('root', 'REV1'), ('root', 'REV2')], 'abcd')
990
self.add_version(('root', 'LCA2'),
991
[('root', 'REV1'), ('root', 'REV2')], 'fabce')
992
plan = self.plan_merge_vf.plan_lca_merge('LCA1', 'LCA2')
993
self.assertEqual([('new-b', 'f\n'),
994
('unchanged', 'a\n'),
995
('unchanged', 'b\n'),
996
('unchanged', 'c\n'),
997
('conflicted-a', 'd\n'),
998
('conflicted-b', 'e\n'),
1001
def test_plan_lca_merge_with_null(self):
1002
self.add_version(('root', 'A'), [], 'ab')
1003
self.add_version(('root', 'B'), [], 'bc')
1004
plan = self.plan_merge_vf.plan_lca_merge('A', 'B')
1005
self.assertEqual([('new-a', 'a\n'),
1006
('unchanged', 'b\n'),
1010
def test_plan_merge_with_delete_and_change(self):
1011
self.add_rev('root', 'C', [], 'a')
1012
self.add_rev('root', 'A', ['C'], 'b')
1013
self.add_rev('root', 'B', ['C'], '')
1014
plan = self.plan_merge_vf.plan_merge('A', 'B')
1015
self.assertEqual([('killed-both', 'a\n'),
1019
def test_plan_merge_with_move_and_change(self):
1020
self.add_rev('root', 'C', [], 'abcd')
1021
self.add_rev('root', 'A', ['C'], 'acbd')
1022
self.add_rev('root', 'B', ['C'], 'aBcd')
1023
plan = self.plan_merge_vf.plan_merge('A', 'B')
1024
self.assertEqual([('unchanged', 'a\n'),
1026
('killed-b', 'b\n'),
1028
('killed-a', 'c\n'),
1029
('unchanged', 'd\n'),
1033
class TestMergeImplementation(object):
1035
def do_merge(self, target_tree, source_tree, **kwargs):
1036
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1037
target_tree, source_tree.last_revision(),
1038
other_branch=source_tree.branch)
1039
merger.merge_type=self.merge_type
1040
for name, value in kwargs.items():
1041
setattr(merger, name, value)
1044
def test_merge_specific_file(self):
1045
this_tree = self.make_branch_and_tree('this')
1046
this_tree.lock_write()
1047
self.addCleanup(this_tree.unlock)
1048
self.build_tree_contents([
1049
('this/file1', 'a\nb\n'),
1050
('this/file2', 'a\nb\n')
1052
this_tree.add(['file1', 'file2'])
1053
this_tree.commit('Added files')
1054
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
1055
self.build_tree_contents([
1056
('other/file1', 'a\nb\nc\n'),
1057
('other/file2', 'a\nb\nc\n')
1059
other_tree.commit('modified both')
1060
self.build_tree_contents([
1061
('this/file1', 'd\na\nb\n'),
1062
('this/file2', 'd\na\nb\n')
1064
this_tree.commit('modified both')
1065
self.do_merge(this_tree, other_tree, interesting_files=['file1'])
1066
self.assertFileEqual('d\na\nb\nc\n', 'this/file1')
1067
self.assertFileEqual('d\na\nb\n', 'this/file2')
1069
def test_merge_move_and_change(self):
1070
this_tree = self.make_branch_and_tree('this')
1071
this_tree.lock_write()
1072
self.addCleanup(this_tree.unlock)
1073
self.build_tree_contents([
1074
('this/file1', 'line 1\nline 2\nline 3\nline 4\n'),
1076
this_tree.add('file1',)
1077
this_tree.commit('Added file')
1078
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
1079
self.build_tree_contents([
1080
('other/file1', 'line 1\nline 2 to 2.1\nline 3\nline 4\n'),
1082
other_tree.commit('Changed 2 to 2.1')
1083
self.build_tree_contents([
1084
('this/file1', 'line 1\nline 3\nline 2\nline 4\n'),
1086
this_tree.commit('Swapped 2 & 3')
1087
self.do_merge(this_tree, other_tree)
1088
self.assertFileEqual('line 1\n'
1095
'>>>>>>> MERGE-SOURCE\n'
1096
'line 4\n', 'this/file1')
1099
class TestMerge3Merge(TestCaseWithTransport, TestMergeImplementation):
1101
merge_type = _mod_merge.Merge3Merger
1104
class TestWeaveMerge(TestCaseWithTransport, TestMergeImplementation):
1106
merge_type = _mod_merge.WeaveMerger
1109
class TestLCAMerge(TestCaseWithTransport, TestMergeImplementation):
1111
merge_type = _mod_merge.LCAMerger
1113
def test_merge_move_and_change(self):
1114
self.expectFailure("lca merge doesn't conflict for move and change",
1115
super(TestLCAMerge, self).test_merge_move_and_change)
1118
class LoggingMerger(object):
1119
# These seem to be the required attributes
1120
requires_base = False
1121
supports_reprocess = False
1122
supports_show_base = False
1123
supports_cherrypick = False
1124
# We intentionally do not define supports_lca_trees
1126
def __init__(self, *args, **kwargs):
1128
self.kwargs = kwargs
1131
class TestMergerBase(TestCaseWithMemoryTransport):
1132
"""Common functionality for Merger tests that don't write to disk."""
1134
def get_builder(self):
1135
builder = self.make_branch_builder('path')
1136
builder.start_series()
1137
self.addCleanup(builder.finish_series)
1140
def setup_simple_graph(self):
1141
"""Create a simple 3-node graph.
1143
:return: A BranchBuilder
1150
builder = self.get_builder()
1151
builder.build_snapshot('A-id', None,
1152
[('add', ('', None, 'directory', None))])
1153
builder.build_snapshot('C-id', ['A-id'], [])
1154
builder.build_snapshot('B-id', ['A-id'], [])
1157
def setup_criss_cross_graph(self):
1158
"""Create a 5-node graph with a criss-cross.
1160
:return: A BranchBuilder
1167
builder = self.setup_simple_graph()
1168
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1169
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1172
def make_Merger(self, builder, other_revision_id,
1173
interesting_files=None, interesting_ids=None):
1174
"""Make a Merger object from a branch builder"""
1175
mem_tree = memorytree.MemoryTree.create_on_branch(builder.get_branch())
1176
mem_tree.lock_write()
1177
self.addCleanup(mem_tree.unlock)
1178
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1179
mem_tree, other_revision_id)
1180
merger.set_interesting_files(interesting_files)
1181
# It seems there is no matching function for set_interesting_ids
1182
merger.interesting_ids = interesting_ids
1183
merger.merge_type = _mod_merge.Merge3Merger
1187
class TestMergerInMemory(TestMergerBase):
1189
def test_find_base(self):
1190
merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1191
self.assertEqual('A-id', merger.base_rev_id)
1192
self.assertFalse(merger._is_criss_cross)
1193
self.assertIs(None, merger._lca_trees)
1195
def test_find_base_criss_cross(self):
1196
builder = self.setup_criss_cross_graph()
1197
merger = self.make_Merger(builder, 'E-id')
1198
self.assertEqual('A-id', merger.base_rev_id)
1199
self.assertTrue(merger._is_criss_cross)
1200
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1201
for t in merger._lca_trees])
1202
# If we swap the order, we should get a different lca order
1203
builder.build_snapshot('F-id', ['E-id'], [])
1204
merger = self.make_Merger(builder, 'D-id')
1205
self.assertEqual(['C-id', 'B-id'], [t.get_revision_id()
1206
for t in merger._lca_trees])
1208
def test_find_base_triple_criss_cross(self):
1211
# B C F # F is merged into both branches
1218
builder = self.setup_criss_cross_graph()
1219
builder.build_snapshot('F-id', ['A-id'], [])
1220
builder.build_snapshot('H-id', ['E-id', 'F-id'], [])
1221
builder.build_snapshot('G-id', ['D-id', 'F-id'], [])
1222
merger = self.make_Merger(builder, 'H-id')
1223
self.assertEqual(['B-id', 'C-id', 'F-id'],
1224
[t.get_revision_id() for t in merger._lca_trees])
1226
def test_no_criss_cross_passed_to_merge_type(self):
1227
class LCATreesMerger(LoggingMerger):
1228
supports_lca_trees = True
1230
merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1231
merger.merge_type = LCATreesMerger
1232
merge_obj = merger.make_merger()
1233
self.assertIsInstance(merge_obj, LCATreesMerger)
1234
self.assertFalse('lca_trees' in merge_obj.kwargs)
1236
def test_criss_cross_passed_to_merge_type(self):
1237
merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
1238
merger.merge_type = _mod_merge.Merge3Merger
1239
merge_obj = merger.make_merger()
1240
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1241
for t in merger._lca_trees])
1243
def test_criss_cross_not_supported_merge_type(self):
1244
merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
1245
# We explicitly do not define supports_lca_trees
1246
merger.merge_type = LoggingMerger
1247
merge_obj = merger.make_merger()
1248
self.assertIsInstance(merge_obj, LoggingMerger)
1249
self.assertFalse('lca_trees' in merge_obj.kwargs)
1251
def test_criss_cross_unsupported_merge_type(self):
1252
class UnsupportedLCATreesMerger(LoggingMerger):
1253
supports_lca_trees = False
1255
merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
1256
merger.merge_type = UnsupportedLCATreesMerger
1257
merge_obj = merger.make_merger()
1258
self.assertIsInstance(merge_obj, UnsupportedLCATreesMerger)
1259
self.assertFalse('lca_trees' in merge_obj.kwargs)
1262
class TestMergerEntriesLCA(TestMergerBase):
1264
def make_merge_obj(self, builder, other_revision_id,
1265
interesting_files=None, interesting_ids=None):
1266
merger = self.make_Merger(builder, other_revision_id,
1267
interesting_files=interesting_files,
1268
interesting_ids=interesting_ids)
1269
return merger.make_merger()
1271
def test_simple(self):
1272
builder = self.get_builder()
1273
builder.build_snapshot('A-id', None,
1274
[('add', (u'', 'a-root-id', 'directory', None)),
1275
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1276
builder.build_snapshot('C-id', ['A-id'],
1277
[('modify', ('a-id', 'a\nb\nC\nc\n'))])
1278
builder.build_snapshot('B-id', ['A-id'],
1279
[('modify', ('a-id', 'a\nB\nb\nc\n'))])
1280
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1281
[('modify', ('a-id', 'a\nB\nb\nC\nc\nE\n'))])
1282
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1283
[('modify', ('a-id', 'a\nB\nb\nC\nc\n'))])
1284
merge_obj = self.make_merge_obj(builder, 'E-id')
1286
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1287
for t in merge_obj._lca_trees])
1288
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1289
entries = list(merge_obj._entries_lca())
1291
# (file_id, changed, parents, names, executable)
1292
# BASE, lca1, lca2, OTHER, THIS
1293
root_id = 'a-root-id'
1294
self.assertEqual([('a-id', True,
1295
((root_id, [root_id, root_id]), root_id, root_id),
1296
((u'a', [u'a', u'a']), u'a', u'a'),
1297
((False, [False, False]), False, False)),
1300
def test_not_in_base(self):
1301
# LCAs all have the same last-modified revision for the file, as do
1302
# the tips, but the base has something different
1303
# A base, doesn't have the file
1305
# B C B introduces 'foo', C introduces 'bar'
1307
# D E D and E now both have 'foo' and 'bar'
1309
# F G the files are now in F, G, D and E, but not in A
1312
builder = self.get_builder()
1313
builder.build_snapshot('A-id', None,
1314
[('add', (u'', 'a-root-id', 'directory', None))])
1315
builder.build_snapshot('B-id', ['A-id'],
1316
[('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
1317
builder.build_snapshot('C-id', ['A-id'],
1318
[('add', (u'bar', 'bar-id', 'file', 'd\ne\nf\n'))])
1319
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1320
[('add', (u'bar', 'bar-id', 'file', 'd\ne\nf\n'))])
1321
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1322
[('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
1323
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1324
[('modify', (u'bar-id', 'd\ne\nf\nG\n'))])
1325
builder.build_snapshot('F-id', ['D-id', 'E-id'], [])
1326
merge_obj = self.make_merge_obj(builder, 'G-id')
1328
self.assertEqual(['D-id', 'E-id'], [t.get_revision_id()
1329
for t in merge_obj._lca_trees])
1330
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1331
entries = list(merge_obj._entries_lca())
1332
root_id = 'a-root-id'
1333
self.assertEqual([('bar-id', True,
1334
((None, [root_id, root_id]), root_id, root_id),
1335
((None, [u'bar', u'bar']), u'bar', u'bar'),
1336
((None, [False, False]), False, False)),
1339
def test_not_in_this(self):
1340
builder = self.get_builder()
1341
builder.build_snapshot('A-id', None,
1342
[('add', (u'', 'a-root-id', 'directory', None)),
1343
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1344
builder.build_snapshot('B-id', ['A-id'],
1345
[('modify', ('a-id', 'a\nB\nb\nc\n'))])
1346
builder.build_snapshot('C-id', ['A-id'],
1347
[('modify', ('a-id', 'a\nb\nC\nc\n'))])
1348
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1349
[('modify', ('a-id', 'a\nB\nb\nC\nc\nE\n'))])
1350
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1351
[('unversion', 'a-id')])
1352
merge_obj = self.make_merge_obj(builder, 'E-id')
1354
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1355
for t in merge_obj._lca_trees])
1356
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1358
entries = list(merge_obj._entries_lca())
1359
root_id = 'a-root-id'
1360
self.assertEqual([('a-id', True,
1361
((root_id, [root_id, root_id]), root_id, None),
1362
((u'a', [u'a', u'a']), u'a', None),
1363
((False, [False, False]), False, None)),
1366
def test_file_not_in_one_lca(self):
1369
# B C # B no file, C introduces a file
1371
# D E # D and E both have the file, unchanged from C
1372
builder = self.get_builder()
1373
builder.build_snapshot('A-id', None,
1374
[('add', (u'', 'a-root-id', 'directory', None))])
1375
builder.build_snapshot('B-id', ['A-id'], [])
1376
builder.build_snapshot('C-id', ['A-id'],
1377
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1378
builder.build_snapshot('E-id', ['C-id', 'B-id'], []) # Inherited from C
1379
builder.build_snapshot('D-id', ['B-id', 'C-id'], # Merged from C
1380
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1381
merge_obj = self.make_merge_obj(builder, 'E-id')
1383
self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1384
for t in merge_obj._lca_trees])
1385
self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1387
entries = list(merge_obj._entries_lca())
1388
self.assertEqual([], entries)
1390
def test_not_in_other(self):
1391
builder = self.get_builder()
1392
builder.build_snapshot('A-id', None,
1393
[('add', (u'', 'a-root-id', 'directory', None)),
1394
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1395
builder.build_snapshot('B-id', ['A-id'], [])
1396
builder.build_snapshot('C-id', ['A-id'], [])
1397
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1398
[('unversion', 'a-id')])
1399
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1400
merge_obj = self.make_merge_obj(builder, 'E-id')
1402
entries = list(merge_obj._entries_lca())
1403
root_id = 'a-root-id'
1404
self.assertEqual([('a-id', True,
1405
((root_id, [root_id, root_id]), None, root_id),
1406
((u'a', [u'a', u'a']), None, u'a'),
1407
((False, [False, False]), None, False)),
1410
def test_not_in_other_or_lca(self):
1411
# A base, introduces 'foo'
1413
# B C B nothing, C deletes foo
1415
# D E D restores foo (same as B), E leaves it deleted
1417
# A => B, no changes
1418
# A => C, delete foo (C should supersede B)
1419
# C => D, restore foo
1420
# C => E, no changes
1421
# D would then win 'cleanly' and no record would be given
1422
builder = self.get_builder()
1423
builder.build_snapshot('A-id', None,
1424
[('add', (u'', 'a-root-id', 'directory', None)),
1425
('add', (u'foo', 'foo-id', 'file', 'content\n'))])
1426
builder.build_snapshot('B-id', ['A-id'], [])
1427
builder.build_snapshot('C-id', ['A-id'],
1428
[('unversion', 'foo-id')])
1429
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1430
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1431
merge_obj = self.make_merge_obj(builder, 'E-id')
1433
entries = list(merge_obj._entries_lca())
1434
self.assertEqual([], entries)
1436
def test_not_in_other_mod_in_lca1_not_in_lca2(self):
1437
# A base, introduces 'foo'
1439
# B C B changes 'foo', C deletes foo
1441
# D E D restores foo (same as B), E leaves it deleted (as C)
1443
# A => B, modified foo
1444
# A => C, delete foo, C does not supersede B
1445
# B => D, no changes
1446
# C => D, resolve in favor of B
1447
# B => E, resolve in favor of E
1448
# C => E, no changes
1449
# In this case, we have a conflict of how the changes were resolved. E
1450
# picked C and D picked B, so we should issue a conflict
1451
builder = self.get_builder()
1452
builder.build_snapshot('A-id', None,
1453
[('add', (u'', 'a-root-id', 'directory', None)),
1454
('add', (u'foo', 'foo-id', 'file', 'content\n'))])
1455
builder.build_snapshot('B-id', ['A-id'], [
1456
('modify', ('foo-id', 'new-content\n'))])
1457
builder.build_snapshot('C-id', ['A-id'],
1458
[('unversion', 'foo-id')])
1459
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1460
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1461
merge_obj = self.make_merge_obj(builder, 'E-id')
1463
entries = list(merge_obj._entries_lca())
1464
root_id = 'a-root-id'
1465
self.assertEqual([('foo-id', True,
1466
((root_id, [root_id, None]), None, root_id),
1467
((u'foo', [u'foo', None]), None, 'foo'),
1468
((False, [False, None]), None, False)),
1471
def test_only_in_one_lca(self):
1474
# B C B nothing, C add file
1476
# D E D still has nothing, E removes file
1479
# C => D, removed the file
1481
# C => E, removed the file
1482
# Thus D & E have identical changes, and this is a no-op
1485
# A => C, add file, thus C supersedes B
1486
# w/ C=BASE, D=THIS, E=OTHER we have 'happy convergence'
1487
builder = self.get_builder()
1488
builder.build_snapshot('A-id', None,
1489
[('add', (u'', 'a-root-id', 'directory', None))])
1490
builder.build_snapshot('B-id', ['A-id'], [])
1491
builder.build_snapshot('C-id', ['A-id'],
1492
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1493
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1494
[('unversion', 'a-id')])
1495
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1496
merge_obj = self.make_merge_obj(builder, 'E-id')
1498
entries = list(merge_obj._entries_lca())
1499
self.assertEqual([], entries)
1501
def test_only_in_other(self):
1502
builder = self.get_builder()
1503
builder.build_snapshot('A-id', None,
1504
[('add', (u'', 'a-root-id', 'directory', None))])
1505
builder.build_snapshot('B-id', ['A-id'], [])
1506
builder.build_snapshot('C-id', ['A-id'], [])
1507
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1508
[('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1509
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1510
merge_obj = self.make_merge_obj(builder, 'E-id')
1512
entries = list(merge_obj._entries_lca())
1513
root_id = 'a-root-id'
1514
self.assertEqual([('a-id', True,
1515
((None, [None, None]), root_id, None),
1516
((None, [None, None]), u'a', None),
1517
((None, [None, None]), False, None)),
1520
def test_one_lca_supersedes(self):
1521
# One LCA supersedes the other LCAs last modified value, but the
1522
# value is not the same as BASE.
1523
# A base, introduces 'foo', last mod A
1525
# B C B modifies 'foo' (mod B), C does nothing (mod A)
1527
# D E D does nothing (mod B), E updates 'foo' (mod E)
1529
# F G F updates 'foo' (mod F). G does nothing (mod E)
1531
# At this point, G should not be considered to modify 'foo', even
1532
# though its LCAs disagree. This is because the modification in E
1533
# completely supersedes the value in D.
1534
builder = self.get_builder()
1535
builder.build_snapshot('A-id', None,
1536
[('add', (u'', 'a-root-id', 'directory', None)),
1537
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1538
builder.build_snapshot('C-id', ['A-id'], [])
1539
builder.build_snapshot('B-id', ['A-id'],
1540
[('modify', ('foo-id', 'B content\n'))])
1541
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1542
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1543
[('modify', ('foo-id', 'E content\n'))])
1544
builder.build_snapshot('G-id', ['E-id', 'D-id'], [])
1545
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1546
[('modify', ('foo-id', 'F content\n'))])
1547
merge_obj = self.make_merge_obj(builder, 'G-id')
1549
self.assertEqual([], list(merge_obj._entries_lca()))
1551
def test_one_lca_supersedes_path(self):
1552
# Double-criss-cross merge, the ultimate base value is different from
1556
# B C B value 'bar', C = 'foo'
1558
# D E D = 'bar', E supersedes to 'bing'
1560
# F G F = 'bing', G supersedes to 'barry'
1562
# In this case, we technically should not care about the value 'bar' for
1563
# D, because it was clearly superseded by E's 'bing'. The
1564
# per-file/attribute graph would actually look like:
1573
# Because the other side of the merge never modifies the value, it just
1574
# takes the value from the merge.
1576
# ATM this fails because we will prune 'foo' from the LCAs, but we
1577
# won't prune 'bar'. This is getting far off into edge-case land, so we
1578
# aren't supporting it yet.
1580
builder = self.get_builder()
1581
builder.build_snapshot('A-id', None,
1582
[('add', (u'', 'a-root-id', 'directory', None)),
1583
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1584
builder.build_snapshot('C-id', ['A-id'], [])
1585
builder.build_snapshot('B-id', ['A-id'],
1586
[('rename', ('foo', 'bar'))])
1587
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1588
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1589
[('rename', ('foo', 'bing'))]) # override to bing
1590
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1591
[('rename', ('bing', 'barry'))]) # override to barry
1592
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1593
[('rename', ('bar', 'bing'))]) # Merge in E's change
1594
merge_obj = self.make_merge_obj(builder, 'G-id')
1596
self.expectFailure("We don't do an actual heads() check on lca values,"
1597
" or use the per-attribute graph",
1598
self.assertEqual, [], list(merge_obj._entries_lca()))
1600
def test_one_lca_accidentally_pruned(self):
1601
# Another incorrect resolution from the same basic flaw:
1604
# B C B value 'bar', C = 'foo'
1606
# D E D = 'bar', E reverts to 'foo'
1608
# F G F = 'bing', G switches to 'bar'
1610
# 'bar' will not be seen as an interesting change, because 'foo' will
1611
# be pruned from the LCAs, even though it was newly introduced by E
1613
builder = self.get_builder()
1614
builder.build_snapshot('A-id', None,
1615
[('add', (u'', 'a-root-id', 'directory', None)),
1616
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1617
builder.build_snapshot('C-id', ['A-id'], [])
1618
builder.build_snapshot('B-id', ['A-id'],
1619
[('rename', ('foo', 'bar'))])
1620
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1621
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1622
builder.build_snapshot('G-id', ['E-id', 'D-id'],
1623
[('rename', ('foo', 'bar'))])
1624
builder.build_snapshot('F-id', ['D-id', 'E-id'],
1625
[('rename', ('bar', 'bing'))]) # should end up conflicting
1626
merge_obj = self.make_merge_obj(builder, 'G-id')
1628
entries = list(merge_obj._entries_lca())
1629
root_id = 'a-root-id'
1630
self.expectFailure("We prune values from BASE even when relevant.",
1633
((root_id, [root_id, root_id]), root_id, root_id),
1634
((u'foo', [u'bar', u'foo']), u'bar', u'bing'),
1635
((False, [False, False]), False, False)),
1638
def test_both_sides_revert(self):
1639
# Both sides of a criss-cross revert the text to the lca
1640
# A base, introduces 'foo'
1642
# B C B modifies 'foo', C modifies 'foo'
1644
# D E D reverts to B, E reverts to C
1645
# This should conflict
1646
builder = self.get_builder()
1647
builder.build_snapshot('A-id', None,
1648
[('add', (u'', 'a-root-id', 'directory', None)),
1649
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1650
builder.build_snapshot('B-id', ['A-id'],
1651
[('modify', ('foo-id', 'B content\n'))])
1652
builder.build_snapshot('C-id', ['A-id'],
1653
[('modify', ('foo-id', 'C content\n'))])
1654
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1655
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1656
merge_obj = self.make_merge_obj(builder, 'E-id')
1658
entries = list(merge_obj._entries_lca())
1659
root_id = 'a-root-id'
1660
self.assertEqual([('foo-id', True,
1661
((root_id, [root_id, root_id]), root_id, root_id),
1662
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
1663
((False, [False, False]), False, False)),
1666
def test_different_lca_resolve_one_side_updates_content(self):
1667
# Both sides converge, but then one side updates the text.
1668
# A base, introduces 'foo'
1670
# B C B modifies 'foo', C modifies 'foo'
1672
# D E D reverts to B, E reverts to C
1674
# F F updates to a new value
1675
# We need to emit an entry for 'foo', because D & E differed on the
1677
builder = self.get_builder()
1678
builder.build_snapshot('A-id', None,
1679
[('add', (u'', 'a-root-id', 'directory', None)),
1680
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1681
builder.build_snapshot('B-id', ['A-id'],
1682
[('modify', ('foo-id', 'B content\n'))])
1683
builder.build_snapshot('C-id', ['A-id'],
1684
[('modify', ('foo-id', 'C content\n'))])
1685
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1686
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1687
builder.build_snapshot('F-id', ['D-id'],
1688
[('modify', ('foo-id', 'F content\n'))])
1689
merge_obj = self.make_merge_obj(builder, 'E-id')
1691
entries = list(merge_obj._entries_lca())
1692
root_id = 'a-root-id'
1693
self.assertEqual([('foo-id', True,
1694
((root_id, [root_id, root_id]), root_id, root_id),
1695
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
1696
((False, [False, False]), False, False)),
1699
def test_same_lca_resolution_one_side_updates_content(self):
1700
# Both sides converge, but then one side updates the text.
1701
# A base, introduces 'foo'
1703
# B C B modifies 'foo', C modifies 'foo'
1705
# D E D and E use C's value
1707
# F F updates to a new value
1708
# I think it is a bug that this conflicts, but we don't have a way to
1709
# detect otherwise. And because of:
1710
# test_different_lca_resolve_one_side_updates_content
1711
# We need to conflict.
1713
builder = self.get_builder()
1714
builder.build_snapshot('A-id', None,
1715
[('add', (u'', 'a-root-id', 'directory', None)),
1716
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
1717
builder.build_snapshot('B-id', ['A-id'],
1718
[('modify', ('foo-id', 'B content\n'))])
1719
builder.build_snapshot('C-id', ['A-id'],
1720
[('modify', ('foo-id', 'C content\n'))])
1721
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1722
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1723
[('modify', ('foo-id', 'C content\n'))]) # Same as E
1724
builder.build_snapshot('F-id', ['D-id'],
1725
[('modify', ('foo-id', 'F content\n'))])
1726
merge_obj = self.make_merge_obj(builder, 'E-id')
1728
entries = list(merge_obj._entries_lca())
1729
self.expectFailure("We don't detect that LCA resolution was the"
1730
" same on both sides",
1731
self.assertEqual, [], entries)
1733
def test_only_path_changed(self):
1734
builder = self.get_builder()
1735
builder.build_snapshot('A-id', None,
1736
[('add', (u'', 'a-root-id', 'directory', None)),
1737
('add', (u'a', 'a-id', 'file', 'content\n'))])
1738
builder.build_snapshot('B-id', ['A-id'], [])
1739
builder.build_snapshot('C-id', ['A-id'], [])
1740
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1741
[('rename', (u'a', u'b'))])
1742
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1743
merge_obj = self.make_merge_obj(builder, 'E-id')
1744
entries = list(merge_obj._entries_lca())
1745
root_id = 'a-root-id'
1746
# The content was not changed, only the path
1747
self.assertEqual([('a-id', False,
1748
((root_id, [root_id, root_id]), root_id, root_id),
1749
((u'a', [u'a', u'a']), u'b', u'a'),
1750
((False, [False, False]), False, False)),
1753
def test_kind_changed(self):
1754
# Identical content, except 'D' changes a-id into a directory
1755
builder = self.get_builder()
1756
builder.build_snapshot('A-id', None,
1757
[('add', (u'', 'a-root-id', 'directory', None)),
1758
('add', (u'a', 'a-id', 'file', 'content\n'))])
1759
builder.build_snapshot('B-id', ['A-id'], [])
1760
builder.build_snapshot('C-id', ['A-id'], [])
1761
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1762
[('unversion', 'a-id'),
1763
('add', (u'a', 'a-id', 'directory', None))])
1764
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1765
merge_obj = self.make_merge_obj(builder, 'E-id')
1766
entries = list(merge_obj._entries_lca())
1767
root_id = 'a-root-id'
1768
# Only the kind was changed (content)
1769
self.assertEqual([('a-id', True,
1770
((root_id, [root_id, root_id]), root_id, root_id),
1771
((u'a', [u'a', u'a']), u'a', u'a'),
1772
((False, [False, False]), False, False)),
1775
def test_this_changed_kind(self):
1776
# Identical content, but THIS changes a file to a directory
1777
builder = self.get_builder()
1778
builder.build_snapshot('A-id', None,
1779
[('add', (u'', 'a-root-id', 'directory', None)),
1780
('add', (u'a', 'a-id', 'file', 'content\n'))])
1781
builder.build_snapshot('B-id', ['A-id'], [])
1782
builder.build_snapshot('C-id', ['A-id'], [])
1783
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1784
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1785
[('unversion', 'a-id'),
1786
('add', (u'a', 'a-id', 'directory', None))])
1787
merge_obj = self.make_merge_obj(builder, 'E-id')
1788
entries = list(merge_obj._entries_lca())
1789
# Only the kind was changed (content)
1790
self.assertEqual([], entries)
1792
def test_interesting_files(self):
1793
# Two files modified, but we should filter one of them
1794
builder = self.get_builder()
1795
builder.build_snapshot('A-id', None,
1796
[('add', (u'', 'a-root-id', 'directory', None)),
1797
('add', (u'a', 'a-id', 'file', 'content\n')),
1798
('add', (u'b', 'b-id', 'file', 'content\n'))])
1799
builder.build_snapshot('B-id', ['A-id'], [])
1800
builder.build_snapshot('C-id', ['A-id'], [])
1801
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1802
[('modify', ('a-id', 'new-content\n')),
1803
('modify', ('b-id', 'new-content\n'))])
1804
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1805
merge_obj = self.make_merge_obj(builder, 'E-id',
1806
interesting_files=['b'])
1807
entries = list(merge_obj._entries_lca())
1808
root_id = 'a-root-id'
1809
self.assertEqual([('b-id', True,
1810
((root_id, [root_id, root_id]), root_id, root_id),
1811
((u'b', [u'b', u'b']), u'b', u'b'),
1812
((False, [False, False]), False, False)),
1815
def test_interesting_file_in_this(self):
1816
# This renamed the file, but it should still match the entry in other
1817
builder = self.get_builder()
1818
builder.build_snapshot('A-id', None,
1819
[('add', (u'', 'a-root-id', 'directory', None)),
1820
('add', (u'a', 'a-id', 'file', 'content\n')),
1821
('add', (u'b', 'b-id', 'file', 'content\n'))])
1822
builder.build_snapshot('B-id', ['A-id'], [])
1823
builder.build_snapshot('C-id', ['A-id'], [])
1824
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1825
[('modify', ('a-id', 'new-content\n')),
1826
('modify', ('b-id', 'new-content\n'))])
1827
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1828
[('rename', ('b', 'c'))])
1829
merge_obj = self.make_merge_obj(builder, 'E-id',
1830
interesting_files=['c'])
1831
entries = list(merge_obj._entries_lca())
1832
root_id = 'a-root-id'
1833
self.assertEqual([('b-id', True,
1834
((root_id, [root_id, root_id]), root_id, root_id),
1835
((u'b', [u'b', u'b']), u'b', u'c'),
1836
((False, [False, False]), False, False)),
1839
def test_interesting_file_in_base(self):
1840
# This renamed the file, but it should still match the entry in BASE
1841
builder = self.get_builder()
1842
builder.build_snapshot('A-id', None,
1843
[('add', (u'', 'a-root-id', 'directory', None)),
1844
('add', (u'a', 'a-id', 'file', 'content\n')),
1845
('add', (u'c', 'c-id', 'file', 'content\n'))])
1846
builder.build_snapshot('B-id', ['A-id'],
1847
[('rename', ('c', 'b'))])
1848
builder.build_snapshot('C-id', ['A-id'],
1849
[('rename', ('c', 'b'))])
1850
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1851
[('modify', ('a-id', 'new-content\n')),
1852
('modify', ('c-id', 'new-content\n'))])
1853
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1854
merge_obj = self.make_merge_obj(builder, 'E-id',
1855
interesting_files=['c'])
1856
entries = list(merge_obj._entries_lca())
1857
root_id = 'a-root-id'
1858
self.assertEqual([('c-id', True,
1859
((root_id, [root_id, root_id]), root_id, root_id),
1860
((u'c', [u'b', u'b']), u'b', u'b'),
1861
((False, [False, False]), False, False)),
1864
def test_interesting_file_in_lca(self):
1865
# This renamed the file, but it should still match the entry in LCA
1866
builder = self.get_builder()
1867
builder.build_snapshot('A-id', None,
1868
[('add', (u'', 'a-root-id', 'directory', None)),
1869
('add', (u'a', 'a-id', 'file', 'content\n')),
1870
('add', (u'b', 'b-id', 'file', 'content\n'))])
1871
builder.build_snapshot('B-id', ['A-id'],
1872
[('rename', ('b', 'c'))])
1873
builder.build_snapshot('C-id', ['A-id'], [])
1874
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1875
[('modify', ('a-id', 'new-content\n')),
1876
('modify', ('b-id', 'new-content\n'))])
1877
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1878
[('rename', ('c', 'b'))])
1879
merge_obj = self.make_merge_obj(builder, 'E-id',
1880
interesting_files=['c'])
1881
entries = list(merge_obj._entries_lca())
1882
root_id = 'a-root-id'
1883
self.assertEqual([('b-id', True,
1884
((root_id, [root_id, root_id]), root_id, root_id),
1885
((u'b', [u'c', u'b']), u'b', u'b'),
1886
((False, [False, False]), False, False)),
1889
def test_interesting_ids(self):
1890
# Two files modified, but we should filter one of them
1891
builder = self.get_builder()
1892
builder.build_snapshot('A-id', None,
1893
[('add', (u'', 'a-root-id', 'directory', None)),
1894
('add', (u'a', 'a-id', 'file', 'content\n')),
1895
('add', (u'b', 'b-id', 'file', 'content\n'))])
1896
builder.build_snapshot('B-id', ['A-id'], [])
1897
builder.build_snapshot('C-id', ['A-id'], [])
1898
builder.build_snapshot('E-id', ['C-id', 'B-id'],
1899
[('modify', ('a-id', 'new-content\n')),
1900
('modify', ('b-id', 'new-content\n'))])
1901
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1902
merge_obj = self.make_merge_obj(builder, 'E-id',
1903
interesting_ids=['b-id'])
1904
entries = list(merge_obj._entries_lca())
1905
root_id = 'a-root-id'
1906
self.assertEqual([('b-id', True,
1907
((root_id, [root_id, root_id]), root_id, root_id),
1908
((u'b', [u'b', u'b']), u'b', u'b'),
1909
((False, [False, False]), False, False)),
1914
class TestMergerEntriesLCAOnDisk(tests.TestCaseWithTransport):
1916
def get_builder(self):
1917
builder = self.make_branch_builder('path')
1918
builder.start_series()
1919
self.addCleanup(builder.finish_series)
1922
def get_wt_from_builder(self, builder):
1923
"""Get a real WorkingTree from the builder."""
1924
the_branch = builder.get_branch()
1925
wt = the_branch.bzrdir.create_workingtree()
1926
# Note: This is a little bit ugly, but we are holding the branch
1927
# write-locked as part of the build process, and we would like to
1928
# maintain that. So we just force the WT to re-use the same
1930
wt._branch = the_branch
1932
self.addCleanup(wt.unlock)
1935
def do_merge(self, builder, other_revision_id):
1936
wt = self.get_wt_from_builder(builder)
1937
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1938
wt, other_revision_id)
1939
merger.merge_type = _mod_merge.Merge3Merger
1940
return wt, merger.do_merge()
1942
def test_simple_lca(self):
1943
builder = self.get_builder()
1944
builder.build_snapshot('A-id', None,
1945
[('add', (u'', 'a-root-id', 'directory', None)),
1946
('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))])
1947
builder.build_snapshot('C-id', ['A-id'], [])
1948
builder.build_snapshot('B-id', ['A-id'], [])
1949
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1950
builder.build_snapshot('D-id', ['B-id', 'C-id'],
1951
[('modify', ('a-id', 'a\nb\nc\nd\ne\nf\n'))])
1952
wt, conflicts = self.do_merge(builder, 'E-id')
1953
self.assertEqual(0, conflicts)
1954
# The merge should have simply update the contents of 'a'
1955
self.assertEqual('a\nb\nc\nd\ne\nf\n', wt.get_file_text('a-id'))
1957
def test_conflict_without_lca(self):
1958
# This test would cause a merge conflict, unless we use the lca trees
1959
# to determine the real ancestry
1962
# B C Path renamed to 'bar' in B
1966
# D E Path at 'bar' in D and E
1968
# F Path at 'baz' in F, which supersedes 'bar' and 'foo'
1969
builder = self.get_builder()
1970
builder.build_snapshot('A-id', None,
1971
[('add', (u'', 'a-root-id', 'directory', None)),
1972
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
1973
builder.build_snapshot('C-id', ['A-id'], [])
1974
builder.build_snapshot('B-id', ['A-id'],
1975
[('rename', ('foo', 'bar'))])
1976
builder.build_snapshot('E-id', ['C-id', 'B-id'], # merge the rename
1977
[('rename', ('foo', 'bar'))])
1978
builder.build_snapshot('F-id', ['E-id'],
1979
[('rename', ('bar', 'baz'))])
1980
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1981
wt, conflicts = self.do_merge(builder, 'F-id')
1982
self.assertEqual(0, conflicts)
1983
# The merge should simply recognize that the final rename takes
1985
self.assertEqual('baz', wt.id2path('foo-id'))
1987
def test_other_deletes_lca_renames(self):
1988
# This test would cause a merge conflict, unless we use the lca trees
1989
# to determine the real ancestry
1992
# B C Path renamed to 'bar' in B
1996
# D E Path at 'bar' in D and E
1999
builder = self.get_builder()
2000
builder.build_snapshot('A-id', None,
2001
[('add', (u'', 'a-root-id', 'directory', None)),
2002
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2003
builder.build_snapshot('C-id', ['A-id'], [])
2004
builder.build_snapshot('B-id', ['A-id'],
2005
[('rename', ('foo', 'bar'))])
2006
builder.build_snapshot('E-id', ['C-id', 'B-id'], # merge the rename
2007
[('rename', ('foo', 'bar'))])
2008
builder.build_snapshot('F-id', ['E-id'],
2009
[('unversion', 'foo-id')])
2010
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2011
wt, conflicts = self.do_merge(builder, 'F-id')
2012
self.assertEqual(0, conflicts)
2013
self.assertRaises(errors.NoSuchId, wt.id2path, 'foo-id')
2015
def test_executable_changes(self):
2024
# F Executable bit changed
2025
builder = self.get_builder()
2026
builder.build_snapshot('A-id', None,
2027
[('add', (u'', 'a-root-id', 'directory', None)),
2028
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2029
builder.build_snapshot('C-id', ['A-id'], [])
2030
builder.build_snapshot('B-id', ['A-id'], [])
2031
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2032
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2033
# Have to use a real WT, because BranchBuilder doesn't support exec bit
2034
wt = self.get_wt_from_builder(builder)
2035
tt = transform.TreeTransform(wt)
2037
tt.set_executability(True, tt.trans_id_tree_file_id('foo-id'))
2042
self.assertTrue(wt.is_executable('foo-id'))
2043
wt.commit('F-id', rev_id='F-id')
2044
# Reset to D, so that we can merge F
2045
wt.set_parent_ids(['D-id'])
2046
wt.branch.set_last_revision_info(3, 'D-id')
2048
self.assertFalse(wt.is_executable('foo-id'))
2049
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2050
self.assertEqual(0, conflicts)
2051
self.assertTrue(wt.is_executable('foo-id'))
2053
def test_create_symlink(self):
2054
self.requireFeature(tests.SymlinkFeature)
2063
# F Add a symlink 'foo' => 'bar'
2064
# Have to use a real WT, because BranchBuilder and MemoryTree don't
2065
# have symlink support
2066
builder = self.get_builder()
2067
builder.build_snapshot('A-id', None,
2068
[('add', (u'', 'a-root-id', 'directory', None))])
2069
builder.build_snapshot('C-id', ['A-id'], [])
2070
builder.build_snapshot('B-id', ['A-id'], [])
2071
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2072
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2073
# Have to use a real WT, because BranchBuilder doesn't support exec bit
2074
wt = self.get_wt_from_builder(builder)
2075
os.symlink('bar', 'path/foo')
2076
wt.add(['foo'], ['foo-id'])
2077
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2078
wt.commit('add symlink', rev_id='F-id')
2079
# Reset to D, so that we can merge F
2080
wt.set_parent_ids(['D-id'])
2081
wt.branch.set_last_revision_info(3, 'D-id')
2083
self.assertIs(None, wt.path2id('foo'))
2084
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2085
self.assertEqual(0, conflicts)
2086
self.assertEqual('foo-id', wt.path2id('foo'))
2087
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2089
def test_both_sides_revert(self):
2090
# Both sides of a criss-cross revert the text to the lca
2091
# A base, introduces 'foo'
2093
# B C B modifies 'foo', C modifies 'foo'
2095
# D E D reverts to B, E reverts to C
2096
# This should conflict
2097
# This must be done with a real WorkingTree, because normally their
2098
# inventory contains "None" rather than a real sha1
2099
builder = self.get_builder()
2100
builder.build_snapshot('A-id', None,
2101
[('add', (u'', 'a-root-id', 'directory', None)),
2102
('add', (u'foo', 'foo-id', 'file', 'A content\n'))])
2103
builder.build_snapshot('B-id', ['A-id'],
2104
[('modify', ('foo-id', 'B content\n'))])
2105
builder.build_snapshot('C-id', ['A-id'],
2106
[('modify', ('foo-id', 'C content\n'))])
2107
builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
2108
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2109
wt, conflicts = self.do_merge(builder, 'E-id')
2110
self.assertEqual(1, conflicts)
2111
self.assertEqualDiff('<<<<<<< TREE\n'
2115
'>>>>>>> MERGE-SOURCE\n',
2116
wt.get_file_text('foo-id'))
2118
def test_modified_symlink(self):
2119
self.requireFeature(tests.SymlinkFeature)
2120
# A Create symlink foo => bar
2122
# B C B relinks foo => baz
2126
# D E D & E have foo => baz
2128
# F F changes it to bing
2130
# Merging D & F should result in F cleanly overriding D, because D's
2131
# value actually comes from B
2133
# Have to use a real WT, because BranchBuilder and MemoryTree don't
2134
# have symlink support
2135
wt = self.make_branch_and_tree('path')
2137
self.addCleanup(wt.unlock)
2138
os.symlink('bar', 'path/foo')
2139
wt.add(['foo'], ['foo-id'])
2140
wt.commit('add symlink', rev_id='A-id')
2141
os.remove('path/foo')
2142
os.symlink('baz', 'path/foo')
2143
wt.commit('foo => baz', rev_id='B-id')
2144
wt.set_last_revision('A-id')
2145
wt.branch.set_last_revision_info(1, 'A-id')
2147
wt.commit('C', rev_id='C-id')
2148
wt.merge_from_branch(wt.branch, 'B-id')
2149
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2150
wt.commit('E merges C & B', rev_id='E-id')
2151
os.remove('path/foo')
2152
os.symlink('bing', 'path/foo')
2153
wt.commit('F foo => bing', rev_id='F-id')
2154
wt.set_last_revision('B-id')
2155
wt.branch.set_last_revision_info(2, 'B-id')
2157
wt.merge_from_branch(wt.branch, 'C-id')
2158
wt.commit('D merges B & C', rev_id='D-id')
2159
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2160
self.assertEqual(0, conflicts)
2161
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2163
def test_renamed_symlink(self):
2164
self.requireFeature(tests.SymlinkFeature)
2165
# A Create symlink foo => bar
2167
# B C B renames foo => barry
2171
# D E D & E have barry
2173
# F F renames barry to blah
2175
# Merging D & F should result in F cleanly overriding D, because D's
2176
# value actually comes from B
2178
wt = self.make_branch_and_tree('path')
2180
self.addCleanup(wt.unlock)
2181
os.symlink('bar', 'path/foo')
2182
wt.add(['foo'], ['foo-id'])
2183
wt.commit('A add symlink', rev_id='A-id')
2184
wt.rename_one('foo', 'barry')
2185
wt.commit('B foo => barry', rev_id='B-id')
2186
wt.set_last_revision('A-id')
2187
wt.branch.set_last_revision_info(1, 'A-id')
2189
wt.commit('C', rev_id='C-id')
2190
wt.merge_from_branch(wt.branch, 'B-id')
2191
self.assertEqual('barry', wt.id2path('foo-id'))
2192
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2193
wt.commit('E merges C & B', rev_id='E-id')
2194
wt.rename_one('barry', 'blah')
2195
wt.commit('F barry => blah', rev_id='F-id')
2196
wt.set_last_revision('B-id')
2197
wt.branch.set_last_revision_info(2, 'B-id')
2199
wt.merge_from_branch(wt.branch, 'C-id')
2200
wt.commit('D merges B & C', rev_id='D-id')
2201
self.assertEqual('barry', wt.id2path('foo-id'))
2202
# Check the output of the Merger object directly
2203
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2205
merger.merge_type = _mod_merge.Merge3Merger
2206
merge_obj = merger.make_merger()
2207
root_id = wt.path2id('')
2208
entries = list(merge_obj._entries_lca())
2209
# No content change, just a path change
2210
self.assertEqual([('foo-id', False,
2211
((root_id, [root_id, root_id]), root_id, root_id),
2212
((u'foo', [u'barry', u'foo']), u'blah', u'barry'),
2213
((False, [False, False]), False, False)),
2215
conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2216
self.assertEqual(0, conflicts)
2217
self.assertEqual('blah', wt.id2path('foo-id'))
2219
def test_symlink_no_content_change(self):
2220
self.requireFeature(tests.SymlinkFeature)
2221
# A Create symlink foo => bar
2223
# B C B relinks foo => baz
2227
# D E D & E have foo => baz
2229
# F F has foo => bing
2231
# Merging E into F should not cause a conflict, because E doesn't have
2232
# a content change relative to the LCAs (it does relative to A)
2233
wt = self.make_branch_and_tree('path')
2235
self.addCleanup(wt.unlock)
2236
os.symlink('bar', 'path/foo')
2237
wt.add(['foo'], ['foo-id'])
2238
wt.commit('add symlink', rev_id='A-id')
2239
os.remove('path/foo')
2240
os.symlink('baz', 'path/foo')
2241
wt.commit('foo => baz', rev_id='B-id')
2242
wt.set_last_revision('A-id')
2243
wt.branch.set_last_revision_info(1, 'A-id')
2245
wt.commit('C', rev_id='C-id')
2246
wt.merge_from_branch(wt.branch, 'B-id')
2247
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2248
wt.commit('E merges C & B', rev_id='E-id')
2249
wt.set_last_revision('B-id')
2250
wt.branch.set_last_revision_info(2, 'B-id')
2252
wt.merge_from_branch(wt.branch, 'C-id')
2253
wt.commit('D merges B & C', rev_id='D-id')
2254
os.remove('path/foo')
2255
os.symlink('bing', 'path/foo')
2256
wt.commit('F foo => bing', rev_id='F-id')
2258
# Check the output of the Merger object directly
2259
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2261
merger.merge_type = _mod_merge.Merge3Merger
2262
merge_obj = merger.make_merger()
2263
# Nothing interesting happened in OTHER relative to BASE
2264
self.assertEqual([], list(merge_obj._entries_lca()))
2265
# Now do a real merge, just to test the rest of the stack
2266
conflicts = wt.merge_from_branch(wt.branch, to_revision='E-id')
2267
self.assertEqual(0, conflicts)
2268
self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2270
def test_symlink_this_changed_kind(self):
2271
self.requireFeature(tests.SymlinkFeature)
2274
# B C B creates symlink foo => bar
2278
# D E D changes foo into a file, E has foo => bing
2280
# Mostly, this is trying to test that we don't try to os.readlink() on
2281
# a file, or when there is nothing there
2282
wt = self.make_branch_and_tree('path')
2284
self.addCleanup(wt.unlock)
2285
wt.commit('base', rev_id='A-id')
2286
os.symlink('bar', 'path/foo')
2287
wt.add(['foo'], ['foo-id'])
2288
wt.commit('add symlink foo => bar', rev_id='B-id')
2289
wt.set_last_revision('A-id')
2290
wt.branch.set_last_revision_info(1, 'A-id')
2292
wt.commit('C', rev_id='C-id')
2293
wt.merge_from_branch(wt.branch, 'B-id')
2294
self.assertEqual('bar', wt.get_symlink_target('foo-id'))
2295
os.remove('path/foo')
2296
# We have to change the link in E, or it won't try to do a comparison
2297
os.symlink('bing', 'path/foo')
2298
wt.commit('E merges C & B, overrides to bing', rev_id='E-id')
2299
wt.set_last_revision('B-id')
2300
wt.branch.set_last_revision_info(2, 'B-id')
2302
wt.merge_from_branch(wt.branch, 'C-id')
2303
os.remove('path/foo')
2304
self.build_tree_contents([('path/foo', 'file content\n')])
2305
# XXX: workaround, WT doesn't detect kind changes unless you do
2307
list(wt.iter_changes(wt.basis_tree()))
2308
wt.commit('D merges B & C, makes it a file', rev_id='D-id')
2310
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2312
merger.merge_type = _mod_merge.Merge3Merger
2313
merge_obj = merger.make_merger()
2314
entries = list(merge_obj._entries_lca())
2315
root_id = wt.path2id('')
2316
self.assertEqual([('foo-id', True,
2317
((None, [root_id, None]), root_id, root_id),
2318
((None, [u'foo', None]), u'foo', u'foo'),
2319
((None, [False, None]), False, False)),
2322
def test_symlink_all_wt(self):
2323
"""Check behavior if all trees are Working Trees."""
2324
self.requireFeature(tests.SymlinkFeature)
2325
# The big issue is that entry.symlink_target is None for WorkingTrees.
2326
# So we need to make sure we handle that case correctly.
2329
# B C B relinks foo => baz
2331
# D E D & E have foo => baz
2333
# F F changes it to bing
2334
# Merging D & F should result in F cleanly overriding D, because D's
2335
# value actually comes from B
2337
wt = self.make_branch_and_tree('path')
2339
self.addCleanup(wt.unlock)
2340
os.symlink('bar', 'path/foo')
2341
wt.add(['foo'], ['foo-id'])
2342
wt.commit('add symlink', rev_id='A-id')
2343
os.remove('path/foo')
2344
os.symlink('baz', 'path/foo')
2345
wt.commit('foo => baz', rev_id='B-id')
2346
wt.set_last_revision('A-id')
2347
wt.branch.set_last_revision_info(1, 'A-id')
2349
wt.commit('C', rev_id='C-id')
2350
wt.merge_from_branch(wt.branch, 'B-id')
2351
self.assertEqual('baz', wt.get_symlink_target('foo-id'))
2352
wt.commit('E merges C & B', rev_id='E-id')
2353
os.remove('path/foo')
2354
os.symlink('bing', 'path/foo')
2355
wt.commit('F foo => bing', rev_id='F-id')
2356
wt.set_last_revision('B-id')
2357
wt.branch.set_last_revision_info(2, 'B-id')
2359
wt.merge_from_branch(wt.branch, 'C-id')
2360
wt.commit('D merges B & C', rev_id='D-id')
2361
wt_base = wt.bzrdir.sprout('base', 'A-id').open_workingtree()
2363
self.addCleanup(wt_base.unlock)
2364
wt_lca1 = wt.bzrdir.sprout('b-tree', 'B-id').open_workingtree()
2366
self.addCleanup(wt_lca1.unlock)
2367
wt_lca2 = wt.bzrdir.sprout('c-tree', 'C-id').open_workingtree()
2369
self.addCleanup(wt_lca2.unlock)
2370
wt_other = wt.bzrdir.sprout('other', 'F-id').open_workingtree()
2371
wt_other.lock_read()
2372
self.addCleanup(wt_other.unlock)
2373
merge_obj = _mod_merge.Merge3Merger(wt, wt, wt_base,
2374
wt_other, lca_trees=[wt_lca1, wt_lca2], do_merge=False)
2375
entries = list(merge_obj._entries_lca())
2376
root_id = wt.path2id('')
2377
self.assertEqual([('foo-id', True,
2378
((root_id, [root_id, root_id]), root_id, root_id),
2379
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
2380
((False, [False, False]), False, False)),
2383
def test_other_reverted_path_to_base(self):
2386
# B C Path at 'bar' in B
2393
builder = self.get_builder()
2394
builder.build_snapshot('A-id', None,
2395
[('add', (u'', 'a-root-id', 'directory', None)),
2396
('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))])
2397
builder.build_snapshot('C-id', ['A-id'], [])
2398
builder.build_snapshot('B-id', ['A-id'],
2399
[('rename', ('foo', 'bar'))])
2400
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2401
[('rename', ('foo', 'bar'))]) # merge the rename
2402
builder.build_snapshot('F-id', ['E-id'],
2403
[('rename', ('bar', 'foo'))]) # Rename back to BASE
2404
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2405
wt, conflicts = self.do_merge(builder, 'F-id')
2406
self.assertEqual(0, conflicts)
2407
self.assertEqual('foo', wt.id2path('foo-id'))
2409
def test_other_reverted_content_to_base(self):
2410
builder = self.get_builder()
2411
builder.build_snapshot('A-id', None,
2412
[('add', (u'', 'a-root-id', 'directory', None)),
2413
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2414
builder.build_snapshot('C-id', ['A-id'], [])
2415
builder.build_snapshot('B-id', ['A-id'],
2416
[('modify', ('foo-id', 'B content\n'))])
2417
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2418
[('modify', ('foo-id', 'B content\n'))]) # merge the content
2419
builder.build_snapshot('F-id', ['E-id'],
2420
[('modify', ('foo-id', 'base content\n'))]) # Revert back to BASE
2421
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2422
wt, conflicts = self.do_merge(builder, 'F-id')
2423
self.assertEqual(0, conflicts)
2424
# TODO: We need to use the per-file graph to properly select a BASE
2425
# before this will work. Or at least use the LCA trees to find
2426
# the appropriate content base. (which is B, not A).
2427
self.assertEqual('base content\n', wt.get_file_text('foo-id'))
2429
def test_other_modified_content(self):
2430
builder = self.get_builder()
2431
builder.build_snapshot('A-id', None,
2432
[('add', (u'', 'a-root-id', 'directory', None)),
2433
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2434
builder.build_snapshot('C-id', ['A-id'], [])
2435
builder.build_snapshot('B-id', ['A-id'],
2436
[('modify', ('foo-id', 'B content\n'))])
2437
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2438
[('modify', ('foo-id', 'B content\n'))]) # merge the content
2439
builder.build_snapshot('F-id', ['E-id'],
2440
[('modify', ('foo-id', 'F content\n'))]) # Override B content
2441
builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
2442
wt, conflicts = self.do_merge(builder, 'F-id')
2443
self.assertEqual(0, conflicts)
2444
self.assertEqual('F content\n', wt.get_file_text('foo-id'))
2446
def test_all_wt(self):
2447
"""Check behavior if all trees are Working Trees."""
2448
# The big issue is that entry.revision is None for WorkingTrees. (as is
2449
# entry.text_sha1, etc. So we need to make sure we handle that case
2451
# A Content of 'foo', path of 'a'
2453
# B C B modifies content, C renames 'a' => 'b'
2455
# D E E updates content, renames 'b' => 'c'
2456
builder = self.get_builder()
2457
builder.build_snapshot('A-id', None,
2458
[('add', (u'', 'a-root-id', 'directory', None)),
2459
('add', (u'a', 'a-id', 'file', 'base content\n')),
2460
('add', (u'foo', 'foo-id', 'file', 'base content\n'))])
2461
builder.build_snapshot('B-id', ['A-id'],
2462
[('modify', ('foo-id', 'B content\n'))])
2463
builder.build_snapshot('C-id', ['A-id'],
2464
[('rename', ('a', 'b'))])
2465
builder.build_snapshot('E-id', ['C-id', 'B-id'],
2466
[('rename', ('b', 'c')),
2467
('modify', ('foo-id', 'E content\n'))])
2468
builder.build_snapshot('D-id', ['B-id', 'C-id'],
2469
[('rename', ('a', 'b'))]) # merged change
2470
wt_this = self.get_wt_from_builder(builder)
2471
wt_base = wt_this.bzrdir.sprout('base', 'A-id').open_workingtree()
2473
self.addCleanup(wt_base.unlock)
2474
wt_lca1 = wt_this.bzrdir.sprout('b-tree', 'B-id').open_workingtree()
2476
self.addCleanup(wt_lca1.unlock)
2477
wt_lca2 = wt_this.bzrdir.sprout('c-tree', 'C-id').open_workingtree()
2479
self.addCleanup(wt_lca2.unlock)
2480
wt_other = wt_this.bzrdir.sprout('other', 'E-id').open_workingtree()
2481
wt_other.lock_read()
2482
self.addCleanup(wt_other.unlock)
2483
merge_obj = _mod_merge.Merge3Merger(wt_this, wt_this, wt_base,
2484
wt_other, lca_trees=[wt_lca1, wt_lca2], do_merge=False)
2485
entries = list(merge_obj._entries_lca())
2486
root_id = 'a-root-id'
2487
self.assertEqual([('a-id', False,
2488
((root_id, [root_id, root_id]), root_id, root_id),
2489
((u'a', [u'a', u'b']), u'c', u'b'),
2490
((False, [False, False]), False, False)),
2492
((root_id, [root_id, root_id]), root_id, root_id),
2493
((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
2494
((False, [False, False]), False, False)),
2497
def test_nested_tree_unmodified(self):
2498
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2500
wt = self.make_branch_and_tree('tree',
2501
format='dirstate-with-subtree')
2503
self.addCleanup(wt.unlock)
2504
sub_tree = self.make_branch_and_tree('tree/sub-tree',
2505
format='dirstate-with-subtree')
2506
wt.set_root_id('a-root-id')
2507
sub_tree.set_root_id('sub-tree-root')
2508
self.build_tree_contents([('tree/sub-tree/file', 'text1')])
2509
sub_tree.add('file')
2510
sub_tree.commit('foo', rev_id='sub-A-id')
2511
wt.add_reference(sub_tree)
2512
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2513
# Now create a criss-cross merge in the parent, without modifying the
2515
wt.commit('B', rev_id='B-id', recursive=None)
2516
wt.set_last_revision('A-id')
2517
wt.branch.set_last_revision_info(1, 'A-id')
2518
wt.commit('C', rev_id='C-id', recursive=None)
2519
wt.merge_from_branch(wt.branch, to_revision='B-id')
2520
wt.commit('E', rev_id='E-id', recursive=None)
2521
wt.set_parent_ids(['B-id', 'C-id'])
2522
wt.branch.set_last_revision_info(2, 'B-id')
2523
wt.commit('D', rev_id='D-id', recursive=None)
2525
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2527
merger.merge_type = _mod_merge.Merge3Merger
2528
merge_obj = merger.make_merger()
2529
entries = list(merge_obj._entries_lca())
2530
self.assertEqual([], entries)
2532
def test_nested_tree_subtree_modified(self):
2533
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2535
wt = self.make_branch_and_tree('tree',
2536
format='dirstate-with-subtree')
2538
self.addCleanup(wt.unlock)
2539
sub_tree = self.make_branch_and_tree('tree/sub',
2540
format='dirstate-with-subtree')
2541
wt.set_root_id('a-root-id')
2542
sub_tree.set_root_id('sub-tree-root')
2543
self.build_tree_contents([('tree/sub/file', 'text1')])
2544
sub_tree.add('file')
2545
sub_tree.commit('foo', rev_id='sub-A-id')
2546
wt.add_reference(sub_tree)
2547
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2548
# Now create a criss-cross merge in the parent, without modifying the
2550
wt.commit('B', rev_id='B-id', recursive=None)
2551
wt.set_last_revision('A-id')
2552
wt.branch.set_last_revision_info(1, 'A-id')
2553
wt.commit('C', rev_id='C-id', recursive=None)
2554
wt.merge_from_branch(wt.branch, to_revision='B-id')
2555
self.build_tree_contents([('tree/sub/file', 'text2')])
2556
sub_tree.commit('modify contents', rev_id='sub-B-id')
2557
wt.commit('E', rev_id='E-id', recursive=None)
2558
wt.set_parent_ids(['B-id', 'C-id'])
2559
wt.branch.set_last_revision_info(2, 'B-id')
2560
wt.commit('D', rev_id='D-id', recursive=None)
2562
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2564
merger.merge_type = _mod_merge.Merge3Merger
2565
merge_obj = merger.make_merger()
2566
entries = list(merge_obj._entries_lca())
2567
# Nothing interesting about this sub-tree, because content changes are
2568
# computed at a higher level
2569
self.assertEqual([], entries)
2571
def test_nested_tree_subtree_renamed(self):
2572
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2574
wt = self.make_branch_and_tree('tree',
2575
format='dirstate-with-subtree')
2577
self.addCleanup(wt.unlock)
2578
sub_tree = self.make_branch_and_tree('tree/sub',
2579
format='dirstate-with-subtree')
2580
wt.set_root_id('a-root-id')
2581
sub_tree.set_root_id('sub-tree-root')
2582
self.build_tree_contents([('tree/sub/file', 'text1')])
2583
sub_tree.add('file')
2584
sub_tree.commit('foo', rev_id='sub-A-id')
2585
wt.add_reference(sub_tree)
2586
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2587
# Now create a criss-cross merge in the parent, without modifying the
2589
wt.commit('B', rev_id='B-id', recursive=None)
2590
wt.set_last_revision('A-id')
2591
wt.branch.set_last_revision_info(1, 'A-id')
2592
wt.commit('C', rev_id='C-id', recursive=None)
2593
wt.merge_from_branch(wt.branch, to_revision='B-id')
2594
wt.rename_one('sub', 'alt_sub')
2595
wt.commit('E', rev_id='E-id', recursive=None)
2596
wt.set_last_revision('B-id')
2598
wt.set_parent_ids(['B-id', 'C-id'])
2599
wt.branch.set_last_revision_info(2, 'B-id')
2600
wt.commit('D', rev_id='D-id', recursive=None)
2602
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2604
merger.merge_type = _mod_merge.Merge3Merger
2605
merge_obj = merger.make_merger()
2606
entries = list(merge_obj._entries_lca())
2607
root_id = 'a-root-id'
2608
self.assertEqual([('sub-tree-root', False,
2609
((root_id, [root_id, root_id]), root_id, root_id),
2610
((u'sub', [u'sub', u'sub']), u'alt_sub', u'sub'),
2611
((False, [False, False]), False, False)),
2614
def test_nested_tree_subtree_renamed_and_modified(self):
2615
# Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2617
wt = self.make_branch_and_tree('tree',
2618
format='dirstate-with-subtree')
2620
self.addCleanup(wt.unlock)
2621
sub_tree = self.make_branch_and_tree('tree/sub',
2622
format='dirstate-with-subtree')
2623
wt.set_root_id('a-root-id')
2624
sub_tree.set_root_id('sub-tree-root')
2625
self.build_tree_contents([('tree/sub/file', 'text1')])
2626
sub_tree.add('file')
2627
sub_tree.commit('foo', rev_id='sub-A-id')
2628
wt.add_reference(sub_tree)
2629
wt.commit('set text to 1', rev_id='A-id', recursive=None)
2630
# Now create a criss-cross merge in the parent, without modifying the
2632
wt.commit('B', rev_id='B-id', recursive=None)
2633
wt.set_last_revision('A-id')
2634
wt.branch.set_last_revision_info(1, 'A-id')
2635
wt.commit('C', rev_id='C-id', recursive=None)
2636
wt.merge_from_branch(wt.branch, to_revision='B-id')
2637
self.build_tree_contents([('tree/sub/file', 'text2')])
2638
sub_tree.commit('modify contents', rev_id='sub-B-id')
2639
wt.rename_one('sub', 'alt_sub')
2640
wt.commit('E', rev_id='E-id', recursive=None)
2641
wt.set_last_revision('B-id')
2643
wt.set_parent_ids(['B-id', 'C-id'])
2644
wt.branch.set_last_revision_info(2, 'B-id')
2645
wt.commit('D', rev_id='D-id', recursive=None)
2647
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2649
merger.merge_type = _mod_merge.Merge3Merger
2650
merge_obj = merger.make_merger()
2651
entries = list(merge_obj._entries_lca())
2652
root_id = 'a-root-id'
2653
self.assertEqual([('sub-tree-root', False,
2654
((root_id, [root_id, root_id]), root_id, root_id),
2655
((u'sub', [u'sub', u'sub']), u'alt_sub', u'sub'),
2656
((False, [False, False]), False, False)),
2660
class TestLCAMultiWay(tests.TestCase):
2662
def assertLCAMultiWay(self, expected, base, lcas, other, this,
2663
allow_overriding_lca=True):
2664
self.assertEqual(expected, _mod_merge.Merge3Merger._lca_multi_way(
2665
(base, lcas), other, this,
2666
allow_overriding_lca=allow_overriding_lca))
2668
def test_other_equal_equal_lcas(self):
2669
"""Test when OTHER=LCA and all LCAs are identical."""
2670
self.assertLCAMultiWay('this',
2671
'bval', ['bval', 'bval'], 'bval', 'bval')
2672
self.assertLCAMultiWay('this',
2673
'bval', ['lcaval', 'lcaval'], 'lcaval', 'bval')
2674
self.assertLCAMultiWay('this',
2675
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', 'bval')
2676
self.assertLCAMultiWay('this',
2677
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', 'tval')
2678
self.assertLCAMultiWay('this',
2679
'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', None)
2681
def test_other_equal_this(self):
2682
"""Test when other and this are identical."""
2683
self.assertLCAMultiWay('this',
2684
'bval', ['bval', 'bval'], 'oval', 'oval')
2685
self.assertLCAMultiWay('this',
2686
'bval', ['lcaval', 'lcaval'], 'oval', 'oval')
2687
self.assertLCAMultiWay('this',
2688
'bval', ['cval', 'dval'], 'oval', 'oval')
2689
self.assertLCAMultiWay('this',
2690
'bval', [None, 'lcaval'], 'oval', 'oval')
2691
self.assertLCAMultiWay('this',
2692
None, [None, 'lcaval'], 'oval', 'oval')
2693
self.assertLCAMultiWay('this',
2694
None, ['lcaval', 'lcaval'], 'oval', 'oval')
2695
self.assertLCAMultiWay('this',
2696
None, ['cval', 'dval'], 'oval', 'oval')
2697
self.assertLCAMultiWay('this',
2698
None, ['cval', 'dval'], None, None)
2699
self.assertLCAMultiWay('this',
2700
None, ['cval', 'dval', 'eval', 'fval'], 'oval', 'oval')
2702
def test_no_lcas(self):
2703
self.assertLCAMultiWay('this',
2704
'bval', [], 'bval', 'tval')
2705
self.assertLCAMultiWay('other',
2706
'bval', [], 'oval', 'bval')
2707
self.assertLCAMultiWay('conflict',
2708
'bval', [], 'oval', 'tval')
2709
self.assertLCAMultiWay('this',
2710
'bval', [], 'oval', 'oval')
2712
def test_lca_supersedes_other_lca(self):
2713
"""If one lca == base, the other lca takes precedence"""
2714
self.assertLCAMultiWay('this',
2715
'bval', ['bval', 'lcaval'], 'lcaval', 'tval')
2716
self.assertLCAMultiWay('this',
2717
'bval', ['bval', 'lcaval'], 'lcaval', 'bval')
2718
# This is actually considered a 'revert' because the 'lcaval' in LCAS
2719
# supersedes the BASE val (in the other LCA) but then OTHER reverts it
2721
self.assertLCAMultiWay('other',
2722
'bval', ['bval', 'lcaval'], 'bval', 'lcaval')
2723
self.assertLCAMultiWay('conflict',
2724
'bval', ['bval', 'lcaval'], 'bval', 'tval')
2726
def test_other_and_this_pick_different_lca(self):
2727
# OTHER and THIS resolve the lca conflict in different ways
2728
self.assertLCAMultiWay('conflict',
2729
'bval', ['lca1val', 'lca2val'], 'lca1val', 'lca2val')
2730
self.assertLCAMultiWay('conflict',
2731
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'lca2val')
2732
self.assertLCAMultiWay('conflict',
2733
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'lca2val')
2735
def test_other_in_lca(self):
2736
# OTHER takes a value of one of the LCAs, THIS takes a new value, which
2737
# theoretically supersedes both LCA values and 'wins'
2738
self.assertLCAMultiWay('this',
2739
'bval', ['lca1val', 'lca2val'], 'lca1val', 'newval')
2740
self.assertLCAMultiWay('this',
2741
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'newval')
2742
self.assertLCAMultiWay('conflict',
2743
'bval', ['lca1val', 'lca2val'], 'lca1val', 'newval',
2744
allow_overriding_lca=False)
2745
self.assertLCAMultiWay('conflict',
2746
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'newval',
2747
allow_overriding_lca=False)
2748
# THIS reverted back to BASE, but that is an explicit supersede of all
2750
self.assertLCAMultiWay('this',
2751
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'bval')
2752
self.assertLCAMultiWay('this',
2753
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'bval')
2754
self.assertLCAMultiWay('conflict',
2755
'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'bval',
2756
allow_overriding_lca=False)
2757
self.assertLCAMultiWay('conflict',
2758
'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'bval',
2759
allow_overriding_lca=False)
2761
def test_this_in_lca(self):
2762
# THIS takes a value of one of the LCAs, OTHER takes a new value, which
2763
# theoretically supersedes both LCA values and 'wins'
2764
self.assertLCAMultiWay('other',
2765
'bval', ['lca1val', 'lca2val'], 'oval', 'lca1val')
2766
self.assertLCAMultiWay('other',
2767
'bval', ['lca1val', 'lca2val'], 'oval', 'lca2val')
2768
self.assertLCAMultiWay('conflict',
2769
'bval', ['lca1val', 'lca2val'], 'oval', 'lca1val',
2770
allow_overriding_lca=False)
2771
self.assertLCAMultiWay('conflict',
2772
'bval', ['lca1val', 'lca2val'], 'oval', 'lca2val',
2773
allow_overriding_lca=False)
2774
# OTHER reverted back to BASE, but that is an explicit supersede of all
2776
self.assertLCAMultiWay('other',
2777
'bval', ['lca1val', 'lca2val', 'lca3val'], 'bval', 'lca3val')
2778
self.assertLCAMultiWay('conflict',
2779
'bval', ['lca1val', 'lca2val', 'lca3val'], 'bval', 'lca3val',
2780
allow_overriding_lca=False)
2782
def test_all_differ(self):
2783
self.assertLCAMultiWay('conflict',
2784
'bval', ['lca1val', 'lca2val'], 'oval', 'tval')
2785
self.assertLCAMultiWay('conflict',
2786
'bval', ['lca1val', 'lca2val', 'lca2val'], 'oval', 'tval')
2787
self.assertLCAMultiWay('conflict',
2788
'bval', ['lca1val', 'lca2val', 'lca3val'], 'oval', 'tval')