3 test_description='combined diff'
6 . "$TEST_DIRECTORY"/diff-lib.sh
9 one=$1 branch=$2 side=$3 &&
11 git branch $side $branch &&
12 for l in $one two three fyra
18 git commit -m $branch &&
20 for l in $one two three quatro
26 git commit -m $side &&
27 test_must_fail git merge $branch &&
28 for l in $one three four
34 git commit -m "merge $branch into $side"
40 # Ignore lines that were removed only from the other parent
45 ' "$it" >"$it.actual.1" &&
50 ' "$it" >"$it.actual.2" &&
52 git diff "$it^" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.1" &&
53 test_cmp "$it.expect.1" "$it.actual.1" &&
55 git diff "$it^2" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.2" &&
56 test_cmp "$it.expect.2" "$it.actual.2"
59 test_expect_success setup '
63 git commit -m initial &&
68 git checkout withone &&
69 setup_helper one withone sidewithone &&
71 git checkout sansone &&
72 setup_helper "" sansone sidesansone
75 test_expect_success 'check combined output (1)' '
76 git show sidewithone -- >sidewithone &&
77 verify_helper sidewithone
80 test_expect_success 'check combined output (2)' '
81 git show sidesansone -- >sidesansone &&
82 verify_helper sidesansone
85 test_expect_success 'diagnose truncated file' '
88 git commit --amend -C HEAD &&
90 grep "diff --cc file" out
93 test_expect_success 'setup for --cc --raw' '
94 blob=$(echo file | git hash-object --stdin -w) &&
95 base_tree=$(echo "100644 blob $blob file" | git mktree) &&
97 for i in $(test_seq 1 40)
99 blob=$(echo file$i | git hash-object --stdin -w) &&
100 trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF"
104 test_expect_success 'check --cc --raw with four trees' '
105 four_trees=$(echo "$trees" | sed -e 4q) &&
106 git diff --cc --raw $four_trees $base_tree >out &&
107 # Check for four leading colons in the output:
111 test_expect_success 'check --cc --raw with forty trees' '
112 git diff --cc --raw $trees $base_tree >out &&
113 # Check for forty leading colons in the output:
114 grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
117 test_expect_success 'setup combined ignore spaces' '
118 git checkout master &&
121 git commit -m initial &&
123 tr -d Q <<-\EOF >test &&
126 space change coalesce
132 git commit -m "test space change" -a &&
134 git checkout -b side HEAD^ &&
135 tr -d Q <<-\EOF >test &&
138 space change coalesce
144 git commit -m "test other space changes" -a &&
146 test_must_fail git merge master &&
147 tr -d Q <<-\EOF >test &&
152 git commit -m merged -a
155 test_expect_success 'check combined output (no ignore space)' '
156 git show >actual.tmp &&
157 sed -e "1,/^@@@/d" < actual.tmp >actual &&
158 tr -d Q <<-\EOF >expected &&
161 - space change coalesce
162 - all spaces coalesce
166 -eol space coalesce Q
167 -space change coalesce
168 -all spa ces coalesce
173 compare_diff_patch expected actual
176 test_expect_success 'check combined output (ignore space at eol)' '
177 git show --ignore-space-at-eol >actual.tmp &&
178 sed -e "1,/^@@@/d" < actual.tmp >actual &&
179 tr -d Q <<-\EOF >expected &&
182 - space change coalesce
183 - all spaces coalesce
184 -space change coalesce
185 -all spa ces coalesce
192 compare_diff_patch expected actual
195 test_expect_success 'check combined output (ignore space change)' '
196 git show -b >actual.tmp &&
197 sed -e "1,/^@@@/d" < actual.tmp >actual &&
198 tr -d Q <<-\EOF >expected &&
201 --space change coalesce
202 - all spaces coalesce
203 -all spa ces coalesce
209 compare_diff_patch expected actual
212 test_expect_success 'check combined output (ignore all spaces)' '
213 git show -w >actual.tmp &&
214 sed -e "1,/^@@@/d" < actual.tmp >actual &&
215 tr -d Q <<-\EOF >expected &&
218 --space change coalesce
219 --all spaces coalesce
224 compare_diff_patch expected actual
227 test_expect_success 'combine diff coalesce simple' '
230 git commit -m initial &&
232 git commit -a -m empty1 &&
234 git checkout HEAD^ &&
236 git commit -a -m empty2 &&
237 test_must_fail git merge side1 &&
239 git commit -a -m merge &&
240 git show >actual.tmp &&
241 sed -e "1,/^@@@/d" < actual.tmp >actual &&
242 tr -d Q <<-\EOF >expected &&
249 compare_diff_patch expected actual
252 test_expect_success 'combine diff coalesce tricky' '
255 git commit -m initial --allow-empty &&
263 git commit -a -m empty1 &&
264 git branch -f side1 &&
265 git checkout HEAD^ &&
272 git commit -a -m empty2 &&
273 git branch -f side2 &&
274 test_must_fail git merge side1 &&
276 git commit -a -m merge &&
277 git show >actual.tmp &&
278 sed -e "1,/^@@@/d" < actual.tmp >actual &&
279 tr -d Q <<-\EOF >expected &&
287 compare_diff_patch expected actual &&
288 git checkout -f side1 &&
289 test_must_fail git merge side2 &&
291 git commit -a -m merge &&
292 git show >actual.tmp &&
293 sed -e "1,/^@@@/d" < actual.tmp >actual &&
294 tr -d Q <<-\EOF >expected &&
302 compare_diff_patch expected actual
305 test_expect_failure 'combine diff coalesce three parents' '
308 git commit -m initial --allow-empty &&
316 git commit -a -m empty1 &&
317 git checkout -B side1 &&
318 git checkout HEAD^ &&
326 git commit -a -m empty2 &&
327 git branch -f side2 &&
328 git checkout HEAD^ &&
336 git commit -a -m empty3 &&
339 TREE=$(git write-tree) &&
340 COMMIT=$(git commit-tree -p HEAD -p side1 -p side2 -m merge $TREE) &&
341 git show $COMMIT >actual.tmp &&
342 sed -e "1,/^@@@/d" < actual.tmp >actual &&
343 tr -d Q <<-\EOF >expected &&
353 compare_diff_patch expected actual
356 # Test for a bug reported at
357 # https://public-inbox.org/git/20130515143508.GO25742@login.drsnuggles.stderr.nl/
358 # where a delete lines were missing from combined diff output when they
359 # occurred exactly before the context lines of a later change.
360 test_expect_success 'combine diff missing delete bug' '
361 git commit -m initial --allow-empty &&
369 git commit -a -m side1 &&
370 git checkout -B side1 &&
371 git checkout HEAD^ &&
380 git commit -m side2 &&
381 git branch -f side2 &&
382 test_must_fail git merge --no-commit side1 &&
390 git commit -a -m merge &&
391 git diff-tree -c -p HEAD >actual.tmp &&
392 sed -e "1,/^@@@/d" < actual.tmp >actual &&
393 tr -d Q <<-\EOF >expected &&
401 compare_diff_patch expected actual
404 test_expect_success 'combine diff gets tree sorting right' '
405 # create a directory and a file that sort differently in trees
406 # versus byte-wise (implied "/" sorts after ".")
407 git checkout -f master &&
409 echo base >foo/one &&
410 echo base >foo/two &&
411 echo base >foo.ext &&
412 git add foo foo.ext &&
413 git commit -m base &&
415 # one side modifies a file in the directory, along with the root
417 echo master >foo/one &&
418 echo master >foo.ext &&
419 git commit -a -m master &&
421 # the other side modifies the other file in the directory
422 git checkout -b other HEAD^ &&
423 echo other >foo/two &&
424 git commit -a -m other &&
426 # And now we merge. The files in the subdirectory will resolve cleanly,
427 # meaning that a combined diff will not find them interesting. But it
428 # will find the tree itself interesting, because it had to be merged.
429 git checkout master &&
432 printf "MM\tfoo\n" >expect &&
433 git diff-tree -c --name-status -t HEAD >actual.tmp &&
434 sed 1d <actual.tmp >actual &&
435 test_cmp expect actual
438 test_expect_success 'setup for --combined-all-paths' '
441 git checkout side1c &&
442 test_seq 1 10 >filename-side1c &&
443 git add filename-side1c &&
444 git commit -m with &&
445 git checkout side2c &&
446 test_seq 1 9 >filename-side2c &&
447 echo ten >>filename-side2c &&
448 git add filename-side2c &&
450 git checkout -b mergery side1c &&
451 git merge --no-commit side2c &&
452 git rm filename-side1c &&
453 echo eleven >>filename-side2c &&
454 git mv filename-side2c filename-merged &&
455 git add filename-merged &&
459 test_expect_success '--combined-all-paths and --raw' '
460 cat <<-\EOF >expect &&
461 ::100644 100644 100644 f00c965d8307308469e537302baa73048488f162 088bd5d92c2a8e0203ca8e7e4c2a5c692f6ae3f7 333b9c62519f285e1854830ade0fe1ef1d40ee1b RR filename-side1c filename-side2c filename-merged
463 git diff-tree -c -M --raw --combined-all-paths HEAD >actual.tmp &&
464 sed 1d <actual.tmp >actual &&
465 test_cmp expect actual
468 test_expect_success '--combined-all-paths and --cc' '
469 cat <<-\EOF >expect &&
470 --- a/filename-side1c
471 --- a/filename-side2c
472 +++ b/filename-merged
474 git diff-tree --cc -M --combined-all-paths HEAD >actual.tmp &&
475 grep ^[-+][-+][-+] <actual.tmp >actual &&
476 test_cmp expect actual
479 test_expect_success FUNNYNAMES 'setup for --combined-all-paths with funny names' '
482 git checkout side1d &&
483 test_seq 1 10 >$(printf "file\twith\ttabs") &&
485 git commit -m with &&
486 git checkout side2d &&
487 test_seq 1 9 >$(printf "i\tam\ttabbed") &&
488 echo ten >>$(printf "i\tam\ttabbed") &&
491 git checkout -b funny-names-mergery side1d &&
492 git merge --no-commit side2d &&
494 echo eleven >>$(printf "i\tam\ttabbed") &&
495 git mv "$(printf "i\tam\ttabbed")" "$(printf "fickle\tnaming")" &&
500 test_expect_success FUNNYNAMES '--combined-all-paths and --raw and funny names' '
501 cat <<-\EOF >expect &&
502 ::100644 100644 100644 f00c965d8307308469e537302baa73048488f162 088bd5d92c2a8e0203ca8e7e4c2a5c692f6ae3f7 333b9c62519f285e1854830ade0fe1ef1d40ee1b RR "file\twith\ttabs" "i\tam\ttabbed" "fickle\tnaming"
504 git diff-tree -c -M --raw --combined-all-paths HEAD >actual.tmp &&
505 sed 1d <actual.tmp >actual &&
506 test_cmp expect actual
509 test_expect_success FUNNYNAMES '--combined-all-paths and --raw -and -z and funny names' '
510 printf "aaf8087c3cbd4db8e185a2d074cf27c53cfb75d7\0::100644 100644 100644 f00c965d8307308469e537302baa73048488f162 088bd5d92c2a8e0203ca8e7e4c2a5c692f6ae3f7 333b9c62519f285e1854830ade0fe1ef1d40ee1b RR\0file\twith\ttabs\0i\tam\ttabbed\0fickle\tnaming\0" >expect &&
511 git diff-tree -c -M --raw --combined-all-paths -z HEAD >actual &&
512 test_cmp -a expect actual
515 test_expect_success FUNNYNAMES '--combined-all-paths and --cc and funny names' '
516 cat <<-\EOF >expect &&
517 --- "a/file\twith\ttabs"
518 --- "a/i\tam\ttabbed"
519 +++ "b/fickle\tnaming"
521 git diff-tree --cc -M --combined-all-paths HEAD >actual.tmp &&
522 grep ^[-+][-+][-+] <actual.tmp >actual &&
523 test_cmp expect actual