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