3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description='Test special whitespace in diff engine.
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" 'git diff expect out'
49 test_expect_success "Ray's example with -w" 'git diff expect out'
52 test_expect_success "Ray's example with -b" 'git diff 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' 'git diff expect out'
97 index d99af23..8b32fb5 100644
100 test_expect_success 'another test, with -w' 'git diff expect out'
102 tr 'Q' '\015' << EOF > expect
104 index d99af23..8b32fb5 100644
108 -whitespace at beginning
109 + whitespace at beginning
111 -whitespace in the middle
112 +white space in the middle
118 test_expect_success 'another test, with -b' 'git diff expect out'
120 test_expect_success 'check mixed spaces and tabs in indent' '
122 # This is indented with SP HT SP.
123 echo " foo();" > x &&
124 git diff --check | grep "Space in indent is followed by a tab"
128 test_expect_success 'check with no whitespace errors' '
130 git commit -m "snapshot" &&
136 test_expect_failure 'check with trailing whitespace' '
138 echo "foo(); " > x &&
143 test_expect_failure 'check with space before tab in indent' '
145 # indent has space followed by hard tab
146 echo " foo();" > x &&
151 test_expect_success '--check and --exit-code are not exclusive' '
154 git diff --check --exit-code
158 test_expect_success '--check and --quiet are not exclusive' '
160 git diff --check --quiet
164 test_expect_success 'check staged with no whitespace errors' '
168 git diff --cached --check
172 test_expect_failure 'check staged with trailing whitespace' '
174 echo "foo(); " > x &&
176 git diff --cached --check
180 test_expect_failure 'check staged with space before tab in indent' '
182 # indent has space followed by hard tab
183 echo " foo();" > x &&
185 git diff --cached --check
189 test_expect_success 'check with no whitespace errors (diff-index)' '
193 git diff-index --check HEAD
197 test_expect_failure 'check with trailing whitespace (diff-index)' '
199 echo "foo(); " > x &&
201 git diff-index --check HEAD
205 test_expect_failure 'check with space before tab in indent (diff-index)' '
207 # indent has space followed by hard tab
208 echo " foo();" > x &&
210 git diff-index --check HEAD
214 test_expect_success 'check staged with no whitespace errors (diff-index)' '
218 git diff-index --cached --check HEAD
222 test_expect_failure 'check staged with trailing whitespace (diff-index)' '
224 echo "foo(); " > x &&
226 git diff-index --cached --check HEAD
230 test_expect_failure 'check staged with space before tab in indent (diff-index)' '
232 # indent has space followed by hard tab
233 echo " foo();" > x &&
235 git diff-index --cached --check HEAD
239 test_expect_success 'check with no whitespace errors (diff-tree)' '
242 git commit -m "new commit" x &&
243 git diff-tree --check HEAD^ HEAD
247 test_expect_failure 'check with trailing whitespace (diff-tree)' '
249 echo "foo(); " > x &&
250 git commit -m "another commit" x &&
251 git diff-tree --check HEAD^ HEAD
255 test_expect_failure 'check with space before tab in indent (diff-tree)' '
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