parse-options: use prefix_filename_except_for_dash() helper
[alt-git.git] / t / t4069-remerge-diff.sh
blob07323ebafe0d0cb49f08c4396116fa1f45687cd8
1 #!/bin/sh
3 test_description='remerge-diff handling'
5 . ./test-lib.sh
7 # This test is ort-specific
8 if test "${GIT_TEST_MERGE_ALGORITHM}" != ort
9 then
10 skip_all="GIT_TEST_MERGE_ALGORITHM != ort"
11 test_done
14 test_expect_success 'setup basic merges' '
15 test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
16 git add numbers &&
17 git commit -m base &&
19 git branch feature_a &&
20 git branch feature_b &&
21 git branch feature_c &&
23 git branch ab_resolution &&
24 git branch bc_resolution &&
26 git checkout feature_a &&
27 test_write_lines 1 2 three 4 5 6 7 eight 9 >numbers &&
28 git commit -a -m change_a &&
30 git checkout feature_b &&
31 test_write_lines 1 2 tres 4 5 6 7 8 9 >numbers &&
32 git commit -a -m change_b &&
34 git checkout feature_c &&
35 test_write_lines 1 2 3 4 5 6 7 8 9 10 >numbers &&
36 git commit -a -m change_c &&
38 git checkout bc_resolution &&
39 git merge --ff-only feature_b &&
40 # no conflict
41 git merge feature_c &&
43 git checkout ab_resolution &&
44 git merge --ff-only feature_a &&
45 # conflicts!
46 test_must_fail git merge feature_b &&
47 # Resolve conflict...and make another change elsewhere
48 test_write_lines 1 2 drei 4 5 6 7 acht 9 >numbers &&
49 git add numbers &&
50 git merge --continue
53 test_expect_success 'remerge-diff on a clean merge' '
54 git log -1 --oneline bc_resolution >expect &&
55 git show --oneline --remerge-diff bc_resolution >actual &&
56 test_cmp expect actual
59 test_expect_success 'remerge-diff on a clean merge with a filter' '
60 git show --oneline --remerge-diff --diff-filter=U bc_resolution >actual &&
61 test_must_be_empty actual
64 test_expect_success 'remerge-diff with both a resolved conflict and an unrelated change' '
65 git log -1 --oneline ab_resolution >tmp &&
66 cat <<-EOF >>tmp &&
67 diff --git a/numbers b/numbers
68 remerge CONFLICT (content): Merge conflict in numbers
69 index a1fb731..6875544 100644
70 --- a/numbers
71 +++ b/numbers
72 @@ -1,13 +1,9 @@
75 -<<<<<<< b0ed5cb (change_a)
76 -three
77 -=======
78 -tres
79 ->>>>>>> 6cd3f82 (change_b)
80 +drei
85 -eight
86 +acht
88 EOF
89 # Hashes above are sha1; rip them out so test works with sha256
90 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
92 git show --oneline --remerge-diff ab_resolution >tmp &&
93 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
94 test_cmp expect actual
97 test_expect_success 'pickaxe still includes additional headers for relevant changes' '
98 # reuses "expect" from the previous testcase
100 git log --oneline --remerge-diff -Sacht ab_resolution >tmp &&
101 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
102 test_cmp expect actual
105 test_expect_success 'can filter out additional headers with pickaxe' '
106 git show --remerge-diff --submodule=log --find-object=HEAD ab_resolution >actual &&
107 test_must_be_empty actual &&
109 git show --remerge-diff -S"not present" --all >actual &&
110 test_must_be_empty actual
113 test_expect_success 'setup non-content conflicts' '
114 git switch --orphan base &&
116 test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
117 test_write_lines a b c d e f g h i >letters &&
118 test_write_lines in the way >content &&
119 git add numbers letters content &&
120 git commit -m base &&
122 git branch side1 &&
123 git branch side2 &&
125 git checkout side1 &&
126 test_write_lines 1 2 three 4 5 6 7 8 9 >numbers &&
127 git mv letters letters_side1 &&
128 git mv content file_or_directory &&
129 git add numbers &&
130 git commit -m side1 &&
132 git checkout side2 &&
133 git rm numbers &&
134 git mv letters letters_side2 &&
135 mkdir file_or_directory &&
136 echo hello >file_or_directory/world &&
137 git add file_or_directory/world &&
138 git commit -m side2 &&
140 git checkout -b resolution side1 &&
141 test_must_fail git merge side2 &&
142 test_write_lines 1 2 three 4 5 6 7 8 9 >numbers &&
143 git add numbers &&
144 git add letters_side1 &&
145 git rm letters &&
146 git rm letters_side2 &&
147 git add file_or_directory~HEAD &&
148 git mv file_or_directory~HEAD wanted_content &&
149 git commit -m resolved
152 test_expect_success 'remerge-diff with non-content conflicts' '
153 git log -1 --oneline resolution >tmp &&
154 cat <<-EOF >>tmp &&
155 diff --git a/file_or_directory~HASH (side1) b/wanted_content
156 similarity index 100%
157 rename from file_or_directory~HASH (side1)
158 rename to wanted_content
159 remerge CONFLICT (file/directory): directory in the way of file_or_directory from HASH (side1); moving it to file_or_directory~HASH (side1) instead.
160 diff --git a/letters b/letters
161 remerge CONFLICT (rename/rename): letters renamed to letters_side1 in HASH (side1) and to letters_side2 in HASH (side2).
162 diff --git a/letters_side2 b/letters_side2
163 deleted file mode 100644
164 index b236ae5..0000000
165 --- a/letters_side2
166 +++ /dev/null
167 @@ -1,9 +0,0 @@
177 diff --git a/numbers b/numbers
178 remerge CONFLICT (modify/delete): numbers deleted in HASH (side2) and modified in HASH (side1). Version HASH (side1) of numbers left in tree.
180 # We still have some sha1 hashes above; rip them out so test works
181 # with sha256
182 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
184 git show --oneline --remerge-diff resolution >tmp &&
185 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
186 test_cmp expect actual
189 test_expect_success 'remerge-diff w/ diff-filter=U: all conflict headers, no diff content' '
190 git log -1 --oneline resolution >tmp &&
191 cat <<-EOF >>tmp &&
192 diff --git a/file_or_directory~HASH (side1) b/file_or_directory~HASH (side1)
193 remerge CONFLICT (file/directory): directory in the way of file_or_directory from HASH (side1); moving it to file_or_directory~HASH (side1) instead.
194 diff --git a/letters b/letters
195 remerge CONFLICT (rename/rename): letters renamed to letters_side1 in HASH (side1) and to letters_side2 in HASH (side2).
196 diff --git a/numbers b/numbers
197 remerge CONFLICT (modify/delete): numbers deleted in HASH (side2) and modified in HASH (side1). Version HASH (side1) of numbers left in tree.
199 # We still have some sha1 hashes above; rip them out so test works
200 # with sha256
201 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
203 git show --oneline --remerge-diff --diff-filter=U resolution >tmp &&
204 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
205 test_cmp expect actual
208 test_expect_success 'submodule formatting ignores additional headers' '
209 # Reuses "expect" from last testcase
211 git show --oneline --remerge-diff --diff-filter=U --submodule=log >tmp &&
212 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
213 test_cmp expect actual
216 test_expect_success 'remerge-diff w/ diff-filter=R: relevant file + conflict header' '
217 git log -1 --oneline resolution >tmp &&
218 cat <<-EOF >>tmp &&
219 diff --git a/file_or_directory~HASH (side1) b/wanted_content
220 similarity index 100%
221 rename from file_or_directory~HASH (side1)
222 rename to wanted_content
223 remerge CONFLICT (file/directory): directory in the way of file_or_directory from HASH (side1); moving it to file_or_directory~HASH (side1) instead.
225 # We still have some sha1 hashes above; rip them out so test works
226 # with sha256
227 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
229 git show --oneline --remerge-diff --diff-filter=R resolution >tmp &&
230 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
231 test_cmp expect actual
234 test_expect_success 'remerge-diff w/ pathspec: limits to relevant file including conflict header' '
235 git log -1 --oneline resolution >tmp &&
236 cat <<-EOF >>tmp &&
237 diff --git a/letters b/letters
238 remerge CONFLICT (rename/rename): letters renamed to letters_side1 in HASH (side1) and to letters_side2 in HASH (side2).
239 diff --git a/letters_side2 b/letters_side2
240 deleted file mode 100644
241 index b236ae5..0000000
242 --- a/letters_side2
243 +++ /dev/null
244 @@ -1,9 +0,0 @@
255 # We still have some sha1 hashes above; rip them out so test works
256 # with sha256
257 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
259 git show --oneline --remerge-diff resolution -- "letters*" >tmp &&
260 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
261 test_cmp expect actual
264 test_expect_success 'setup non-content conflicts' '
265 git switch --orphan newbase &&
267 test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
268 git add numbers &&
269 git commit -m base &&
271 git branch newside1 &&
272 git branch newside2 &&
274 git checkout newside1 &&
275 test_write_lines 1 2 three 4 5 6 7 8 9 >numbers &&
276 git add numbers &&
277 git commit -m side1 &&
279 git checkout newside2 &&
280 test_write_lines 1 2 drei 4 5 6 7 8 9 >numbers &&
281 git add numbers &&
282 git commit -m side2 &&
284 git checkout -b newresolution newside1 &&
285 test_must_fail git merge newside2 &&
286 git checkout --theirs numbers &&
287 git add -u numbers &&
288 git commit -m resolved
291 test_expect_success 'remerge-diff turns off history simplification' '
292 git log -1 --oneline newresolution >tmp &&
293 cat <<-EOF >>tmp &&
294 diff --git a/numbers b/numbers
295 remerge CONFLICT (content): Merge conflict in numbers
296 index 070e9e7..5335e78 100644
297 --- a/numbers
298 +++ b/numbers
299 @@ -1,10 +1,6 @@
302 -<<<<<<< 96f1e45 (side1)
303 -three
304 -=======
305 drei
306 ->>>>>>> 4fd522f (side2)
311 # We still have some sha1 hashes above; rip them out so test works
312 # with sha256
313 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >expect &&
315 git show --oneline --remerge-diff newresolution -- numbers >tmp &&
316 sed -e "s/[0-9a-f]\{7,\}/HASH/g" tmp >actual &&
317 test_cmp expect actual
320 test_done