3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description='Test special whitespace in diff engine.
10 . "$TEST_DIRECTORY"/diff-lib.sh
12 # Ray Lehtiniemi's example
20 git update-index --add x
32 index adf3937..6edc172 100644
46 test_expect_success "Ray's example without options" 'test_cmp expect out'
49 test_expect_success "Ray's example with -w" 'test_cmp expect out'
52 test_expect_success "Ray's example with -b" 'test_cmp expect out'
54 tr 'Q' '\015' << EOF > x
55 whitespace at beginning
57 whitespace in the middle
66 whitespace at beginning
68 white space in the middle
74 tr 'Q_' '\015 ' << EOF > expect
76 index d99af23..8b32fb5 100644
80 -whitespace at beginning
82 -whitespace in the middle
84 + whitespace at beginning
86 +white space in the middle
93 test_expect_success 'another test, without options' 'test_cmp expect out'
97 index d99af23..8b32fb5 100644
100 test_expect_success 'another test, with -w' 'test_cmp expect out'
102 test_expect_success 'another test, with -w -b' 'test_cmp expect out'
103 git diff -w --ignore-space-at-eol > out
104 test_expect_success 'another test, with -w --ignore-space-at-eol' 'test_cmp expect out'
105 git diff -w -b --ignore-space-at-eol > out
106 test_expect_success 'another test, with -w -b --ignore-space-at-eol' 'test_cmp expect out'
108 tr 'Q' '\015' << EOF > expect
110 index d99af23..8b32fb5 100644
114 -whitespace at beginning
115 + whitespace at beginning
117 -whitespace in the middle
118 +white space in the middle
124 test_expect_success 'another test, with -b' 'test_cmp expect out'
125 git diff -b --ignore-space-at-eol > out
126 test_expect_success 'another test, with -b --ignore-space-at-eol' 'test_cmp expect out'
128 tr 'Q' '\015' << EOF > expect
130 index d99af23..8b32fb5 100644
134 -whitespace at beginning
136 -whitespace in the middle
137 + whitespace at beginning
139 +white space in the middle
144 git diff --ignore-space-at-eol > out
145 test_expect_success 'another test, with --ignore-space-at-eol' 'test_cmp expect out'
147 test_expect_success 'check mixed spaces and tabs in indent' '
149 # This is indented with SP HT SP.
150 echo " foo();" > x &&
151 git diff --check | grep "space before tab in indent"
155 test_expect_success 'check mixed tabs and spaces in indent' '
157 # This is indented with HT SP HT.
158 echo " foo();" > x &&
159 git diff --check | grep "space before tab in indent"
163 test_expect_success 'check with no whitespace errors' '
165 git commit -m "snapshot" &&
171 test_expect_success 'check with trailing whitespace' '
173 echo "foo(); " > x &&
174 test_must_fail git diff --check
178 test_expect_success 'check with space before tab in indent' '
180 # indent has space followed by hard tab
181 echo " foo();" > x &&
182 test_must_fail git diff --check
186 test_expect_success '--check and --exit-code are not exclusive' '
189 git diff --check --exit-code
193 test_expect_success '--check and --quiet are not exclusive' '
195 git diff --check --quiet
199 test_expect_success 'check staged with no whitespace errors' '
203 git diff --cached --check
207 test_expect_success 'check staged with trailing whitespace' '
209 echo "foo(); " > x &&
211 test_must_fail git diff --cached --check
215 test_expect_success 'check staged with space before tab in indent' '
217 # indent has space followed by hard tab
218 echo " foo();" > x &&
220 test_must_fail git diff --cached --check
224 test_expect_success 'check with no whitespace errors (diff-index)' '
228 git diff-index --check HEAD
232 test_expect_success 'check with trailing whitespace (diff-index)' '
234 echo "foo(); " > x &&
236 test_must_fail git diff-index --check HEAD
240 test_expect_success 'check with space before tab in indent (diff-index)' '
242 # indent has space followed by hard tab
243 echo " foo();" > x &&
245 test_must_fail git diff-index --check HEAD
249 test_expect_success 'check staged with no whitespace errors (diff-index)' '
253 git diff-index --cached --check HEAD
257 test_expect_success 'check staged with trailing whitespace (diff-index)' '
259 echo "foo(); " > x &&
261 test_must_fail git diff-index --cached --check HEAD
265 test_expect_success 'check staged with space before tab in indent (diff-index)' '
267 # indent has space followed by hard tab
268 echo " foo();" > x &&
270 test_must_fail git diff-index --cached --check HEAD
274 test_expect_success 'check with no whitespace errors (diff-tree)' '
277 git commit -m "new commit" x &&
278 git diff-tree --check HEAD^ HEAD
282 test_expect_success 'check with trailing whitespace (diff-tree)' '
284 echo "foo(); " > x &&
285 git commit -m "another commit" x &&
286 test_must_fail git diff-tree --check HEAD^ HEAD
290 test_expect_success 'check with space before tab in indent (diff-tree)' '
292 # indent has space followed by hard tab
293 echo " foo();" > x &&
294 git commit -m "yet another" x &&
295 test_must_fail git diff-tree --check HEAD^ HEAD
299 test_expect_success 'check trailing whitespace (trailing-space: off)' '
301 git config core.whitespace "-trailing-space" &&
302 echo "foo (); " > x &&
307 test_expect_success 'check trailing whitespace (trailing-space: on)' '
309 git config core.whitespace "trailing-space" &&
310 echo "foo (); " > x &&
311 test_must_fail git diff --check
315 test_expect_success 'check space before tab in indent (space-before-tab: off)' '
317 # indent contains space followed by HT
318 git config core.whitespace "-space-before-tab" &&
319 echo " foo ();" > x &&
324 test_expect_success 'check space before tab in indent (space-before-tab: on)' '
326 # indent contains space followed by HT
327 git config core.whitespace "space-before-tab" &&
328 echo " foo (); " > x &&
329 test_must_fail git diff --check
333 test_expect_success 'check spaces as indentation (indent-with-non-tab: off)' '
335 git config core.whitespace "-indent-with-non-tab"
336 echo " foo ();" > x &&
341 test_expect_success 'check spaces as indentation (indent-with-non-tab: on)' '
343 git config core.whitespace "indent-with-non-tab" &&
344 echo " foo ();" > x &&
345 test_must_fail git diff --check
349 test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab: on)' '
351 git config core.whitespace "indent-with-non-tab" &&
352 echo " foo ();" > x &&
353 test_must_fail git diff --check
357 test_expect_success 'line numbers in --check output are correct' '
360 echo "foo(); " >> x &&
361 git diff --check | grep "x:2:"
365 test_expect_success 'checkdiff detects new trailing blank lines (1)' '
368 git diff --check | grep "new blank line"
371 test_expect_success 'checkdiff detects new trailing blank lines (2)' '
372 { echo a; echo b; echo; echo; } >x &&
374 { echo a; echo; echo; echo; echo; } >x &&
375 git diff --check | grep "new blank line"
378 test_expect_success 'checkdiff allows new blank lines' '
382 echo "/* This is new */" &&
389 test_expect_success 'combined diff with autocrlf conversion' '
393 git commit -m "one side" x &&
394 git checkout HEAD^ &&
396 git commit -m "the other side" x &&
397 git config core.autocrlf true &&
398 test_must_fail git merge master &&
400 git diff | sed -e "1,/^@@@/d" >actual &&