add-patch: plug a leak handling the '/' command
[alt-git.git] / t / t4038-diff-combined.sh
blob2ce26e585c98c1a3045dee4545763f160f59aa82
1 #!/bin/sh
3 test_description='combined diff'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-diff.sh
11 setup_helper () {
12 one=$1 branch=$2 side=$3 &&
14 git branch $side $branch &&
15 for l in $one two three fyra
17 echo $l
18 done >file &&
19 git add file &&
20 test_tick &&
21 git commit -m $branch &&
22 git checkout $side &&
23 for l in $one two three quatro
25 echo $l
26 done >file &&
27 git add file &&
28 test_tick &&
29 git commit -m $side &&
30 test_must_fail git merge $branch &&
31 for l in $one three four
33 echo $l
34 done >file &&
35 git add file &&
36 test_tick &&
37 git commit -m "merge $branch into $side"
40 verify_helper () {
41 it=$1 &&
43 # Ignore lines that were removed only from the other parent
44 sed -e '
45 1,/^@@@/d
46 /^ -/d
47 s/^\(.\)./\1/
48 ' "$it" >"$it.actual.1" &&
49 sed -e '
50 1,/^@@@/d
51 /^- /d
52 s/^.\(.\)/\1/
53 ' "$it" >"$it.actual.2" &&
55 git diff "$it^" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.1" &&
56 test_cmp "$it.expect.1" "$it.actual.1" &&
58 git diff "$it^2" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.2" &&
59 test_cmp "$it.expect.2" "$it.actual.2"
62 test_expect_success setup '
63 >file &&
64 git add file &&
65 test_tick &&
66 git commit -m initial &&
68 git branch withone &&
69 git branch sansone &&
71 git checkout withone &&
72 setup_helper one withone sidewithone &&
74 git checkout sansone &&
75 setup_helper "" sansone sidesansone
78 test_expect_success 'check combined output (1)' '
79 git show sidewithone -- >sidewithone &&
80 verify_helper sidewithone
83 test_expect_success 'check combined output (1) with git diff <rev>^!' '
84 git diff sidewithone^! -- >sidewithone &&
85 verify_helper sidewithone
88 test_expect_success 'check combined output (2)' '
89 git show sidesansone -- >sidesansone &&
90 verify_helper sidesansone
93 test_expect_success 'check combined output (2) with git diff <rev>^!' '
94 git diff sidesansone^! -- >sidesansone &&
95 verify_helper sidesansone
98 test_expect_success 'diagnose truncated file' '
99 >file &&
100 git add file &&
101 git commit --amend -C HEAD &&
102 git show >out &&
103 grep "diff --cc file" out
106 test_expect_success 'setup for --cc --raw' '
107 blob=$(echo file | git hash-object --stdin -w) &&
108 base_tree=$(echo "100644 blob $blob file" | git mktree) &&
109 trees= &&
110 for i in $(test_seq 1 40)
112 blob=$(echo file$i | git hash-object --stdin -w) &&
113 trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF" || return 1
114 done
117 test_expect_success 'check --cc --raw with four trees' '
118 four_trees=$(echo "$trees" | sed -e 4q) &&
119 git diff --cc --raw $four_trees $base_tree >out &&
120 # Check for four leading colons in the output:
121 grep "^::::[^:]" out
124 test_expect_success 'check --cc --raw with forty trees' '
125 git diff --cc --raw $trees $base_tree >out &&
126 # Check for forty leading colons in the output:
127 grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
130 test_expect_success 'setup combined ignore spaces' '
131 git checkout main &&
132 >test &&
133 git add test &&
134 git commit -m initial &&
136 tr -d Q <<-\EOF >test &&
137 always coalesce
138 eol space coalesce Q
139 space change coalesce
140 all spa ces coalesce
141 eol spaces Q
142 space change
143 all spa ces
145 git commit -m "test space change" -a &&
147 git checkout -b side HEAD^ &&
148 tr -d Q <<-\EOF >test &&
149 always coalesce
150 eol space coalesce
151 space change coalesce
152 all spaces coalesce
153 eol spaces
154 space change
155 all spaces
157 git commit -m "test other space changes" -a &&
159 test_must_fail git merge main &&
160 tr -d Q <<-\EOF >test &&
161 eol spaces Q
162 space change
163 all spa ces
165 git commit -m merged -a
168 test_expect_success 'check combined output (no ignore space)' '
169 git show >actual.tmp &&
170 sed -e "1,/^@@@/d" < actual.tmp >actual &&
171 tr -d Q <<-\EOF >expected &&
172 --always coalesce
173 - eol space coalesce
174 - space change coalesce
175 - all spaces coalesce
176 - eol spaces
177 - space change
178 - all spaces
179 -eol space coalesce Q
180 -space change coalesce
181 -all spa ces coalesce
182 + eol spaces Q
183 + space change
184 + all spa ces
186 compare_diff_patch expected actual
189 test_expect_success 'check combined output (ignore space at eol)' '
190 git show --ignore-space-at-eol >actual.tmp &&
191 sed -e "1,/^@@@/d" < actual.tmp >actual &&
192 tr -d Q <<-\EOF >expected &&
193 --always coalesce
194 --eol space coalesce
195 - space change coalesce
196 - all spaces coalesce
197 -space change coalesce
198 -all spa ces coalesce
199 eol spaces Q
200 - space change
201 - all spaces
202 + space change
203 + all spa ces
205 compare_diff_patch expected actual
208 test_expect_success 'check combined output (ignore space change)' '
209 git show -b >actual.tmp &&
210 sed -e "1,/^@@@/d" < actual.tmp >actual &&
211 tr -d Q <<-\EOF >expected &&
212 --always coalesce
213 --eol space coalesce
214 --space change coalesce
215 - all spaces coalesce
216 -all spa ces coalesce
217 eol spaces Q
218 space change
219 - all spaces
220 + all spa ces
222 compare_diff_patch expected actual
225 test_expect_success 'check combined output (ignore all spaces)' '
226 git show -w >actual.tmp &&
227 sed -e "1,/^@@@/d" < actual.tmp >actual &&
228 tr -d Q <<-\EOF >expected &&
229 --always coalesce
230 --eol space coalesce
231 --space change coalesce
232 --all spaces coalesce
233 eol spaces Q
234 space change
235 all spa ces
237 compare_diff_patch expected actual
240 test_expect_success 'combine diff coalesce simple' '
241 >test &&
242 git add test &&
243 git commit -m initial &&
244 test_seq 4 >test &&
245 git commit -a -m empty1 &&
246 git branch side1 &&
247 git checkout HEAD^ &&
248 test_seq 5 >test &&
249 git commit -a -m empty2 &&
250 test_must_fail git merge side1 &&
251 >test &&
252 git commit -a -m merge &&
253 git show >actual.tmp &&
254 sed -e "1,/^@@@/d" < actual.tmp >actual &&
255 tr -d Q <<-\EOF >expected &&
262 compare_diff_patch expected actual
265 test_expect_success 'combine diff coalesce tricky' '
266 >test &&
267 git add test &&
268 git commit -m initial --allow-empty &&
269 cat <<-\EOF >test &&
276 git commit -a -m empty1 &&
277 git branch -f side1 &&
278 git checkout HEAD^ &&
279 cat <<-\EOF >test &&
285 git commit -a -m empty2 &&
286 git branch -f side2 &&
287 test_must_fail git merge side1 &&
288 >test &&
289 git commit -a -m merge &&
290 git show >actual.tmp &&
291 sed -e "1,/^@@@/d" < actual.tmp >actual &&
292 tr -d Q <<-\EOF >expected &&
300 compare_diff_patch expected actual &&
301 git checkout -f side1 &&
302 test_must_fail git merge side2 &&
303 >test &&
304 git commit -a -m merge &&
305 git show >actual.tmp &&
306 sed -e "1,/^@@@/d" < actual.tmp >actual &&
307 tr -d Q <<-\EOF >expected &&
315 compare_diff_patch expected actual
318 test_expect_failure 'combine diff coalesce three parents' '
319 >test &&
320 git add test &&
321 git commit -m initial --allow-empty &&
322 cat <<-\EOF >test &&
329 git commit -a -m empty1 &&
330 git checkout -B side1 &&
331 git checkout HEAD^ &&
332 cat <<-\EOF >test &&
339 git commit -a -m empty2 &&
340 git branch -f side2 &&
341 git checkout HEAD^ &&
342 cat <<-\EOF >test &&
349 git commit -a -m empty3 &&
350 >test &&
351 git add test &&
352 TREE=$(git write-tree) &&
353 COMMIT=$(git commit-tree -p HEAD -p side1 -p side2 -m merge $TREE) &&
354 git show $COMMIT >actual.tmp &&
355 sed -e "1,/^@@@/d" < actual.tmp >actual &&
356 tr -d Q <<-\EOF >expected &&
357 -- 3
358 ---1
363 - -5
364 ---4
366 compare_diff_patch expected actual
369 # Test for a bug reported at
370 # https://lore.kernel.org/git/20130515143508.GO25742@login.drsnuggles.stderr.nl/
371 # where a delete lines were missing from combined diff output when they
372 # occurred exactly before the context lines of a later change.
373 test_expect_success 'combine diff missing delete bug' '
374 git commit -m initial --allow-empty &&
375 cat <<-\EOF >test &&
381 git add test &&
382 git commit -a -m side1 &&
383 git checkout -B side1 &&
384 git checkout HEAD^ &&
385 cat <<-\EOF >test &&
390 4modified
392 git add test &&
393 git commit -m side2 &&
394 git branch -f side2 &&
395 test_must_fail git merge --no-commit side1 &&
396 cat <<-\EOF >test &&
400 4modified
402 git add test &&
403 git commit -a -m merge &&
404 git diff-tree -c -p HEAD >actual.tmp &&
405 sed -e "1,/^@@@/d" < actual.tmp >actual &&
406 tr -d Q <<-\EOF >expected &&
412 +4modified
414 compare_diff_patch expected actual
417 test_expect_success 'combine diff gets tree sorting right' '
418 # create a directory and a file that sort differently in trees
419 # versus byte-wise (implied "/" sorts after ".")
420 git checkout -f main &&
421 mkdir foo &&
422 echo base >foo/one &&
423 echo base >foo/two &&
424 echo base >foo.ext &&
425 git add foo foo.ext &&
426 git commit -m base &&
428 # one side modifies a file in the directory, along with the root
429 # file...
430 echo main >foo/one &&
431 echo main >foo.ext &&
432 git commit -a -m main &&
434 # the other side modifies the other file in the directory
435 git checkout -b other HEAD^ &&
436 echo other >foo/two &&
437 git commit -a -m other &&
439 # And now we merge. The files in the subdirectory will resolve cleanly,
440 # meaning that a combined diff will not find them interesting. But it
441 # will find the tree itself interesting, because it had to be merged.
442 git checkout main &&
443 git merge other &&
445 printf "MM\tfoo\n" >expect &&
446 git diff-tree -c --name-status -t HEAD >actual.tmp &&
447 sed 1d <actual.tmp >actual &&
448 test_cmp expect actual
451 test_expect_success 'setup for --combined-all-paths' '
452 git branch side1c &&
453 git branch side2c &&
454 git checkout side1c &&
455 test_seq 1 10 >filename-side1c &&
456 side1cf=$(git hash-object filename-side1c) &&
457 git add filename-side1c &&
458 git commit -m with &&
459 git checkout side2c &&
460 test_seq 1 9 >filename-side2c &&
461 echo ten >>filename-side2c &&
462 side2cf=$(git hash-object filename-side2c) &&
463 git add filename-side2c &&
464 git commit -m iam &&
465 git checkout -b mergery side1c &&
466 git merge --no-commit side2c &&
467 git rm filename-side1c &&
468 echo eleven >>filename-side2c &&
469 git mv filename-side2c filename-merged &&
470 mergedf=$(git hash-object filename-merged) &&
471 git add filename-merged &&
472 git commit
475 test_expect_success '--combined-all-paths and --raw' '
476 cat <<-EOF >expect &&
477 ::100644 100644 100644 $side1cf $side2cf $mergedf RR filename-side1c filename-side2c filename-merged
479 git diff-tree -c -M --raw --combined-all-paths HEAD >actual.tmp &&
480 sed 1d <actual.tmp >actual &&
481 test_cmp expect actual
484 test_expect_success '--combined-all-paths and --cc' '
485 cat <<-\EOF >expect &&
486 --- a/filename-side1c
487 --- a/filename-side2c
488 +++ b/filename-merged
490 git diff-tree --cc -M --combined-all-paths HEAD >actual.tmp &&
491 grep ^[-+][-+][-+] <actual.tmp >actual &&
492 test_cmp expect actual
495 test_expect_success FUNNYNAMES 'setup for --combined-all-paths with funny names' '
496 git branch side1d &&
497 git branch side2d &&
498 git checkout side1d &&
499 test_seq 1 10 >"$(printf "file\twith\ttabs")" &&
500 git add file* &&
501 side1df=$(git hash-object *tabs) &&
502 git commit -m with &&
503 git checkout side2d &&
504 test_seq 1 9 >"$(printf "i\tam\ttabbed")" &&
505 echo ten >>"$(printf "i\tam\ttabbed")" &&
506 git add *tabbed &&
507 side2df=$(git hash-object *tabbed) &&
508 git commit -m iam &&
509 git checkout -b funny-names-mergery side1d &&
510 git merge --no-commit side2d &&
511 git rm *tabs &&
512 echo eleven >>"$(printf "i\tam\ttabbed")" &&
513 git mv "$(printf "i\tam\ttabbed")" "$(printf "fickle\tnaming")" &&
514 git add fickle* &&
515 headf=$(git hash-object fickle*) &&
516 git commit &&
517 head=$(git rev-parse HEAD)
520 test_expect_success FUNNYNAMES '--combined-all-paths and --raw and funny names' '
521 cat <<-EOF >expect &&
522 ::100644 100644 100644 $side1df $side2df $headf RR "file\twith\ttabs" "i\tam\ttabbed" "fickle\tnaming"
524 git diff-tree -c -M --raw --combined-all-paths HEAD >actual.tmp &&
525 sed 1d <actual.tmp >actual &&
526 test_cmp expect actual
529 test_expect_success FUNNYNAMES '--combined-all-paths and --raw -and -z and funny names' '
530 printf "$head\0::100644 100644 100644 $side1df $side2df $headf RR\0file\twith\ttabs\0i\tam\ttabbed\0fickle\tnaming\0" >expect &&
531 git diff-tree -c -M --raw --combined-all-paths -z HEAD >actual &&
532 test_cmp expect actual
535 test_expect_success FUNNYNAMES '--combined-all-paths and --cc and funny names' '
536 cat <<-\EOF >expect &&
537 --- "a/file\twith\ttabs"
538 --- "a/i\tam\ttabbed"
539 +++ "b/fickle\tnaming"
541 git diff-tree --cc -M --combined-all-paths HEAD >actual.tmp &&
542 grep ^[-+][-+][-+] <actual.tmp >actual &&
543 test_cmp expect actual
546 test_done