831
827
('unchanged', 'f\n'),
832
828
('unchanged', 'g\n')],
834
plan = self.plan_merge_vf.plan_lca_merge('F', 'G')
835
# This is one of the main differences between plan_merge and
836
# plan_lca_merge. plan_lca_merge generates a conflict for 'x => z',
837
# because 'x' was not present in one of the bases. However, in this
838
# case it is spurious because 'x' does not exist in the global base A.
840
('unchanged', 'h\n'),
841
('unchanged', 'a\n'),
842
('conflicted-a', 'x\n'),
844
('unchanged', 'c\n'),
845
('unchanged', 'd\n'),
846
('unchanged', 'y\n'),
847
('unchanged', 'f\n'),
848
('unchanged', 'g\n')],
851
def test_criss_cross_flip_flop(self):
852
# This is specificly trying to trigger problems when using limited
853
# ancestry and weaves. The ancestry graph looks like:
854
# XX unused ancestor, should not show up in the weave
858
# B C B & C both introduce a new line
862
# D E B & C are both merged, so both are common ancestors
863
# In the process of merging, both sides order the new
866
self.add_rev('root', 'XX', [], 'qrs')
867
self.add_rev('root', 'A', ['XX'], 'abcdef')
868
self.add_rev('root', 'B', ['A'], 'abcdgef')
869
self.add_rev('root', 'C', ['A'], 'abcdhef')
870
self.add_rev('root', 'D', ['B', 'C'], 'abcdghef')
871
self.add_rev('root', 'E', ['C', 'B'], 'abcdhgef')
872
plan = list(self.plan_merge_vf.plan_merge('D', 'E'))
874
('unchanged', 'a\n'),
875
('unchanged', 'b\n'),
876
('unchanged', 'c\n'),
877
('unchanged', 'd\n'),
879
('unchanged', 'g\n'),
881
('unchanged', 'e\n'),
882
('unchanged', 'f\n'),
884
pwm = versionedfile.PlanWeaveMerge(plan)
885
self.assertEqualDiff('\n'.join('abcdghef') + '\n',
886
''.join(pwm.base_from_plan()))
887
# Reversing the order reverses the merge plan, and final order of 'hg'
889
plan = list(self.plan_merge_vf.plan_merge('E', 'D'))
891
('unchanged', 'a\n'),
892
('unchanged', 'b\n'),
893
('unchanged', 'c\n'),
894
('unchanged', 'd\n'),
896
('unchanged', 'h\n'),
898
('unchanged', 'e\n'),
899
('unchanged', 'f\n'),
901
pwm = versionedfile.PlanWeaveMerge(plan)
902
self.assertEqualDiff('\n'.join('abcdhgef') + '\n',
903
''.join(pwm.base_from_plan()))
904
# This is where lca differs, in that it (fairly correctly) determines
905
# that there is a conflict because both sides resolved the merge
907
plan = list(self.plan_merge_vf.plan_lca_merge('D', 'E'))
909
('unchanged', 'a\n'),
910
('unchanged', 'b\n'),
911
('unchanged', 'c\n'),
912
('unchanged', 'd\n'),
913
('conflicted-b', 'h\n'),
914
('unchanged', 'g\n'),
915
('conflicted-a', 'h\n'),
916
('unchanged', 'e\n'),
917
('unchanged', 'f\n'),
919
pwm = versionedfile.PlanWeaveMerge(plan)
920
self.assertEqualDiff('\n'.join('abcdgef') + '\n',
921
''.join(pwm.base_from_plan()))
922
# Reversing it changes what line is doubled, but still gives a
924
plan = list(self.plan_merge_vf.plan_lca_merge('E', 'D'))
926
('unchanged', 'a\n'),
927
('unchanged', 'b\n'),
928
('unchanged', 'c\n'),
929
('unchanged', 'd\n'),
930
('conflicted-b', 'g\n'),
931
('unchanged', 'h\n'),
932
('conflicted-a', 'g\n'),
933
('unchanged', 'e\n'),
934
('unchanged', 'f\n'),
936
pwm = versionedfile.PlanWeaveMerge(plan)
937
self.assertEqualDiff('\n'.join('abcdhef') + '\n',
938
''.join(pwm.base_from_plan()))
940
831
def assertRemoveExternalReferences(self, filtered_parent_map,
941
832
child_map, tails, parent_map):
1035
class TestMergeImplementation(object):
1037
def do_merge(self, target_tree, source_tree, **kwargs):
1038
merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1039
target_tree, source_tree.last_revision(),
1040
other_branch=source_tree.branch)
1041
merger.merge_type=self.merge_type
1042
for name, value in kwargs.items():
1043
setattr(merger, name, value)
1046
def test_merge_specific_file(self):
1047
this_tree = self.make_branch_and_tree('this')
1048
this_tree.lock_write()
1049
self.addCleanup(this_tree.unlock)
1050
self.build_tree_contents([
1051
('this/file1', 'a\nb\n'),
1052
('this/file2', 'a\nb\n')
1054
this_tree.add(['file1', 'file2'])
1055
this_tree.commit('Added files')
1056
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
1057
self.build_tree_contents([
1058
('other/file1', 'a\nb\nc\n'),
1059
('other/file2', 'a\nb\nc\n')
1061
other_tree.commit('modified both')
1062
self.build_tree_contents([
1063
('this/file1', 'd\na\nb\n'),
1064
('this/file2', 'd\na\nb\n')
1066
this_tree.commit('modified both')
1067
self.do_merge(this_tree, other_tree, interesting_files=['file1'])
1068
self.assertFileEqual('d\na\nb\nc\n', 'this/file1')
1069
self.assertFileEqual('d\na\nb\n', 'this/file2')
1071
def test_merge_move_and_change(self):
1072
this_tree = self.make_branch_and_tree('this')
1073
this_tree.lock_write()
1074
self.addCleanup(this_tree.unlock)
1075
self.build_tree_contents([
1076
('this/file1', 'line 1\nline 2\nline 3\nline 4\n'),
1078
this_tree.add('file1',)
1079
this_tree.commit('Added file')
1080
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
1081
self.build_tree_contents([
1082
('other/file1', 'line 1\nline 2 to 2.1\nline 3\nline 4\n'),
1084
other_tree.commit('Changed 2 to 2.1')
1085
self.build_tree_contents([
1086
('this/file1', 'line 1\nline 3\nline 2\nline 4\n'),
1088
this_tree.commit('Swapped 2 & 3')
1089
self.do_merge(this_tree, other_tree)
1090
self.assertFileEqual('line 1\n'
1097
'>>>>>>> MERGE-SOURCE\n'
1098
'line 4\n', 'this/file1')
1100
def test_modify_conflicts_with_delete(self):
1101
# If one side deletes a line, and the other modifies that line, then
1102
# the modification should be considered a conflict
1103
builder = self.make_branch_builder('test')
1104
builder.start_series()
1105
builder.build_snapshot('BASE-id', None,
1106
[('add', ('', None, 'directory', None)),
1107
('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
1110
builder.build_snapshot('OTHER-id', ['BASE-id'],
1111
[('modify', ('foo-id', 'a\nc\nd\ne\n'))])
1112
# Modify 'b\n', add 'X\n'
1113
builder.build_snapshot('THIS-id', ['BASE-id'],
1114
[('modify', ('foo-id', 'a\nb2\nc\nd\nX\ne\n'))])
1115
builder.finish_series()
1116
branch = builder.get_branch()
1117
this_tree = branch.bzrdir.create_workingtree()
1118
this_tree.lock_write()
1119
self.addCleanup(this_tree.unlock)
1120
other_tree = this_tree.bzrdir.sprout('other', 'OTHER-id').open_workingtree()
1121
self.do_merge(this_tree, other_tree)
1122
if self.merge_type is _mod_merge.LCAMerger:
1123
self.expectFailure("lca merge doesn't track deleted lines",
1124
self.assertFileEqual,
1129
'>>>>>>> MERGE-SOURCE\n'
1135
self.assertFileEqual(
1140
'>>>>>>> MERGE-SOURCE\n'
1146
def get_limbodir_deletiondir(self, wt):
1147
transform = TreeTransform(wt)
1148
limbodir = transform._limbodir
1149
deletiondir = transform._deletiondir
1150
transform.finalize()
1151
return (limbodir, deletiondir)
1153
def test_merge_with_existing_limbo(self):
1154
wt = self.make_branch_and_tree('this')
1155
(limbodir, deletiondir) = self.get_limbodir_deletiondir(wt)
1157
self.assertRaises(errors.ExistingLimbo, self.do_merge, wt, wt)
1158
self.assertRaises(errors.LockError, wt.unlock)
1160
def test_merge_with_pending_deletion(self):
1161
wt = self.make_branch_and_tree('this')
1162
(limbodir, deletiondir) = self.get_limbodir_deletiondir(wt)
1163
os.mkdir(deletiondir)
1164
self.assertRaises(errors.ExistingPendingDeletion, self.do_merge, wt, wt)
1165
self.assertRaises(errors.LockError, wt.unlock)
1168
class TestMerge3Merge(TestCaseWithTransport, TestMergeImplementation):
1170
merge_type = _mod_merge.Merge3Merger
1173
class TestWeaveMerge(TestCaseWithTransport, TestMergeImplementation):
1175
merge_type = _mod_merge.WeaveMerger
1178
class TestLCAMerge(TestCaseWithTransport, TestMergeImplementation):
1180
merge_type = _mod_merge.LCAMerger
1182
def test_merge_move_and_change(self):
1183
self.expectFailure("lca merge doesn't conflict for move and change",
1184
super(TestLCAMerge, self).test_merge_move_and_change)
1144
1187
class LoggingMerger(object):
1145
1188
# These seem to be the required attributes
1146
1189
requires_base = False