The eleventh batch
[git/gitster.git] / t / t4038-diff-combined.sh
blob00190802d831f032fd936b3fe11ad5661dfb6ca5
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-diff.sh
12 setup_helper () {
13 one=$1 branch=$2 side=$3 &&
15 git branch $side $branch &&
16 for l in $one two three fyra
18 echo $l
19 done >file &&
20 git add file &&
21 test_tick &&
22 git commit -m $branch &&
23 git checkout $side &&
24 for l in $one two three quatro
26 echo $l
27 done >file &&
28 git add file &&
29 test_tick &&
30 git commit -m $side &&
31 test_must_fail git merge $branch &&
32 for l in $one three four
34 echo $l
35 done >file &&
36 git add file &&
37 test_tick &&
38 git commit -m "merge $branch into $side"
41 verify_helper () {
42 it=$1 &&
44 # Ignore lines that were removed only from the other parent
45 sed -e '
46 1,/^@@@/d
47 /^ -/d
48 s/^\(.\)./\1/
49 ' "$it" >"$it.actual.1" &&
50 sed -e '
51 1,/^@@@/d
52 /^- /d
53 s/^.\(.\)/\1/
54 ' "$it" >"$it.actual.2" &&
56 git diff "$it^" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.1" &&
57 test_cmp "$it.expect.1" "$it.actual.1" &&
59 git diff "$it^2" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.2" &&
60 test_cmp "$it.expect.2" "$it.actual.2"
63 test_expect_success setup '
64 >file &&
65 git add file &&
66 test_tick &&
67 git commit -m initial &&
69 git branch withone &&
70 git branch sansone &&
72 git checkout withone &&
73 setup_helper one withone sidewithone &&
75 git checkout sansone &&
76 setup_helper "" sansone sidesansone
79 test_expect_success 'check combined output (1)' '
80 git show sidewithone -- >sidewithone &&
81 verify_helper sidewithone
84 test_expect_success 'check combined output (1) with git diff <rev>^!' '
85 git diff sidewithone^! -- >sidewithone &&
86 verify_helper sidewithone
89 test_expect_success 'check combined output (2)' '
90 git show sidesansone -- >sidesansone &&
91 verify_helper sidesansone
94 test_expect_success 'check combined output (2) with git diff <rev>^!' '
95 git diff sidesansone^! -- >sidesansone &&
96 verify_helper sidesansone
99 test_expect_success 'diagnose truncated file' '
100 >file &&
101 git add file &&
102 git commit --amend -C HEAD &&
103 git show >out &&
104 grep "diff --cc file" out
107 test_expect_success 'setup for --cc --raw' '
108 blob=$(echo file | git hash-object --stdin -w) &&
109 base_tree=$(echo "100644 blob $blob file" | git mktree) &&
110 trees= &&
111 for i in $(test_seq 1 40)
113 blob=$(echo file$i | git hash-object --stdin -w) &&
114 trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF" || return 1
115 done
118 test_expect_success 'check --cc --raw with four trees' '
119 four_trees=$(echo "$trees" | sed -e 4q) &&
120 git diff --cc --raw $four_trees $base_tree >out &&
121 # Check for four leading colons in the output:
122 grep "^::::[^:]" out
125 test_expect_success 'check --cc --raw with forty trees' '
126 git diff --cc --raw $trees $base_tree >out &&
127 # Check for forty leading colons in the output:
128 grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
131 test_expect_success 'setup combined ignore spaces' '
132 git checkout main &&
133 >test &&
134 git add test &&
135 git commit -m initial &&
137 tr -d Q <<-\EOF >test &&
138 always coalesce
139 eol space coalesce Q
140 space change coalesce
141 all spa ces coalesce
142 eol spaces Q
143 space change
144 all spa ces
146 git commit -m "test space change" -a &&
148 git checkout -b side HEAD^ &&
149 tr -d Q <<-\EOF >test &&
150 always coalesce
151 eol space coalesce
152 space change coalesce
153 all spaces coalesce
154 eol spaces
155 space change
156 all spaces
158 git commit -m "test other space changes" -a &&
160 test_must_fail git merge main &&
161 tr -d Q <<-\EOF >test &&
162 eol spaces Q
163 space change
164 all spa ces
166 git commit -m merged -a
169 test_expect_success 'check combined output (no ignore space)' '
170 git show >actual.tmp &&
171 sed -e "1,/^@@@/d" < actual.tmp >actual &&
172 tr -d Q <<-\EOF >expected &&
173 --always coalesce
174 - eol space coalesce
175 - space change coalesce
176 - all spaces coalesce
177 - eol spaces
178 - space change
179 - all spaces
180 -eol space coalesce Q
181 -space change coalesce
182 -all spa ces coalesce
183 + eol spaces Q
184 + space change
185 + all spa ces
187 compare_diff_patch expected actual
190 test_expect_success 'check combined output (ignore space at eol)' '
191 git show --ignore-space-at-eol >actual.tmp &&
192 sed -e "1,/^@@@/d" < actual.tmp >actual &&
193 tr -d Q <<-\EOF >expected &&
194 --always coalesce
195 --eol space coalesce
196 - space change coalesce
197 - all spaces coalesce
198 -space change coalesce
199 -all spa ces coalesce
200 eol spaces Q
201 - space change
202 - all spaces
203 + space change
204 + all spa ces
206 compare_diff_patch expected actual
209 test_expect_success 'check combined output (ignore space change)' '
210 git show -b >actual.tmp &&
211 sed -e "1,/^@@@/d" < actual.tmp >actual &&
212 tr -d Q <<-\EOF >expected &&
213 --always coalesce
214 --eol space coalesce
215 --space change coalesce
216 - all spaces coalesce
217 -all spa ces coalesce
218 eol spaces Q
219 space change
220 - all spaces
221 + all spa ces
223 compare_diff_patch expected actual
226 test_expect_success 'check combined output (ignore all spaces)' '
227 git show -w >actual.tmp &&
228 sed -e "1,/^@@@/d" < actual.tmp >actual &&
229 tr -d Q <<-\EOF >expected &&
230 --always coalesce
231 --eol space coalesce
232 --space change coalesce
233 --all spaces coalesce
234 eol spaces Q
235 space change
236 all spa ces
238 compare_diff_patch expected actual
241 test_expect_success 'combine diff coalesce simple' '
242 >test &&
243 git add test &&
244 git commit -m initial &&
245 test_seq 4 >test &&
246 git commit -a -m empty1 &&
247 git branch side1 &&
248 git checkout HEAD^ &&
249 test_seq 5 >test &&
250 git commit -a -m empty2 &&
251 test_must_fail git merge side1 &&
252 >test &&
253 git commit -a -m merge &&
254 git show >actual.tmp &&
255 sed -e "1,/^@@@/d" < actual.tmp >actual &&
256 tr -d Q <<-\EOF >expected &&
263 compare_diff_patch expected actual
266 test_expect_success 'combine diff coalesce tricky' '
267 >test &&
268 git add test &&
269 git commit -m initial --allow-empty &&
270 cat <<-\EOF >test &&
277 git commit -a -m empty1 &&
278 git branch -f side1 &&
279 git checkout HEAD^ &&
280 cat <<-\EOF >test &&
286 git commit -a -m empty2 &&
287 git branch -f side2 &&
288 test_must_fail git merge side1 &&
289 >test &&
290 git commit -a -m merge &&
291 git show >actual.tmp &&
292 sed -e "1,/^@@@/d" < actual.tmp >actual &&
293 tr -d Q <<-\EOF >expected &&
301 compare_diff_patch expected actual &&
302 git checkout -f side1 &&
303 test_must_fail git merge side2 &&
304 >test &&
305 git commit -a -m merge &&
306 git show >actual.tmp &&
307 sed -e "1,/^@@@/d" < actual.tmp >actual &&
308 tr -d Q <<-\EOF >expected &&
316 compare_diff_patch expected actual
319 test_expect_failure 'combine diff coalesce three parents' '
320 >test &&
321 git add test &&
322 git commit -m initial --allow-empty &&
323 cat <<-\EOF >test &&
330 git commit -a -m empty1 &&
331 git checkout -B side1 &&
332 git checkout HEAD^ &&
333 cat <<-\EOF >test &&
340 git commit -a -m empty2 &&
341 git branch -f side2 &&
342 git checkout HEAD^ &&
343 cat <<-\EOF >test &&
350 git commit -a -m empty3 &&
351 >test &&
352 git add test &&
353 TREE=$(git write-tree) &&
354 COMMIT=$(git commit-tree -p HEAD -p side1 -p side2 -m merge $TREE) &&
355 git show $COMMIT >actual.tmp &&
356 sed -e "1,/^@@@/d" < actual.tmp >actual &&
357 tr -d Q <<-\EOF >expected &&
358 -- 3
359 ---1
364 - -5
365 ---4
367 compare_diff_patch expected actual
370 # Test for a bug reported at
371 # https://lore.kernel.org/git/20130515143508.GO25742@login.drsnuggles.stderr.nl/
372 # where a delete lines were missing from combined diff output when they
373 # occurred exactly before the context lines of a later change.
374 test_expect_success 'combine diff missing delete bug' '
375 git commit -m initial --allow-empty &&
376 cat <<-\EOF >test &&
382 git add test &&
383 git commit -a -m side1 &&
384 git checkout -B side1 &&
385 git checkout HEAD^ &&
386 cat <<-\EOF >test &&
391 4modified
393 git add test &&
394 git commit -m side2 &&
395 git branch -f side2 &&
396 test_must_fail git merge --no-commit side1 &&
397 cat <<-\EOF >test &&
401 4modified
403 git add test &&
404 git commit -a -m merge &&
405 git diff-tree -c -p HEAD >actual.tmp &&
406 sed -e "1,/^@@@/d" < actual.tmp >actual &&
407 tr -d Q <<-\EOF >expected &&
413 +4modified
415 compare_diff_patch expected actual
418 test_expect_success 'combine diff gets tree sorting right' '
419 # create a directory and a file that sort differently in trees
420 # versus byte-wise (implied "/" sorts after ".")
421 git checkout -f main &&
422 mkdir foo &&
423 echo base >foo/one &&
424 echo base >foo/two &&
425 echo base >foo.ext &&
426 git add foo foo.ext &&
427 git commit -m base &&
429 # one side modifies a file in the directory, along with the root
430 # file...
431 echo main >foo/one &&
432 echo main >foo.ext &&
433 git commit -a -m main &&
435 # the other side modifies the other file in the directory
436 git checkout -b other HEAD^ &&
437 echo other >foo/two &&
438 git commit -a -m other &&
440 # And now we merge. The files in the subdirectory will resolve cleanly,
441 # meaning that a combined diff will not find them interesting. But it
442 # will find the tree itself interesting, because it had to be merged.
443 git checkout main &&
444 git merge other &&
446 printf "MM\tfoo\n" >expect &&
447 git diff-tree -c --name-status -t HEAD >actual.tmp &&
448 sed 1d <actual.tmp >actual &&
449 test_cmp expect actual
452 test_expect_success 'setup for --combined-all-paths' '
453 git branch side1c &&
454 git branch side2c &&
455 git checkout side1c &&
456 test_seq 1 10 >filename-side1c &&
457 side1cf=$(git hash-object filename-side1c) &&
458 git add filename-side1c &&
459 git commit -m with &&
460 git checkout side2c &&
461 test_seq 1 9 >filename-side2c &&
462 echo ten >>filename-side2c &&
463 side2cf=$(git hash-object filename-side2c) &&
464 git add filename-side2c &&
465 git commit -m iam &&
466 git checkout -b mergery side1c &&
467 git merge --no-commit side2c &&
468 git rm filename-side1c &&
469 echo eleven >>filename-side2c &&
470 git mv filename-side2c filename-merged &&
471 mergedf=$(git hash-object filename-merged) &&
472 git add filename-merged &&
473 git commit
476 test_expect_success '--combined-all-paths and --raw' '
477 cat <<-EOF >expect &&
478 ::100644 100644 100644 $side1cf $side2cf $mergedf RR filename-side1c filename-side2c filename-merged
480 git diff-tree -c -M --raw --combined-all-paths HEAD >actual.tmp &&
481 sed 1d <actual.tmp >actual &&
482 test_cmp expect actual
485 test_expect_success '--combined-all-paths and --cc' '
486 cat <<-\EOF >expect &&
487 --- a/filename-side1c
488 --- a/filename-side2c
489 +++ b/filename-merged
491 git diff-tree --cc -M --combined-all-paths HEAD >actual.tmp &&
492 grep ^[-+][-+][-+] <actual.tmp >actual &&
493 test_cmp expect actual
496 test_expect_success FUNNYNAMES 'setup for --combined-all-paths with funny names' '
497 git branch side1d &&
498 git branch side2d &&
499 git checkout side1d &&
500 test_seq 1 10 >"$(printf "file\twith\ttabs")" &&
501 git add file* &&
502 side1df=$(git hash-object *tabs) &&
503 git commit -m with &&
504 git checkout side2d &&
505 test_seq 1 9 >"$(printf "i\tam\ttabbed")" &&
506 echo ten >>"$(printf "i\tam\ttabbed")" &&
507 git add *tabbed &&
508 side2df=$(git hash-object *tabbed) &&
509 git commit -m iam &&
510 git checkout -b funny-names-mergery side1d &&
511 git merge --no-commit side2d &&
512 git rm *tabs &&
513 echo eleven >>"$(printf "i\tam\ttabbed")" &&
514 git mv "$(printf "i\tam\ttabbed")" "$(printf "fickle\tnaming")" &&
515 git add fickle* &&
516 headf=$(git hash-object fickle*) &&
517 git commit &&
518 head=$(git rev-parse HEAD)
521 test_expect_success FUNNYNAMES '--combined-all-paths and --raw and funny names' '
522 cat <<-EOF >expect &&
523 ::100644 100644 100644 $side1df $side2df $headf RR "file\twith\ttabs" "i\tam\ttabbed" "fickle\tnaming"
525 git diff-tree -c -M --raw --combined-all-paths HEAD >actual.tmp &&
526 sed 1d <actual.tmp >actual &&
527 test_cmp expect actual
530 test_expect_success FUNNYNAMES '--combined-all-paths and --raw -and -z and funny names' '
531 printf "$head\0::100644 100644 100644 $side1df $side2df $headf RR\0file\twith\ttabs\0i\tam\ttabbed\0fickle\tnaming\0" >expect &&
532 git diff-tree -c -M --raw --combined-all-paths -z HEAD >actual &&
533 test_cmp expect actual
536 test_expect_success FUNNYNAMES '--combined-all-paths and --cc and funny names' '
537 cat <<-\EOF >expect &&
538 --- "a/file\twith\ttabs"
539 --- "a/i\tam\ttabbed"
540 +++ "b/fickle\tnaming"
542 git diff-tree --cc -M --combined-all-paths HEAD >actual.tmp &&
543 grep ^[-+][-+][-+] <actual.tmp >actual &&
544 test_cmp expect actual
547 test_done