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 (2)' '
84 git show sidesansone -- >sidesansone &&
85 verify_helper sidesansone
88 test_expect_success 'diagnose truncated file' '
91 git commit --amend -C HEAD &&
93 grep "diff --cc file" out
96 test_expect_success 'setup for --cc --raw' '
97 blob=$(echo file | git hash-object --stdin -w) &&
98 base_tree=$(echo "100644 blob $blob file" | git mktree) &&
100 for i in $(test_seq 1 40)
102 blob=$(echo file$i | git hash-object --stdin -w) &&
103 trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF"
107 test_expect_success 'check --cc --raw with four trees' '
108 four_trees=$(echo "$trees" | sed -e 4q) &&
109 git diff --cc --raw $four_trees $base_tree >out &&
110 # Check for four leading colons in the output:
114 test_expect_success 'check --cc --raw with forty trees' '
115 git diff --cc --raw $trees $base_tree >out &&
116 # Check for forty leading colons in the output:
117 grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
120 test_expect_success 'setup combined ignore spaces' '
124 git commit -m initial &&
126 tr -d Q <<-\EOF >test &&
129 space change coalesce
135 git commit -m "test space change" -a &&
137 git checkout -b side HEAD^ &&
138 tr -d Q <<-\EOF >test &&
141 space change coalesce
147 git commit -m "test other space changes" -a &&
149 test_must_fail git merge main &&
150 tr -d Q <<-\EOF >test &&
155 git commit -m merged -a
158 test_expect_success 'check combined output (no ignore space)' '
159 git show >actual.tmp &&
160 sed -e "1,/^@@@/d" < actual.tmp >actual &&
161 tr -d Q <<-\EOF >expected &&
164 - space change coalesce
165 - all spaces coalesce
169 -eol space coalesce Q
170 -space change coalesce
171 -all spa ces coalesce
176 compare_diff_patch expected actual
179 test_expect_success 'check combined output (ignore space at eol)' '
180 git show --ignore-space-at-eol >actual.tmp &&
181 sed -e "1,/^@@@/d" < actual.tmp >actual &&
182 tr -d Q <<-\EOF >expected &&
185 - space change coalesce
186 - all spaces coalesce
187 -space change coalesce
188 -all spa ces coalesce
195 compare_diff_patch expected actual
198 test_expect_success 'check combined output (ignore space change)' '
199 git show -b >actual.tmp &&
200 sed -e "1,/^@@@/d" < actual.tmp >actual &&
201 tr -d Q <<-\EOF >expected &&
204 --space change coalesce
205 - all spaces coalesce
206 -all spa ces coalesce
212 compare_diff_patch expected actual
215 test_expect_success 'check combined output (ignore all spaces)' '
216 git show -w >actual.tmp &&
217 sed -e "1,/^@@@/d" < actual.tmp >actual &&
218 tr -d Q <<-\EOF >expected &&
221 --space change coalesce
222 --all spaces coalesce
227 compare_diff_patch expected actual
230 test_expect_success 'combine diff coalesce simple' '
233 git commit -m initial &&
235 git commit -a -m empty1 &&
237 git checkout HEAD^ &&
239 git commit -a -m empty2 &&
240 test_must_fail git merge side1 &&
242 git commit -a -m merge &&
243 git show >actual.tmp &&
244 sed -e "1,/^@@@/d" < actual.tmp >actual &&
245 tr -d Q <<-\EOF >expected &&
252 compare_diff_patch expected actual
255 test_expect_success 'combine diff coalesce tricky' '
258 git commit -m initial --allow-empty &&
266 git commit -a -m empty1 &&
267 git branch -f side1 &&
268 git checkout HEAD^ &&
275 git commit -a -m empty2 &&
276 git branch -f side2 &&
277 test_must_fail git merge side1 &&
279 git commit -a -m merge &&
280 git show >actual.tmp &&
281 sed -e "1,/^@@@/d" < actual.tmp >actual &&
282 tr -d Q <<-\EOF >expected &&
290 compare_diff_patch expected actual &&
291 git checkout -f side1 &&
292 test_must_fail git merge side2 &&
294 git commit -a -m merge &&
295 git show >actual.tmp &&
296 sed -e "1,/^@@@/d" < actual.tmp >actual &&
297 tr -d Q <<-\EOF >expected &&
305 compare_diff_patch expected actual
308 test_expect_failure 'combine diff coalesce three parents' '
311 git commit -m initial --allow-empty &&
319 git commit -a -m empty1 &&
320 git checkout -B side1 &&
321 git checkout HEAD^ &&
329 git commit -a -m empty2 &&
330 git branch -f side2 &&
331 git checkout HEAD^ &&
339 git commit -a -m empty3 &&
342 TREE=$(git write-tree) &&
343 COMMIT=$(git commit-tree -p HEAD -p side1 -p side2 -m merge $TREE) &&
344 git show $COMMIT >actual.tmp &&
345 sed -e "1,/^@@@/d" < actual.tmp >actual &&
346 tr -d Q <<-\EOF >expected &&
356 compare_diff_patch expected actual
359 # Test for a bug reported at
360 # https://lore.kernel.org/git/20130515143508.GO25742@login.drsnuggles.stderr.nl/
361 # where a delete lines were missing from combined diff output when they
362 # occurred exactly before the context lines of a later change.
363 test_expect_success 'combine diff missing delete bug' '
364 git commit -m initial --allow-empty &&
372 git commit -a -m side1 &&
373 git checkout -B side1 &&
374 git checkout HEAD^ &&
383 git commit -m side2 &&
384 git branch -f side2 &&
385 test_must_fail git merge --no-commit side1 &&
393 git commit -a -m merge &&
394 git diff-tree -c -p HEAD >actual.tmp &&
395 sed -e "1,/^@@@/d" < actual.tmp >actual &&
396 tr -d Q <<-\EOF >expected &&
404 compare_diff_patch expected actual
407 test_expect_success 'combine diff gets tree sorting right' '
408 # create a directory and a file that sort differently in trees
409 # versus byte-wise (implied "/" sorts after ".")
410 git checkout -f main &&
412 echo base >foo/one &&
413 echo base >foo/two &&
414 echo base >foo.ext &&
415 git add foo foo.ext &&
416 git commit -m base &&
418 # one side modifies a file in the directory, along with the root
420 echo main >foo/one &&
421 echo main >foo.ext &&
422 git commit -a -m main &&
424 # the other side modifies the other file in the directory
425 git checkout -b other HEAD^ &&
426 echo other >foo/two &&
427 git commit -a -m other &&
429 # And now we merge. The files in the subdirectory will resolve cleanly,
430 # meaning that a combined diff will not find them interesting. But it
431 # will find the tree itself interesting, because it had to be merged.
435 printf "MM\tfoo\n" >expect &&
436 git diff-tree -c --name-status -t HEAD >actual.tmp &&
437 sed 1d <actual.tmp >actual &&
438 test_cmp expect actual
441 test_expect_success 'setup for --combined-all-paths' '
444 git checkout side1c &&
445 test_seq 1 10 >filename-side1c &&
446 side1cf=$(git hash-object filename-side1c) &&
447 git add filename-side1c &&
448 git commit -m with &&
449 git checkout side2c &&
450 test_seq 1 9 >filename-side2c &&
451 echo ten >>filename-side2c &&
452 side2cf=$(git hash-object filename-side2c) &&
453 git add filename-side2c &&
455 git checkout -b mergery side1c &&
456 git merge --no-commit side2c &&
457 git rm filename-side1c &&
458 echo eleven >>filename-side2c &&
459 git mv filename-side2c filename-merged &&
460 mergedf=$(git hash-object filename-merged) &&
461 git add filename-merged &&
465 test_expect_success '--combined-all-paths and --raw' '
466 cat <<-EOF >expect &&
467 ::100644 100644 100644 $side1cf $side2cf $mergedf RR filename-side1c filename-side2c filename-merged
469 git diff-tree -c -M --raw --combined-all-paths HEAD >actual.tmp &&
470 sed 1d <actual.tmp >actual &&
471 test_cmp expect actual
474 test_expect_success '--combined-all-paths and --cc' '
475 cat <<-\EOF >expect &&
476 --- a/filename-side1c
477 --- a/filename-side2c
478 +++ b/filename-merged
480 git diff-tree --cc -M --combined-all-paths HEAD >actual.tmp &&
481 grep ^[-+][-+][-+] <actual.tmp >actual &&
482 test_cmp expect actual
485 test_expect_success FUNNYNAMES 'setup for --combined-all-paths with funny names' '
488 git checkout side1d &&
489 test_seq 1 10 >"$(printf "file\twith\ttabs")" &&
491 side1df=$(git hash-object *tabs) &&
492 git commit -m with &&
493 git checkout side2d &&
494 test_seq 1 9 >"$(printf "i\tam\ttabbed")" &&
495 echo ten >>"$(printf "i\tam\ttabbed")" &&
497 side2df=$(git hash-object *tabbed) &&
499 git checkout -b funny-names-mergery side1d &&
500 git merge --no-commit side2d &&
502 echo eleven >>"$(printf "i\tam\ttabbed")" &&
503 git mv "$(printf "i\tam\ttabbed")" "$(printf "fickle\tnaming")" &&
505 headf=$(git hash-object fickle*) &&
507 head=$(git rev-parse HEAD)
510 test_expect_success FUNNYNAMES '--combined-all-paths and --raw and funny names' '
511 cat <<-EOF >expect &&
512 ::100644 100644 100644 $side1df $side2df $headf RR "file\twith\ttabs" "i\tam\ttabbed" "fickle\tnaming"
514 git diff-tree -c -M --raw --combined-all-paths HEAD >actual.tmp &&
515 sed 1d <actual.tmp >actual &&
516 test_cmp expect actual
519 test_expect_success FUNNYNAMES '--combined-all-paths and --raw -and -z and funny names' '
520 printf "$head\0::100644 100644 100644 $side1df $side2df $headf RR\0file\twith\ttabs\0i\tam\ttabbed\0fickle\tnaming\0" >expect &&
521 git diff-tree -c -M --raw --combined-all-paths -z HEAD >actual &&
522 test_cmp expect actual
525 test_expect_success FUNNYNAMES '--combined-all-paths and --cc and funny names' '
526 cat <<-\EOF >expect &&
527 --- "a/file\twith\ttabs"
528 --- "a/i\tam\ttabbed"
529 +++ "b/fickle\tnaming"
531 git diff-tree --cc -M --combined-all-paths HEAD >actual.tmp &&
532 grep ^[-+][-+][-+] <actual.tmp >actual &&
533 test_cmp expect actual