]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4015-diff-whitespace.sh
diff-tree: read the index so attribute checks work in bare repositories
[thirdparty/git.git] / t / t4015-diff-whitespace.sh
CommitLineData
2344d47f
JS
1#!/bin/sh
2#
3# Copyright (c) 2006 Johannes E. Schindelin
4#
5
6test_description='Test special whitespace in diff engine.
7
8'
9. ./test-lib.sh
bfdbee98 10. "$TEST_DIRECTORY"/diff-lib.sh
2344d47f 11
d55ef3e0
JH
12test_expect_success "Ray Lehtiniemi's example" '
13 cat <<-\EOF >x &&
14 do {
15 nothing;
16 } while (0);
17 EOF
18 git update-index --add x &&
2344d47f 19
d55ef3e0
JH
20 cat <<-\EOF >x &&
21 do
22 {
23 nothing;
24 }
25 while (0);
26 EOF
2344d47f 27
d55ef3e0
JH
28 cat <<-\EOF >expect &&
29 diff --git a/x b/x
30 index adf3937..6edc172 100644
31 --- a/x
32 +++ b/x
33 @@ -1,3 +1,5 @@
34 -do {
35 +do
36 +{
37 nothing;
38 -} while (0);
39 +}
40 +while (0);
41 EOF
2344d47f 42
d55ef3e0
JH
43 git diff >out &&
44 test_cmp expect out &&
2344d47f 45
d55ef3e0
JH
46 git diff -w >out &&
47 test_cmp expect out &&
2344d47f 48
d55ef3e0
JH
49 git diff -b >out &&
50 test_cmp expect out
51'
2344d47f 52
d55ef3e0
JH
53test_expect_success 'another test, without options' '
54 tr Q "\015" <<-\EOF >x &&
55 whitespace at beginning
56 whitespace change
57 whitespace in the middle
58 whitespace at end
59 unchanged line
60 CR at endQ
61 EOF
2344d47f 62
d55ef3e0 63 git update-index x &&
2344d47f 64
d55ef3e0
JH
65 tr "_" " " <<-\EOF >x &&
66 _ whitespace at beginning
67 whitespace change
68 white space in the middle
69 whitespace at end__
70 unchanged line
71 CR at end
72 EOF
2344d47f 73
d55ef3e0
JH
74 tr "Q_" "\015 " <<-\EOF >expect &&
75 diff --git a/x b/x
76 index d99af23..22d9f73 100644
77 --- a/x
78 +++ b/x
79 @@ -1,6 +1,6 @@
80 -whitespace at beginning
81 -whitespace change
82 -whitespace in the middle
83 -whitespace at end
84 + whitespace at beginning
85 +whitespace change
86 +white space in the middle
87 +whitespace at end__
88 unchanged line
89 -CR at endQ
90 +CR at end
91 EOF
2344d47f 92
d55ef3e0
JH
93 git diff >out &&
94 test_cmp expect out &&
2344d47f 95
d55ef3e0
JH
96 >expect &&
97 git diff -w >out &&
98 test_cmp expect out &&
99
100 git diff -w -b >out &&
101 test_cmp expect out &&
102
103 git diff -w --ignore-space-at-eol >out &&
104 test_cmp expect out &&
105
106 git diff -w -b --ignore-space-at-eol >out &&
107 test_cmp expect out &&
2344d47f 108
d55ef3e0
JH
109
110 tr "Q_" "\015 " <<-\EOF >expect &&
111 diff --git a/x b/x
112 index d99af23..22d9f73 100644
113 --- a/x
114 +++ b/x
115 @@ -1,6 +1,6 @@
116 -whitespace at beginning
117 +_ whitespace at beginning
118 whitespace change
119 -whitespace in the middle
120 +white space in the middle
121 whitespace at end__
122 unchanged line
123 CR at end
124 EOF
125 git diff -b >out &&
126 test_cmp expect out &&
127
128 git diff -b --ignore-space-at-eol >out &&
129 test_cmp expect out &&
130
131 tr "Q_" "\015 " <<-\EOF >expect &&
132 diff --git a/x b/x
133 index d99af23..22d9f73 100644
134 --- a/x
135 +++ b/x
136 @@ -1,6 +1,6 @@
137 -whitespace at beginning
138 -whitespace change
139 -whitespace in the middle
140 +_ whitespace at beginning
141 +whitespace change
142 +white space in the middle
143 whitespace at end__
144 unchanged line
145 CR at end
146 EOF
147 git diff --ignore-space-at-eol >out &&
148 test_cmp expect out
149'
2344d47f 150
36617af7
AP
151test_expect_success 'ignore-blank-lines: only new lines' '
152 test_seq 5 >x &&
153 git update-index x &&
90a95301 154 test_seq 5 | sed "/3/i\\
36617af7
AP
155" >x &&
156 git diff --ignore-blank-lines >out &&
157 >expect &&
158 test_cmp out expect
159'
160
161test_expect_success 'ignore-blank-lines: only new lines with space' '
162 test_seq 5 >x &&
163 git update-index x &&
90a95301
BW
164 test_seq 5 | sed "/3/i\\
165 " >x &&
36617af7
AP
166 git diff -w --ignore-blank-lines >out &&
167 >expect &&
168 test_cmp out expect
169'
170
171test_expect_success 'ignore-blank-lines: after change' '
172 cat <<-\EOF >x &&
173 1
174 2
175
176 3
177 4
178 5
179
180 6
181 7
182 EOF
183 git update-index x &&
184 cat <<-\EOF >x &&
185 change
186
187 1
188 2
189 3
190 4
191 5
192 6
193
194 7
195 EOF
196 git diff --inter-hunk-context=100 --ignore-blank-lines >out.tmp &&
197 cat <<-\EOF >expected &&
198 diff --git a/x b/x
199 --- a/x
200 +++ b/x
201 @@ -1,6 +1,7 @@
202 +change
203 +
204 1
205 2
206 -
207 3
208 4
209 5
210 EOF
211 compare_diff_patch expected out.tmp
212'
213
214test_expect_success 'ignore-blank-lines: before change' '
215 cat <<-\EOF >x &&
216 1
217 2
218
219 3
220 4
221 5
222 6
223 7
224 EOF
225 git update-index x &&
226 cat <<-\EOF >x &&
227
228 1
229 2
230 3
231 4
232 5
233
234 6
235 7
236 change
237 EOF
238 git diff --inter-hunk-context=100 --ignore-blank-lines >out.tmp &&
239 cat <<-\EOF >expected &&
240 diff --git a/x b/x
241 --- a/x
242 +++ b/x
243 @@ -4,5 +4,7 @@
244 3
245 4
246 5
247 +
248 6
249 7
250 +change
251 EOF
252 compare_diff_patch expected out.tmp
253'
254
255test_expect_success 'ignore-blank-lines: between changes' '
256 cat <<-\EOF >x &&
257 1
258 2
259 3
260 4
261 5
262
263
264 6
265 7
266 8
267 9
268 10
269 EOF
270 git update-index x &&
271 cat <<-\EOF >x &&
272 change
273 1
274 2
275
276 3
277 4
278 5
279 6
280 7
281 8
282
283 9
284 10
285 change
286 EOF
287 git diff --ignore-blank-lines >out.tmp &&
288 cat <<-\EOF >expected &&
289 diff --git a/x b/x
290 --- a/x
291 +++ b/x
292 @@ -1,5 +1,7 @@
293 +change
294 1
295 2
296 +
297 3
298 4
299 5
300 @@ -8,5 +8,7 @@
301 6
302 7
303 8
304 +
305 9
306 10
307 +change
308 EOF
309 compare_diff_patch expected out.tmp
310'
311
312test_expect_success 'ignore-blank-lines: between changes (with interhunkctx)' '
313 test_seq 10 >x &&
314 git update-index x &&
315 cat <<-\EOF >x &&
316 change
317 1
318 2
319
320 3
321 4
322 5
323
324 6
325 7
326 8
327 9
328
329 10
330 change
331 EOF
332 git diff --inter-hunk-context=2 --ignore-blank-lines >out.tmp &&
333 cat <<-\EOF >expected &&
334 diff --git a/x b/x
335 --- a/x
336 +++ b/x
337 @@ -1,10 +1,15 @@
338 +change
339 1
340 2
341 +
342 3
343 4
344 5
345 +
346 6
347 7
348 8
349 9
350 +
351 10
352 +change
353 EOF
354 compare_diff_patch expected out.tmp
355'
356
357test_expect_success 'ignore-blank-lines: scattered spaces' '
358 test_seq 10 >x &&
359 git update-index x &&
360 cat <<-\EOF >x &&
361 change
362 1
363 2
364 3
365
366 4
367
368 5
369
370 6
371
372
373 7
374
375 8
376 9
377 10
378 change
379 EOF
380 git diff --inter-hunk-context=4 --ignore-blank-lines >out.tmp &&
381 cat <<-\EOF >expected &&
382 diff --git a/x b/x
383 --- a/x
384 +++ b/x
385 @@ -1,3 +1,4 @@
386 +change
387 1
388 2
389 3
390 @@ -8,3 +15,4 @@
391 8
392 9
393 10
394 +change
395 EOF
396 compare_diff_patch expected out.tmp
397'
398
399test_expect_success 'ignore-blank-lines: spaces coalesce' '
400 test_seq 6 >x &&
401 git update-index x &&
402 cat <<-\EOF >x &&
403 change
404 1
405 2
406 3
407
408 4
409
410 5
411
412 6
413 change
414 EOF
415 git diff --inter-hunk-context=4 --ignore-blank-lines >out.tmp &&
416 cat <<-\EOF >expected &&
417 diff --git a/x b/x
418 --- a/x
419 +++ b/x
420 @@ -1,6 +1,11 @@
421 +change
422 1
423 2
424 3
425 +
426 4
427 +
428 5
429 +
430 6
431 +change
432 EOF
433 compare_diff_patch expected out.tmp
434'
435
436test_expect_success 'ignore-blank-lines: mix changes and blank lines' '
437 test_seq 16 >x &&
438 git update-index x &&
439 cat <<-\EOF >x &&
440 change
441 1
442 2
443
444 3
445 4
446 5
447 change
448 6
449 7
450 8
451
452 9
453 10
454 11
455 change
456 12
457 13
458 14
459
460 15
461 16
462 change
463 EOF
464 git diff --ignore-blank-lines >out.tmp &&
465 cat <<-\EOF >expected &&
466 diff --git a/x b/x
467 --- a/x
468 +++ b/x
469 @@ -1,8 +1,11 @@
470 +change
471 1
472 2
473 +
474 3
475 4
476 5
477 +change
478 6
479 7
480 8
481 @@ -9,8 +13,11 @@
482 9
483 10
484 11
485 +change
486 12
487 13
488 14
489 +
490 15
491 16
492 +change
493 EOF
494 compare_diff_patch expected out.tmp
495'
496
86f8c236 497test_expect_success 'check mixed spaces and tabs in indent' '
86f8c236 498 # This is indented with SP HT SP.
d55ef3e0 499 echo " foo();" >x &&
420f4f04 500 git diff --check | grep "space before tab in indent"
86f8c236
WC
501'
502
9afa2d4a 503test_expect_success 'check mixed tabs and spaces in indent' '
9afa2d4a 504 # This is indented with HT SP HT.
d55ef3e0 505 echo " foo();" >x &&
9afa2d4a 506 git diff --check | grep "space before tab in indent"
9afa2d4a
BF
507'
508
62c64895 509test_expect_success 'check with no whitespace errors' '
62c64895 510 git commit -m "snapshot" &&
d55ef3e0 511 echo "foo();" >x &&
62c64895 512 git diff --check
62c64895
WC
513'
514
f8175466 515test_expect_success 'check with trailing whitespace' '
d55ef3e0 516 echo "foo(); " >x &&
d492b31c 517 test_must_fail git diff --check
62c64895
WC
518'
519
f8175466 520test_expect_success 'check with space before tab in indent' '
62c64895 521 # indent has space followed by hard tab
d55ef3e0 522 echo " foo();" >x &&
d492b31c 523 test_must_fail git diff --check
62c64895
WC
524'
525
da31b358 526test_expect_success '--check and --exit-code are not exclusive' '
62c64895
WC
527 git checkout x &&
528 git diff --check --exit-code
62c64895
WC
529'
530
da31b358 531test_expect_success '--check and --quiet are not exclusive' '
62c64895 532 git diff --check --quiet
62c64895
WC
533'
534
535test_expect_success 'check staged with no whitespace errors' '
d55ef3e0 536 echo "foo();" >x &&
62c64895
WC
537 git add x &&
538 git diff --cached --check
62c64895
WC
539'
540
f8175466 541test_expect_success 'check staged with trailing whitespace' '
d55ef3e0 542 echo "foo(); " >x &&
62c64895 543 git add x &&
d492b31c 544 test_must_fail git diff --cached --check
62c64895
WC
545'
546
f8175466 547test_expect_success 'check staged with space before tab in indent' '
62c64895 548 # indent has space followed by hard tab
d55ef3e0 549 echo " foo();" >x &&
62c64895 550 git add x &&
d492b31c 551 test_must_fail git diff --cached --check
62c64895
WC
552'
553
554test_expect_success 'check with no whitespace errors (diff-index)' '
d55ef3e0 555 echo "foo();" >x &&
62c64895
WC
556 git add x &&
557 git diff-index --check HEAD
62c64895
WC
558'
559
f8175466 560test_expect_success 'check with trailing whitespace (diff-index)' '
d55ef3e0 561 echo "foo(); " >x &&
62c64895 562 git add x &&
d492b31c 563 test_must_fail git diff-index --check HEAD
62c64895
WC
564'
565
f8175466 566test_expect_success 'check with space before tab in indent (diff-index)' '
62c64895 567 # indent has space followed by hard tab
d55ef3e0 568 echo " foo();" >x &&
62c64895 569 git add x &&
d492b31c 570 test_must_fail git diff-index --check HEAD
62c64895
WC
571'
572
573test_expect_success 'check staged with no whitespace errors (diff-index)' '
d55ef3e0 574 echo "foo();" >x &&
62c64895
WC
575 git add x &&
576 git diff-index --cached --check HEAD
62c64895
WC
577'
578
f8175466 579test_expect_success 'check staged with trailing whitespace (diff-index)' '
d55ef3e0 580 echo "foo(); " >x &&
62c64895 581 git add x &&
d492b31c 582 test_must_fail git diff-index --cached --check HEAD
62c64895
WC
583'
584
f8175466 585test_expect_success 'check staged with space before tab in indent (diff-index)' '
62c64895 586 # indent has space followed by hard tab
d55ef3e0 587 echo " foo();" >x &&
62c64895 588 git add x &&
d492b31c 589 test_must_fail git diff-index --cached --check HEAD
62c64895
WC
590'
591
592test_expect_success 'check with no whitespace errors (diff-tree)' '
d55ef3e0 593 echo "foo();" >x &&
62c64895
WC
594 git commit -m "new commit" x &&
595 git diff-tree --check HEAD^ HEAD
62c64895
WC
596'
597
f8175466 598test_expect_success 'check with trailing whitespace (diff-tree)' '
d55ef3e0 599 echo "foo(); " >x &&
62c64895 600 git commit -m "another commit" x &&
d492b31c 601 test_must_fail git diff-tree --check HEAD^ HEAD
62c64895
WC
602'
603
f8175466 604test_expect_success 'check with space before tab in indent (diff-tree)' '
62c64895 605 # indent has space followed by hard tab
d55ef3e0 606 echo " foo();" >x &&
62c64895 607 git commit -m "yet another" x &&
d492b31c 608 test_must_fail git diff-tree --check HEAD^ HEAD
f8175466
JH
609'
610
fd66bcc3
BW
611test_expect_success 'check with ignored trailing whitespace attr (diff-tree)' '
612 test_when_finished "git reset --hard HEAD^" &&
613
614 # create a whitespace error that should be ignored
615 echo "* -whitespace" >.gitattributes &&
616 git add .gitattributes &&
617 echo "foo(); " >x &&
618 git add x &&
619 git commit -m "add trailing space" &&
620
621 # with a worktree diff-tree ignores the whitespace error
622 git diff-tree --root --check HEAD &&
623
624 # without a worktree diff-tree still ignores the whitespace error
625 git -C .git diff-tree --root --check HEAD
626'
627
f8175466 628test_expect_success 'check trailing whitespace (trailing-space: off)' '
f8175466 629 git config core.whitespace "-trailing-space" &&
d55ef3e0 630 echo "foo (); " >x &&
f8175466 631 git diff --check
f8175466
JH
632'
633
634test_expect_success 'check trailing whitespace (trailing-space: on)' '
f8175466 635 git config core.whitespace "trailing-space" &&
d55ef3e0 636 echo "foo (); " >x &&
d492b31c 637 test_must_fail git diff --check
f8175466
JH
638'
639
640test_expect_success 'check space before tab in indent (space-before-tab: off)' '
f8175466
JH
641 # indent contains space followed by HT
642 git config core.whitespace "-space-before-tab" &&
d55ef3e0 643 echo " foo ();" >x &&
f8175466 644 git diff --check
f8175466
JH
645'
646
647test_expect_success 'check space before tab in indent (space-before-tab: on)' '
f8175466
JH
648 # indent contains space followed by HT
649 git config core.whitespace "space-before-tab" &&
d55ef3e0 650 echo " foo (); " >x &&
d492b31c 651 test_must_fail git diff --check
f8175466
JH
652'
653
654test_expect_success 'check spaces as indentation (indent-with-non-tab: off)' '
a48fcd83 655 git config core.whitespace "-indent-with-non-tab" &&
d55ef3e0 656 echo " foo ();" >x &&
f8175466 657 git diff --check
f8175466
JH
658'
659
660test_expect_success 'check spaces as indentation (indent-with-non-tab: on)' '
f8175466 661 git config core.whitespace "indent-with-non-tab" &&
d55ef3e0 662 echo " foo ();" >x &&
d492b31c 663 test_must_fail git diff --check
62c64895
WC
664'
665
f4b05a49 666test_expect_success 'ditto, but tabwidth=9' '
f4b05a49
JS
667 git config core.whitespace "indent-with-non-tab,tabwidth=9" &&
668 git diff --check
f4b05a49
JS
669'
670
9afa2d4a 671test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab: on)' '
9afa2d4a 672 git config core.whitespace "indent-with-non-tab" &&
d55ef3e0 673 echo " foo ();" >x &&
d492b31c 674 test_must_fail git diff --check
9afa2d4a 675'
0ef617f4 676
f4b05a49 677test_expect_success 'ditto, but tabwidth=10' '
f4b05a49
JS
678 git config core.whitespace "indent-with-non-tab,tabwidth=10" &&
679 test_must_fail git diff --check
f4b05a49
JS
680'
681
682test_expect_success 'ditto, but tabwidth=20' '
f4b05a49
JS
683 git config core.whitespace "indent-with-non-tab,tabwidth=20" &&
684 git diff --check
f4b05a49
JS
685'
686
b27eb499 687test_expect_success 'check tabs as indentation (tab-in-indent: off)' '
b27eb499 688 git config core.whitespace "-tab-in-indent" &&
d55ef3e0 689 echo " foo ();" >x &&
b27eb499 690 git diff --check
b27eb499
CW
691'
692
693test_expect_success 'check tabs as indentation (tab-in-indent: on)' '
b27eb499 694 git config core.whitespace "tab-in-indent" &&
d55ef3e0 695 echo " foo ();" >x &&
b27eb499 696 test_must_fail git diff --check
b27eb499
CW
697'
698
699test_expect_success 'check tabs and spaces as indentation (tab-in-indent: on)' '
b27eb499 700 git config core.whitespace "tab-in-indent" &&
d55ef3e0 701 echo " foo ();" >x &&
b27eb499 702 test_must_fail git diff --check
b27eb499
CW
703'
704
f4b05a49 705test_expect_success 'ditto, but tabwidth=1 (must be irrelevant)' '
f4b05a49
JS
706 git config core.whitespace "tab-in-indent,tabwidth=1" &&
707 test_must_fail git diff --check
f4b05a49
JS
708'
709
b27eb499 710test_expect_success 'check tab-in-indent and indent-with-non-tab conflict' '
b27eb499 711 git config core.whitespace "tab-in-indent,indent-with-non-tab" &&
d55ef3e0 712 echo "foo ();" >x &&
b27eb499 713 test_must_fail git diff --check
b27eb499
CW
714'
715
716test_expect_success 'check tab-in-indent excluded from wildcard whitespace attribute' '
b27eb499 717 git config --unset core.whitespace &&
d55ef3e0
JH
718 echo "x whitespace" >.gitattributes &&
719 echo " foo ();" >x &&
b27eb499
CW
720 git diff --check &&
721 rm -f .gitattributes
b27eb499
CW
722'
723
0ef617f4 724test_expect_success 'line numbers in --check output are correct' '
d55ef3e0
JH
725 echo "" >x &&
726 echo "foo(); " >>x &&
0ef617f4 727 git diff --check | grep "x:2:"
0ef617f4
JH
728'
729
5b5061ef 730test_expect_success 'checkdiff detects new trailing blank lines (1)' '
877f23cc
JH
731 echo "foo();" >x &&
732 echo "" >>x &&
5b5061ef 733 git diff --check | grep "new blank line"
877f23cc
JH
734'
735
467babf8
JH
736test_expect_success 'checkdiff detects new trailing blank lines (2)' '
737 { echo a; echo b; echo; echo; } >x &&
738 git add x &&
739 { echo a; echo; echo; echo; echo; } >x &&
740 git diff --check | grep "new blank line"
877f23cc
JH
741'
742
c35539eb
JH
743test_expect_success 'checkdiff allows new blank lines' '
744 git checkout x &&
745 mv x y &&
746 (
747 echo "/* This is new */" &&
748 echo "" &&
749 cat y
750 ) >x &&
751 git diff --check
752'
753
3e97c7c6
GB
754cat <<EOF >expect
755EOF
756test_expect_success 'whitespace-only changes not reported' '
757 git reset --hard &&
758 echo >x "hello world" &&
759 git add x &&
760 git commit -m "hello 1" &&
761 echo >x "hello world" &&
762 git diff -b >actual &&
763 test_cmp expect actual
764'
765
296c6bb2
CC
766cat <<EOF >expect
767diff --git a/x b/z
768similarity index NUM%
769rename from x
770rename to z
771index 380c32a..a97b785 100644
772EOF
773test_expect_success 'whitespace-only changes reported across renames' '
774 git reset --hard &&
775 for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
776 git add x &&
777 git commit -m "base" &&
778 sed -e "5s/^/ /" x >z &&
779 git rm x &&
780 git add z &&
781 git diff -w -M --cached |
782 sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual &&
783 test_cmp expect actual
784'
785
786cat >expected <<\EOF
787diff --git a/empty b/void
788similarity index 100%
789rename from empty
790rename to void
791EOF
792
793test_expect_success 'rename empty' '
794 git reset --hard &&
795 >empty &&
796 git add empty &&
797 git commit -m empty &&
798 git mv empty void &&
799 git diff -w --cached -M >current &&
800 test_cmp expected current
801'
802
5e568f9e
AG
803test_expect_success 'combined diff with autocrlf conversion' '
804
805 git reset --hard &&
806 echo >x hello &&
807 git commit -m "one side" x &&
808 git checkout HEAD^ &&
809 echo >x goodbye &&
810 git commit -m "the other side" x &&
811 git config core.autocrlf true &&
812 test_must_fail git merge master &&
813
814 git diff | sed -e "1,/^@@@/d" >actual &&
815 ! grep "^-" actual
816
817'
818
cfd1a984
KB
819# Start testing the colored format for whitespace checks
820
821test_expect_success 'setup diff colors' '
822 git config color.diff always &&
823 git config color.diff.plain normal &&
824 git config color.diff.meta bold &&
825 git config color.diff.frag cyan &&
826 git config color.diff.func normal &&
827 git config color.diff.old red &&
828 git config color.diff.new green &&
829 git config color.diff.commit yellow &&
0ad782f2 830 git config color.diff.whitespace blue &&
cfd1a984 831
0ad782f2
JH
832 git config core.autocrlf false
833'
834
835test_expect_success 'diff that introduces a line with only tabs' '
836 git config core.whitespace blank-at-eol &&
837 git reset --hard &&
838 echo "test" >x &&
839 git commit -m "initial" x &&
840 echo "{NTN}" | tr "NT" "\n\t" >>x &&
841 git -c color.diff=always diff | test_decode_color >current &&
d55ef3e0 842
0ad782f2 843 cat >expected <<-\EOF &&
d55ef3e0
JH
844 <BOLD>diff --git a/x b/x<RESET>
845 <BOLD>index 9daeafb..2874b91 100644<RESET>
846 <BOLD>--- a/x<RESET>
847 <BOLD>+++ b/x<RESET>
848 <CYAN>@@ -1 +1,4 @@<RESET>
849 test<RESET>
850 <GREEN>+<RESET><GREEN>{<RESET>
0ad782f2 851 <GREEN>+<RESET><BLUE> <RESET>
d55ef3e0
JH
852 <GREEN>+<RESET><GREEN>}<RESET>
853 EOF
cfd1a984 854
cfd1a984
KB
855 test_cmp expected current
856'
857
b8767f79
JH
858test_expect_success 'diff that introduces and removes ws breakages' '
859 git reset --hard &&
860 {
861 echo "0. blank-at-eol " &&
862 echo "1. blank-at-eol "
863 } >x &&
864 git commit -a --allow-empty -m preimage &&
865 {
866 echo "0. blank-at-eol " &&
867 echo "1. still-blank-at-eol " &&
868 echo "2. and a new line "
869 } >x &&
870
871 git -c color.diff=always diff |
872 test_decode_color >current &&
873
874 cat >expected <<-\EOF &&
875 <BOLD>diff --git a/x b/x<RESET>
876 <BOLD>index d0233a2..700886e 100644<RESET>
877 <BOLD>--- a/x<RESET>
878 <BOLD>+++ b/x<RESET>
879 <CYAN>@@ -1,2 +1,3 @@<RESET>
880 0. blank-at-eol <RESET>
881 <RED>-1. blank-at-eol <RESET>
882 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
883 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
884 EOF
885
886 test_cmp expected current
887'
888
f3f5c7f5
JH
889test_expect_success 'ws-error-highlight test setup' '
890
b8767f79
JH
891 git reset --hard &&
892 {
893 echo "0. blank-at-eol " &&
894 echo "1. blank-at-eol "
895 } >x &&
896 git commit -a --allow-empty -m preimage &&
897 {
898 echo "0. blank-at-eol " &&
899 echo "1. still-blank-at-eol " &&
900 echo "2. and a new line "
901 } >x &&
902
f3f5c7f5 903 cat >expect.default-old <<-\EOF &&
b8767f79
JH
904 <BOLD>diff --git a/x b/x<RESET>
905 <BOLD>index d0233a2..700886e 100644<RESET>
906 <BOLD>--- a/x<RESET>
907 <BOLD>+++ b/x<RESET>
908 <CYAN>@@ -1,2 +1,3 @@<RESET>
909 0. blank-at-eol <RESET>
910 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
911 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
912 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
913 EOF
914
f3f5c7f5 915 cat >expect.all <<-\EOF &&
b8767f79
JH
916 <BOLD>diff --git a/x b/x<RESET>
917 <BOLD>index d0233a2..700886e 100644<RESET>
918 <BOLD>--- a/x<RESET>
919 <BOLD>+++ b/x<RESET>
920 <CYAN>@@ -1,2 +1,3 @@<RESET>
921 <RESET>0. blank-at-eol<RESET><BLUE> <RESET>
922 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
923 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
924 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
925 EOF
926
f3f5c7f5 927 cat >expect.none <<-\EOF
b8767f79
JH
928 <BOLD>diff --git a/x b/x<RESET>
929 <BOLD>index d0233a2..700886e 100644<RESET>
930 <BOLD>--- a/x<RESET>
931 <BOLD>+++ b/x<RESET>
932 <CYAN>@@ -1,2 +1,3 @@<RESET>
933 0. blank-at-eol <RESET>
934 <RED>-1. blank-at-eol <RESET>
935 <GREEN>+1. still-blank-at-eol <RESET>
936 <GREEN>+2. and a new line <RESET>
937 EOF
938
f3f5c7f5
JH
939'
940
941test_expect_success 'test --ws-error-highlight option' '
942
943 git -c color.diff=always diff --ws-error-highlight=default,old |
944 test_decode_color >current &&
945 test_cmp expect.default-old current &&
946
947 git -c color.diff=always diff --ws-error-highlight=all |
948 test_decode_color >current &&
949 test_cmp expect.all current &&
950
951 git -c color.diff=always diff --ws-error-highlight=none |
952 test_decode_color >current &&
953 test_cmp expect.none current
954
b8767f79
JH
955'
956
a17505f2
JH
957test_expect_success 'test diff.wsErrorHighlight config' '
958
959 git -c color.diff=always -c diff.wsErrorHighlight=default,old diff |
960 test_decode_color >current &&
961 test_cmp expect.default-old current &&
962
963 git -c color.diff=always -c diff.wsErrorHighlight=all diff |
964 test_decode_color >current &&
965 test_cmp expect.all current &&
966
967 git -c color.diff=always -c diff.wsErrorHighlight=none diff |
968 test_decode_color >current &&
969 test_cmp expect.none current
970
971'
972
973test_expect_success 'option overrides diff.wsErrorHighlight' '
974
975 git -c color.diff=always -c diff.wsErrorHighlight=none \
976 diff --ws-error-highlight=default,old |
977 test_decode_color >current &&
978 test_cmp expect.default-old current &&
979
980 git -c color.diff=always -c diff.wsErrorHighlight=default \
981 diff --ws-error-highlight=all |
982 test_decode_color >current &&
983 test_cmp expect.all current &&
984
985 git -c color.diff=always -c diff.wsErrorHighlight=all \
986 diff --ws-error-highlight=none |
987 test_decode_color >current &&
988 test_cmp expect.none current
989
990'
991
2344d47f 992test_done