3 test_description
='combined diff'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 .
"$TEST_DIRECTORY"/lib-diff.sh
12 one
=$1 branch
=$2 side
=$3 &&
14 git branch
$side $branch &&
15 for l
in $one two three fyra
21 git commit
-m $branch &&
23 for l
in $one two three quatro
29 git commit
-m $side &&
30 test_must_fail git merge
$branch &&
31 for l
in $one three four
37 git commit
-m "merge $branch into $side"
43 # Ignore lines that were removed only from the other parent
48 ' "$it" >"$it.actual.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
'
66 git commit -m initial &&
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' '
101 git commit --amend -C HEAD &&
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) &&
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
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:
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' '
134 git commit -m initial &&
136 tr -d Q <<-\EOF >test &&
139 space change coalesce
145 git commit -m "test space change" -a &&
147 git checkout -b side HEAD^ &&
148 tr -d Q <<-\EOF >test &&
151 space change coalesce
157 git commit -m "test other space changes" -a &&
159 test_must_fail git merge main &&
160 tr -d Q <<-\EOF >test &&
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 &&
174 - space change coalesce
175 - all spaces coalesce
179 -eol space coalesce Q
180 -space change coalesce
181 -all spa ces coalesce
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 &&
195 - space change coalesce
196 - all spaces coalesce
197 -space change coalesce
198 -all spa ces coalesce
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 &&
214 --space change coalesce
215 - all spaces coalesce
216 -all spa ces coalesce
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 &&
231 --space change coalesce
232 --all spaces coalesce
237 compare_diff_patch expected actual
240 test_expect_success
'combine diff coalesce simple' '
243 git commit -m initial &&
245 git commit -a -m empty1 &&
247 git checkout HEAD^ &&
249 git commit -a -m empty2 &&
250 test_must_fail git merge side1 &&
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' '
268 git commit -m initial --allow-empty &&
276 git commit -a -m empty1 &&
277 git branch -f side1 &&
278 git checkout HEAD^ &&
285 git commit -a -m empty2 &&
286 git branch -f side2 &&
287 test_must_fail git merge side1 &&
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 &&
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' '
321 git commit -m initial --allow-empty &&
329 git commit -a -m empty1 &&
330 git checkout -B side1 &&
331 git checkout HEAD^ &&
339 git commit -a -m empty2 &&
340 git branch -f side2 &&
341 git checkout HEAD^ &&
349 git commit -a -m empty3 &&
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 &&
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 &&
382 git commit -a -m side1 &&
383 git checkout -B side1 &&
384 git checkout HEAD^ &&
393 git commit -m side2 &&
394 git branch -f side2 &&
395 test_must_fail git merge --no-commit side1 &&
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 &&
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 &&
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
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.
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' '
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 &&
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 &&
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' '
498 git checkout side1d &&
499 test_seq 1 10 >"$(printf "file\twith\ttabs")" &&
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")" &&
507 side2df=$(git hash-object *tabbed) &&
509 git checkout -b funny-names-mergery side1d &&
510 git merge --no-commit side2d &&
512 echo eleven >>"$(printf "i\tam\ttabbed")" &&
513 git mv "$(printf "i\tam\ttabbed")" "$(printf "fickle\tnaming")" &&
515 headf=$(git hash-object fickle*) &&
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