4343 '
4444done
4545
46+ test_expect_success " incomplete line in both pre- and post-image context" '
47+ (echo foo && echo baz | tr -d "\012") >x &&
48+ git add x &&
49+ (echo bar && echo baz | tr -d "\012") >x &&
50+ git diff x &&
51+ git -c core.whitespace=incomplete diff --check x &&
52+ git diff -R x &&
53+ git -c core.whitespace=incomplete diff -R --check x
54+ '
55+
56+ test_expect_success " incomplete lines on both pre- and post-image" '
57+ # The interpretation taken here is "since you are touching
58+ # the line anyway, you would better fix the incomplete line
59+ # while you are at it." but this is debatable.
60+ echo foo | tr -d "\012" >x &&
61+ git add x &&
62+ echo bar | tr -d "\012" >x &&
63+ git diff x &&
64+ test_must_fail git -c core.whitespace=incomplete diff --check x >error &&
65+ test_grep "no newline at the end of file" error &&
66+ git diff -R x &&
67+ test_must_fail git -c core.whitespace=incomplete diff -R --check x >error &&
68+ test_grep "no newline at the end of file" error
69+ '
70+
71+ test_expect_success " fix incomplete line in pre-image" '
72+ echo foo | tr -d "\012" >x &&
73+ git add x &&
74+ echo bar >x &&
75+ git diff x &&
76+ git -c core.whitespace=incomplete diff --check x &&
77+ git diff -R x &&
78+ test_must_fail git -c core.whitespace=incomplete diff -R --check x >error &&
79+ test_grep "no newline at the end of file" error
80+ '
81+
82+ test_expect_success " new incomplete line in post-image" '
83+ echo foo >x &&
84+ git add x &&
85+ echo bar | tr -d "\012" >x &&
86+ git diff x &&
87+ test_must_fail git -c core.whitespace=incomplete diff --check x >error &&
88+ test_grep "no newline at the end of file" error &&
89+ git diff -R x &&
90+ git -c core.whitespace=incomplete diff -R --check x
91+ '
92+
4693test_expect_success " Ray Lehtiniemi's example" '
4794 cat <<-\EOF >x &&
4895 do {
@@ -1040,7 +1087,8 @@ test_expect_success 'ws-error-highlight test setup' '
10401087 {
10411088 echo "0. blank-at-eol " &&
10421089 echo "1. still-blank-at-eol " &&
1043- echo "2. and a new line "
1090+ echo "2. and a new line " &&
1091+ printf "3. and more"
10441092 } >x &&
10451093 new_hash_x=$(git hash-object x) &&
10461094 after=$(git rev-parse --short "$new_hash_x") &&
@@ -1050,40 +1098,47 @@ test_expect_success 'ws-error-highlight test setup' '
10501098 <BOLD>index $before..$after 100644<RESET>
10511099 <BOLD>--- a/x<RESET>
10521100 <BOLD>+++ b/x<RESET>
1053- <CYAN>@@ -1,2 +1,3 @@<RESET>
1101+ <CYAN>@@ -1,2 +1,4 @@<RESET>
10541102 0. blank-at-eol <RESET>
10551103 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
10561104 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
10571105 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
1106+ <GREEN>+<RESET><GREEN>3. and more<RESET>
1107+ <BLUE>\ No newline at end of file<RESET>
10581108 EOF
10591109
10601110 cat >expect.all <<-EOF &&
10611111 <BOLD>diff --git a/x b/x<RESET>
10621112 <BOLD>index $before..$after 100644<RESET>
10631113 <BOLD>--- a/x<RESET>
10641114 <BOLD>+++ b/x<RESET>
1065- <CYAN>@@ -1,2 +1,3 @@<RESET>
1115+ <CYAN>@@ -1,2 +1,4 @@<RESET>
10661116 <RESET>0. blank-at-eol<RESET><BLUE> <RESET>
10671117 <RED>-<RESET><RED>1. blank-at-eol<RESET><BLUE> <RESET>
10681118 <GREEN>+<RESET><GREEN>1. still-blank-at-eol<RESET><BLUE> <RESET>
10691119 <GREEN>+<RESET><GREEN>2. and a new line<RESET><BLUE> <RESET>
1120+ <GREEN>+<RESET><GREEN>3. and more<RESET>
1121+ <BLUE>\ No newline at end of file<RESET>
10701122 EOF
10711123
10721124 cat >expect.none <<-EOF
10731125 <BOLD>diff --git a/x b/x<RESET>
10741126 <BOLD>index $before..$after 100644<RESET>
10751127 <BOLD>--- a/x<RESET>
10761128 <BOLD>+++ b/x<RESET>
1077- <CYAN>@@ -1,2 +1,3 @@<RESET>
1129+ <CYAN>@@ -1,2 +1,4 @@<RESET>
10781130 0. blank-at-eol <RESET>
10791131 <RED>-1. blank-at-eol <RESET>
10801132 <GREEN>+1. still-blank-at-eol <RESET>
10811133 <GREEN>+2. and a new line <RESET>
1134+ <GREEN>+3. and more<RESET>
1135+ \ No newline at end of file<RESET>
10821136 EOF
10831137
10841138'
10851139
10861140test_expect_success ' test --ws-error-highlight option' '
1141+ git config core.whitespace blank-at-eol,incomplete-line &&
10871142
10881143 git diff --color --ws-error-highlight=default,old >current.raw &&
10891144 test_decode_color <current.raw >current &&
@@ -1100,6 +1155,7 @@ test_expect_success 'test --ws-error-highlight option' '
11001155'
11011156
11021157test_expect_success ' test diff.wsErrorHighlight config' '
1158+ git config core.whitespace blank-at-eol,incomplete-line &&
11031159
11041160 git -c diff.wsErrorHighlight=default,old diff --color >current.raw &&
11051161 test_decode_color <current.raw >current &&
@@ -1116,6 +1172,7 @@ test_expect_success 'test diff.wsErrorHighlight config' '
11161172'
11171173
11181174test_expect_success ' option overrides diff.wsErrorHighlight' '
1175+ git config core.whitespace blank-at-eol,incomplete-line &&
11191176
11201177 git -c diff.wsErrorHighlight=none \
11211178 diff --color --ws-error-highlight=default,old >current.raw &&
@@ -1135,6 +1192,8 @@ test_expect_success 'option overrides diff.wsErrorHighlight' '
11351192'
11361193
11371194test_expect_success ' detect moved code, complete file' '
1195+ git config core.whitespace blank-at-eol &&
1196+
11381197 git reset --hard &&
11391198 cat <<-\EOF >test.c &&
11401199 #include<stdio.h>
0 commit comments