117117git diff -b > out
118118test_expect_success ' another test, with -b' ' git diff expect out'
119119
120-
121120test_expect_success ' check mixed spaces and tabs in indent' '
122121
123122 # This is indented with SP HT SP.
@@ -126,4 +125,140 @@ test_expect_success 'check mixed spaces and tabs in indent' '
126125
127126'
128127
128+ test_expect_success ' check with no whitespace errors' '
129+
130+ git commit -m "snapshot" &&
131+ echo "foo();" > x &&
132+ git diff --check
133+
134+ '
135+
136+ test_expect_failure ' check with trailing whitespace' '
137+
138+ echo "foo(); " > x &&
139+ git diff --check
140+
141+ '
142+
143+ test_expect_failure ' check with space before tab in indent' '
144+
145+ # indent has space followed by hard tab
146+ echo " foo();" > x &&
147+ git diff --check
148+
149+ '
150+
151+ test_expect_failure ' --check and --exit-code are exclusive' '
152+
153+ git checkout x &&
154+ git diff --check --exit-code
155+
156+ '
157+
158+ test_expect_failure ' --check and --quiet are exclusive' '
159+
160+ git diff --check --quiet
161+
162+ '
163+
164+ test_expect_success ' check staged with no whitespace errors' '
165+
166+ echo "foo();" > x &&
167+ git add x &&
168+ git diff --cached --check
169+
170+ '
171+
172+ test_expect_failure ' check staged with trailing whitespace' '
173+
174+ echo "foo(); " > x &&
175+ git add x &&
176+ git diff --cached --check
177+
178+ '
179+
180+ test_expect_failure ' check staged with space before tab in indent' '
181+
182+ # indent has space followed by hard tab
183+ echo " foo();" > x &&
184+ git add x &&
185+ git diff --cached --check
186+
187+ '
188+
189+ test_expect_success ' check with no whitespace errors (diff-index)' '
190+
191+ echo "foo();" > x &&
192+ git add x &&
193+ git diff-index --check HEAD
194+
195+ '
196+
197+ test_expect_failure ' check with trailing whitespace (diff-index)' '
198+
199+ echo "foo(); " > x &&
200+ git add x &&
201+ git diff-index --check HEAD
202+
203+ '
204+
205+ test_expect_failure ' check with space before tab in indent (diff-index)' '
206+
207+ # indent has space followed by hard tab
208+ echo " foo();" > x &&
209+ git add x &&
210+ git diff-index --check HEAD
211+
212+ '
213+
214+ test_expect_success ' check staged with no whitespace errors (diff-index)' '
215+
216+ echo "foo();" > x &&
217+ git add x &&
218+ git diff-index --cached --check HEAD
219+
220+ '
221+
222+ test_expect_failure ' check staged with trailing whitespace (diff-index)' '
223+
224+ echo "foo(); " > x &&
225+ git add x &&
226+ git diff-index --cached --check HEAD
227+
228+ '
229+
230+ test_expect_failure ' check staged with space before tab in indent (diff-index)' '
231+
232+ # indent has space followed by hard tab
233+ echo " foo();" > x &&
234+ git add x &&
235+ git diff-index --cached --check HEAD
236+
237+ '
238+
239+ test_expect_success ' check with no whitespace errors (diff-tree)' '
240+
241+ echo "foo();" > x &&
242+ git commit -m "new commit" x &&
243+ git diff-tree --check HEAD^ HEAD
244+
245+ '
246+
247+ test_expect_failure ' check with trailing whitespace (diff-tree)' '
248+
249+ echo "foo(); " > x &&
250+ git commit -m "another commit" x &&
251+ git diff-tree --check HEAD^ HEAD
252+
253+ '
254+
255+ test_expect_failure ' check with space before tab in indent (diff-tree)' '
256+
257+ # indent has space followed by hard tab
258+ echo " foo();" > x &&
259+ git commit -m "yet another" x &&
260+ git diff-tree --check HEAD^ HEAD
261+
262+ '
263+
129264test_done
0 commit comments