3 test_description
='remerge-diff handling'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 # This test is ort-specific
9 if test "${GIT_TEST_MERGE_ALGORITHM}" != ort
11 skip_all
="GIT_TEST_MERGE_ALGORITHM != ort"
15 test_expect_success
'setup basic merges' '
16 test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
20 git branch feature_a &&
21 git branch feature_b &&
22 git branch feature_c &&
24 git branch ab_resolution &&
25 git branch bc_resolution &&
27 git checkout feature_a &&
28 test_write_lines 1 2 three 4 5 6 7 eight 9 >numbers &&
29 git commit -a -m change_a &&
31 git checkout feature_b &&
32 test_write_lines 1 2 tres 4 5 6 7 8 9 >numbers &&
33 git commit -a -m change_b &&
35 git checkout feature_c &&
36 test_write_lines 1 2 3 4 5 6 7 8 9 10 >numbers &&
37 git commit -a -m change_c &&
39 git checkout bc_resolution &&
40 git merge --ff-only feature_b &&
42 git merge feature_c &&
44 git checkout ab_resolution &&
45 git merge --ff-only feature_a &&
47 test_must_fail git merge feature_b &&
48 # Resolve conflict...and make another change elsewhere
49 test_write_lines 1 2 drei 4 5 6 7 acht 9 >numbers &&
54 test_expect_success
'remerge-diff on a clean merge' '
55 git log -1 --oneline bc_resolution >expect &&
56 git show --oneline --remerge-diff bc_resolution >actual &&
57 test_cmp expect actual
60 test_expect_success
'remerge-diff on a clean merge with a filter' '
61 git show --oneline --remerge-diff --diff-filter=U bc_resolution >actual &&
62 test_must_be_empty actual
65 test_expect_success
'remerge-diff with both a resolved conflict and an unrelated change' '
66 git log -1 --oneline ab_resolution >tmp &&
68 diff --git a/numbers b/numbers
69 remerge CONFLICT (content): Merge conflict in numbers
70 index a1fb731..6875544 100644
76 -<<<<<<< b0ed5cb (change_a)
80 ->>>>>>> 6cd3f82 (change_b)
90 # Hashes above are sha1; rip them out so test works with sha256
91 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
93 git show --oneline --remerge-diff ab_resolution >tmp &&
94 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
95 test_cmp expect actual
98 test_expect_success
'pickaxe still includes additional headers for relevant changes' '
99 # reuses "expect" from the previous testcase
101 git log --oneline --remerge-diff -Sacht ab_resolution >tmp &&
102 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
103 test_cmp expect actual
106 test_expect_success
'can filter out additional headers with pickaxe' '
107 git show --remerge-diff --submodule=log --find-object=HEAD ab_resolution >actual &&
108 test_must_be_empty actual &&
110 git show --remerge-diff -S"not present" --all >actual &&
111 test_must_be_empty actual
114 test_expect_success
'remerge-diff also works for git-diff-tree' '
116 git diff-tree -r -p --remerge-diff --no-commit-id bc_resolution >actual &&
117 test_must_be_empty actual &&
119 # With both a resolved conflict and an unrelated change
121 diff --git a/numbers b/numbers
122 remerge CONFLICT (content): Merge conflict in numbers
123 index a1fb731..6875544 100644
129 -<<<<<<< b0ed5cb (change_a)
133 ->>>>>>> 6cd3f82 (change_b)
143 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
144 git diff-tree -r -p --remerge-diff --no-commit-id ab_resolution >tmp &&
145 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
146 test_cmp expect actual
149 test_expect_success
'setup non-content conflicts' '
150 git switch --orphan base &&
152 test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
153 test_write_lines a b c d e f g h i >letters &&
154 test_write_lines in the way >content &&
155 git add numbers letters content &&
156 git commit -m base &&
161 git checkout side1 &&
162 test_write_lines 1 2 three 4 5 6 7 8 9 >numbers &&
163 git mv letters letters_side1 &&
164 git mv content file_or_directory &&
166 git commit -m side1 &&
168 git checkout side2 &&
170 git mv letters letters_side2 &&
171 mkdir file_or_directory &&
172 echo hello >file_or_directory/world &&
173 git add file_or_directory/world &&
174 git commit -m side2 &&
176 git checkout -b resolution side1 &&
177 test_must_fail git merge side2 &&
178 test_write_lines 1 2 three 4 5 6 7 8 9 >numbers &&
180 git add letters_side1 &&
182 git rm letters_side2 &&
183 git add file_or_directory~HEAD &&
184 git mv file_or_directory~HEAD wanted_content &&
185 git commit -m resolved
188 test_expect_success
'remerge-diff with non-content conflicts' '
189 git log -1 --oneline resolution >tmp &&
191 diff --git a/file_or_directory~HASH (side1) b/wanted_content
192 similarity index 100%
193 rename from file_or_directory~HASH (side1)
194 rename to wanted_content
195 remerge CONFLICT (file/directory): directory in the way of file_or_directory from HASH (side1); moving it to file_or_directory~HASH (side1) instead.
196 diff --git a/letters b/letters
197 remerge CONFLICT (rename/rename): letters renamed to letters_side1 in HASH (side1) and to letters_side2 in HASH (side2).
198 diff --git a/letters_side2 b/letters_side2
199 deleted file mode 100644
200 index b236ae5..0000000
213 diff --git a/numbers b/numbers
214 remerge CONFLICT (modify/delete): numbers deleted in HASH (side2) and modified in HASH (side1). Version HASH (side1) of numbers left in tree.
216 # We still have some sha1 hashes above; rip them out so test works
218 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
220 git show --oneline --remerge-diff resolution >tmp &&
221 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
222 test_cmp expect actual
225 test_expect_success
'remerge-diff w/ diff-filter=U: all conflict headers, no diff content' '
226 git log -1 --oneline resolution >tmp &&
228 diff --git a/file_or_directory~HASH (side1) b/file_or_directory~HASH (side1)
229 remerge CONFLICT (file/directory): directory in the way of file_or_directory from HASH (side1); moving it to file_or_directory~HASH (side1) instead.
230 diff --git a/letters b/letters
231 remerge CONFLICT (rename/rename): letters renamed to letters_side1 in HASH (side1) and to letters_side2 in HASH (side2).
232 diff --git a/numbers b/numbers
233 remerge CONFLICT (modify/delete): numbers deleted in HASH (side2) and modified in HASH (side1). Version HASH (side1) of numbers left in tree.
235 # We still have some sha1 hashes above; rip them out so test works
237 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
239 git show --oneline --remerge-diff --diff-filter=U resolution >tmp &&
240 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
241 test_cmp expect actual
244 test_expect_success
'submodule formatting ignores additional headers' '
245 # Reuses "expect" from last testcase
247 git show --oneline --remerge-diff --diff-filter=U --submodule=log >tmp &&
248 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
249 test_cmp expect actual
252 test_expect_success
'remerge-diff w/ diff-filter=R: relevant file + conflict header' '
253 git log -1 --oneline resolution >tmp &&
255 diff --git a/file_or_directory~HASH (side1) b/wanted_content
256 similarity index 100%
257 rename from file_or_directory~HASH (side1)
258 rename to wanted_content
259 remerge CONFLICT (file/directory): directory in the way of file_or_directory from HASH (side1); moving it to file_or_directory~HASH (side1) instead.
261 # We still have some sha1 hashes above; rip them out so test works
263 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
265 git show --oneline --remerge-diff --diff-filter=R resolution >tmp &&
266 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
267 test_cmp expect actual
270 test_expect_success
'remerge-diff w/ pathspec: limits to relevant file including conflict header' '
271 git log -1 --oneline resolution >tmp &&
273 diff --git a/letters b/letters
274 remerge CONFLICT (rename/rename): letters renamed to letters_side1 in HASH (side1) and to letters_side2 in HASH (side2).
275 diff --git a/letters_side2 b/letters_side2
276 deleted file mode 100644
277 index b236ae5..0000000
291 # We still have some sha1 hashes above; rip them out so test works
293 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
295 git show --oneline --remerge-diff resolution -- "letters*" >tmp &&
296 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
297 test_cmp expect actual
300 test_expect_success
'setup non-content conflicts' '
301 git switch --orphan newbase &&
303 test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
305 git commit -m base &&
307 git branch newside1 &&
308 git branch newside2 &&
310 git checkout newside1 &&
311 test_write_lines 1 2 three 4 5 6 7 8 9 >numbers &&
313 git commit -m side1 &&
315 git checkout newside2 &&
316 test_write_lines 1 2 drei 4 5 6 7 8 9 >numbers &&
318 git commit -m side2 &&
320 git checkout -b newresolution newside1 &&
321 test_must_fail git merge newside2 &&
322 git checkout --theirs numbers &&
323 git add -u numbers &&
324 git commit -m resolved
327 test_expect_success
'remerge-diff turns off history simplification' '
328 git log -1 --oneline newresolution >tmp &&
330 diff --git a/numbers b/numbers
331 remerge CONFLICT (content): Merge conflict in numbers
332 index 070e9e7..5335e78 100644
338 -<<<<<<< 96f1e45 (side1)
342 ->>>>>>> 4fd522f (side2)
347 # We still have some sha1 hashes above; rip them out so test works
349 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
351 git show --oneline --remerge-diff newresolution -- numbers >tmp &&
352 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
353 test_cmp expect actual