]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4069-remerge-diff.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t4069-remerge-diff.sh
1 #!/bin/sh
2
3 test_description='remerge-diff handling'
4
5 . ./test-lib.sh
6
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
12 fi
13
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 &&
18
19 git branch feature_a &&
20 git branch feature_b &&
21 git branch feature_c &&
22
23 git branch ab_resolution &&
24 git branch bc_resolution &&
25
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 &&
29
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 &&
33
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 &&
37
38 git checkout bc_resolution &&
39 git merge --ff-only feature_b &&
40 # no conflict
41 git merge feature_c &&
42
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
51 '
52
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
57 '
58
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
62 '
63
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 @@
73 1
74 2
75 -<<<<<<< b0ed5cb (change_a)
76 -three
77 -=======
78 -tres
79 ->>>>>>> 6cd3f82 (change_b)
80 +drei
81 4
82 5
83 6
84 7
85 -eight
86 +acht
87 9
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 &&
91
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
95 '
96
97 test_expect_success 'pickaxe still includes additional headers for relevant changes' '
98 # reuses "expect" from the previous testcase
99
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
103 '
104
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 &&
108
109 git show --remerge-diff -S"not present" --all >actual &&
110 test_must_be_empty actual
111 '
112
113 test_expect_success 'setup non-content conflicts' '
114 git switch --orphan base &&
115
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 &&
121
122 git branch side1 &&
123 git branch side2 &&
124
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 &&
131
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 &&
139
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
150 '
151
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 @@
168 -a
169 -b
170 -c
171 -d
172 -e
173 -f
174 -g
175 -h
176 -i
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.
179 EOF
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 &&
183
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
187 '
188
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.
198 EOF
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 &&
202
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
206 '
207
208 test_expect_success 'submodule formatting ignores additional headers' '
209 # Reuses "expect" from last testcase
210
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
214 '
215
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.
224 EOF
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 &&
228
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
232 '
233
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 @@
245 -a
246 -b
247 -c
248 -d
249 -e
250 -f
251 -g
252 -h
253 -i
254 EOF
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 &&
258
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
262 '
263
264 test_expect_success 'setup non-content conflicts' '
265 git switch --orphan newbase &&
266
267 test_write_lines 1 2 3 4 5 6 7 8 9 >numbers &&
268 git add numbers &&
269 git commit -m base &&
270
271 git branch newside1 &&
272 git branch newside2 &&
273
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 &&
278
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 &&
283
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
289 '
290
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 @@
300 1
301 2
302 -<<<<<<< 96f1e45 (side1)
303 -three
304 -=======
305 drei
306 ->>>>>>> 4fd522f (side2)
307 4
308 5
309 6
310 EOF
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 &&
314
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
318 '
319
320 test_done