builtin-commit: add --date option
[git/vmiklos.git] / t / t4019-diff-wserror.sh
blob3a3663fbcb4795a9e3755fe831c89a7e312f659e
1 #!/bin/sh
3 test_description='diff whitespace error detection'
5 . ./test-lib.sh
7 test_expect_success setup '
9 git config diff.color.whitespace "blue reverse" &&
10 >F &&
11 git add F &&
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 &&
17 echo >>F
21 blue_grep='7;34m' ;# ESC [ 7 ; 3 4 m
23 test_expect_success default '
25 git diff --color >output
26 grep "$blue_grep" output >error
27 grep -v "$blue_grep" output >normal
29 grep Eight normal >/dev/null &&
30 grep HT error >/dev/null &&
31 grep With error >/dev/null &&
32 grep Return error >/dev/null &&
33 grep No normal >/dev/null
37 test_expect_success 'without -trail' '
39 git config core.whitespace -trail
40 git diff --color >output
41 grep "$blue_grep" output >error
42 grep -v "$blue_grep" output >normal
44 grep Eight normal >/dev/null &&
45 grep HT error >/dev/null &&
46 grep With normal >/dev/null &&
47 grep Return normal >/dev/null &&
48 grep No normal >/dev/null
52 test_expect_success 'without -trail (attribute)' '
54 git config --unset core.whitespace
55 echo "F whitespace=-trail" >.gitattributes
56 git diff --color >output
57 grep "$blue_grep" output >error
58 grep -v "$blue_grep" output >normal
60 grep Eight normal >/dev/null &&
61 grep HT error >/dev/null &&
62 grep With normal >/dev/null &&
63 grep Return normal >/dev/null &&
64 grep No normal >/dev/null
68 test_expect_success 'without -space' '
70 rm -f .gitattributes
71 git config core.whitespace -space
72 git diff --color >output
73 grep "$blue_grep" output >error
74 grep -v "$blue_grep" output >normal
76 grep Eight normal >/dev/null &&
77 grep HT normal >/dev/null &&
78 grep With error >/dev/null &&
79 grep Return error >/dev/null &&
80 grep No normal >/dev/null
84 test_expect_success 'without -space (attribute)' '
86 git config --unset core.whitespace
87 echo "F whitespace=-space" >.gitattributes
88 git diff --color >output
89 grep "$blue_grep" output >error
90 grep -v "$blue_grep" output >normal
92 grep Eight normal >/dev/null &&
93 grep HT normal >/dev/null &&
94 grep With error >/dev/null &&
95 grep Return error >/dev/null &&
96 grep No normal >/dev/null
100 test_expect_success 'with indent-non-tab only' '
102 rm -f .gitattributes
103 git config core.whitespace indent,-trailing,-space
104 git diff --color >output
105 grep "$blue_grep" output >error
106 grep -v "$blue_grep" output >normal
108 grep Eight error >/dev/null &&
109 grep HT normal >/dev/null &&
110 grep With normal >/dev/null &&
111 grep Return normal >/dev/null &&
112 grep No normal >/dev/null
116 test_expect_success 'with indent-non-tab only (attribute)' '
118 git config --unset core.whitespace
119 echo "F whitespace=indent,-trailing,-space" >.gitattributes
120 git diff --color >output
121 grep "$blue_grep" output >error
122 grep -v "$blue_grep" output >normal
124 grep Eight error >/dev/null &&
125 grep HT normal >/dev/null &&
126 grep With normal >/dev/null &&
127 grep Return normal >/dev/null &&
128 grep No normal >/dev/null
132 test_expect_success 'with cr-at-eol' '
134 rm -f .gitattributes
135 git config core.whitespace cr-at-eol
136 git diff --color >output
137 grep "$blue_grep" output >error
138 grep -v "$blue_grep" output >normal
140 grep Eight normal >/dev/null &&
141 grep HT error >/dev/null &&
142 grep With error >/dev/null &&
143 grep Return normal >/dev/null &&
144 grep No normal >/dev/null
148 test_expect_success 'with cr-at-eol (attribute)' '
150 git config --unset core.whitespace
151 echo "F whitespace=trailing,cr-at-eol" >.gitattributes
152 git diff --color >output
153 grep "$blue_grep" output >error
154 grep -v "$blue_grep" output >normal
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 &&
177 ! test -s 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 &&
185 git add 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 &&
195 git add x &&
196 { echo a; echo; echo; echo; echo c; echo; echo; echo; echo; } >x &&
197 git diff --color x >output &&
198 cnt=$(grep "${blue_grep}" output | wc -l) &&
199 test $cnt = 2
202 test_done