3 test_description
='diff whitespace error detection'
7 test_expect_success setup
'
9 git config diff.color.whitespace "blue reverse" &&
12 echo " Eight SP indent" >>F &&
13 echo " HT and SP indent" >>F &&
14 echo "With trailing SP " >>F &&
15 echo "Carriage ReturnQ" | tr Q "\015" >>F &&
16 echo "No problem" >>F &&
21 blue_grep
='7;34m' ;# ESC [ 7 ; 3 4 m
23 printf "\033[%s" "$blue_grep" >check-grep
24 if (grep "$blue_grep" <check-grep |
grep "$blue_grep") >/dev
/null
2>&1
27 elif (grep -a "$blue_grep" <check-grep |
grep -a "$blue_grep") >/dev
/null
2>&1
31 grep_a
=grep ;# expected to fail...
36 git
diff --color >output
37 $grep_a "$blue_grep" output
>error
38 $grep_a -v "$blue_grep" output
>normal
41 test_expect_success default
'
45 grep Eight normal >/dev/null &&
46 grep HT error >/dev/null &&
47 grep With error >/dev/null &&
48 grep Return error >/dev/null &&
49 grep No normal >/dev/null
53 test_expect_success
'without -trail' '
55 git config core.whitespace -trail
58 grep Eight normal >/dev/null &&
59 grep HT error >/dev/null &&
60 grep With normal >/dev/null &&
61 grep Return normal >/dev/null &&
62 grep No normal >/dev/null
66 test_expect_success
'without -trail (attribute)' '
68 git config --unset core.whitespace
69 echo "F whitespace=-trail" >.gitattributes
72 grep Eight normal >/dev/null &&
73 grep HT error >/dev/null &&
74 grep With normal >/dev/null &&
75 grep Return normal >/dev/null &&
76 grep No normal >/dev/null
80 test_expect_success
'without -space' '
83 git config core.whitespace -space
86 grep Eight normal >/dev/null &&
87 grep HT normal >/dev/null &&
88 grep With error >/dev/null &&
89 grep Return error >/dev/null &&
90 grep No normal >/dev/null
94 test_expect_success
'without -space (attribute)' '
96 git config --unset core.whitespace
97 echo "F whitespace=-space" >.gitattributes
100 grep Eight normal >/dev/null &&
101 grep HT normal >/dev/null &&
102 grep With error >/dev/null &&
103 grep Return error >/dev/null &&
104 grep No normal >/dev/null
108 test_expect_success
'with indent-non-tab only' '
111 git config core.whitespace indent,-trailing,-space
114 grep Eight error >/dev/null &&
115 grep HT normal >/dev/null &&
116 grep With normal >/dev/null &&
117 grep Return normal >/dev/null &&
118 grep No normal >/dev/null
122 test_expect_success
'with indent-non-tab only (attribute)' '
124 git config --unset core.whitespace
125 echo "F whitespace=indent,-trailing,-space" >.gitattributes
128 grep Eight error >/dev/null &&
129 grep HT normal >/dev/null &&
130 grep With normal >/dev/null &&
131 grep Return normal >/dev/null &&
132 grep No normal >/dev/null
136 test_expect_success
'with cr-at-eol' '
139 git config core.whitespace cr-at-eol
142 grep Eight normal >/dev/null &&
143 grep HT error >/dev/null &&
144 grep With error >/dev/null &&
145 grep Return normal >/dev/null &&
146 grep No normal >/dev/null
150 test_expect_success
'with cr-at-eol (attribute)' '
152 git config --unset core.whitespace
153 echo "F whitespace=trailing,cr-at-eol" >.gitattributes
156 grep Eight normal >/dev/null &&
157 grep HT error >/dev/null &&
158 grep With error >/dev/null &&
159 grep Return normal >/dev/null &&
160 grep No normal >/dev/null
164 test_expect_success
'trailing empty lines (1)' '
166 rm -f .gitattributes &&
167 test_must_fail git diff --check >output &&
168 grep "new blank line at" output &&
169 grep "trailing whitespace" output
173 test_expect_success
'trailing empty lines (2)' '
175 echo "F -whitespace" >.gitattributes &&
176 git diff --check >output &&
181 test_expect_success
'do not color trailing cr in context' '
182 git config --unset core.whitespace
183 rm -f .gitattributes &&
184 echo AAAQ | tr Q "\015" >G &&
186 echo BBBQ | tr Q "\015" >>G
187 git diff --color G | tr "\015" Q >output &&
188 grep "BBB.*${blue_grep}Q" output &&
189 grep "AAA.*\[mQ" output
193 test_expect_success
'color new trailing blank lines' '
194 { echo a; echo b; echo; echo; } >x &&
196 { echo a; echo; echo; echo; echo c; echo; echo; echo; echo; } >x &&
197 git diff --color x >output &&
198 cnt=$($grep_a "${blue_grep}" output | wc -l) &&