Revert "make git-status use a pager"
[git/spearce.git] / t / t0020-crlf.sh
blob1be7446d8d9f8a46b463f2474a8c25bdd33044d2
1 #!/bin/sh
3 test_description='CRLF conversion'
5 . ./test-lib.sh
7 q_to_nul () {
8 perl -pe 'y/Q/\000/'
11 q_to_cr () {
12 tr Q '\015'
15 append_cr () {
16 sed -e 's/$/Q/' | tr Q '\015'
19 remove_cr () {
20 tr '\015' Q <"$1" | grep Q >/dev/null &&
21 tr '\015' Q <"$1" | sed -ne 's/Q$//p'
24 test_expect_success setup '
26 git config core.autocrlf false &&
28 for w in Hello world how are you; do echo $w; done >one &&
29 mkdir dir &&
30 for w in I am very very fine thank you; do echo $w; done >dir/two &&
31 for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three &&
32 git add . &&
34 git commit -m initial &&
36 one=`git rev-parse HEAD:one` &&
37 dir=`git rev-parse HEAD:dir` &&
38 two=`git rev-parse HEAD:dir/two` &&
39 three=`git rev-parse HEAD:three` &&
41 for w in Some extra lines here; do echo $w; done >>one &&
42 git diff >patch.file &&
43 patched=`git hash-object --stdin <one` &&
44 git read-tree --reset -u HEAD &&
46 echo happy.
49 test_expect_success 'safecrlf: autocrlf=input, all CRLF' '
51 git config core.autocrlf input &&
52 git config core.safecrlf true &&
54 for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
55 test_must_fail git add allcrlf
58 test_expect_success 'safecrlf: autocrlf=input, mixed LF/CRLF' '
60 git config core.autocrlf input &&
61 git config core.safecrlf true &&
63 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
64 test_must_fail git add mixed
67 test_expect_success 'safecrlf: autocrlf=true, all LF' '
69 git config core.autocrlf true &&
70 git config core.safecrlf true &&
72 for w in I am all LF; do echo $w; done >alllf &&
73 test_must_fail git add alllf
76 test_expect_success 'safecrlf: autocrlf=true mixed LF/CRLF' '
78 git config core.autocrlf true &&
79 git config core.safecrlf true &&
81 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
82 test_must_fail git add mixed
85 test_expect_success 'safecrlf: print warning only once' '
87 git config core.autocrlf input &&
88 git config core.safecrlf warn &&
90 for w in I am all LF; do echo $w; done >doublewarn &&
91 git add doublewarn &&
92 git commit -m "nowarn" &&
93 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >doublewarn &&
94 test $(git add doublewarn 2>&1 | grep "CRLF will be replaced by LF" | wc -l) = 1
97 test_expect_success 'switch off autocrlf, safecrlf, reset HEAD' '
98 git config core.autocrlf false &&
99 git config core.safecrlf false &&
100 git reset --hard HEAD^
103 test_expect_success 'update with autocrlf=input' '
105 rm -f tmp one dir/two three &&
106 git read-tree --reset -u HEAD &&
107 git config core.autocrlf input &&
109 for f in one dir/two
111 append_cr <$f >tmp && mv -f tmp $f &&
112 git update-index -- $f || {
113 echo Oops
114 false
115 break
117 done &&
119 differs=`git diff-index --cached HEAD` &&
120 test -z "$differs" || {
121 echo Oops "$differs"
122 false
127 test_expect_success 'update with autocrlf=true' '
129 rm -f tmp one dir/two three &&
130 git read-tree --reset -u HEAD &&
131 git config core.autocrlf true &&
133 for f in one dir/two
135 append_cr <$f >tmp && mv -f tmp $f &&
136 git update-index -- $f || {
137 echo "Oops $f"
138 false
139 break
141 done &&
143 differs=`git diff-index --cached HEAD` &&
144 test -z "$differs" || {
145 echo Oops "$differs"
146 false
151 test_expect_success 'checkout with autocrlf=true' '
153 rm -f tmp one dir/two three &&
154 git config core.autocrlf true &&
155 git read-tree --reset -u HEAD &&
157 for f in one dir/two
159 remove_cr "$f" >tmp && mv -f tmp $f &&
160 git update-index -- $f || {
161 echo "Eh? $f"
162 false
163 break
165 done &&
166 test "$one" = `git hash-object --stdin <one` &&
167 test "$two" = `git hash-object --stdin <dir/two` &&
168 differs=`git diff-index --cached HEAD` &&
169 test -z "$differs" || {
170 echo Oops "$differs"
171 false
175 test_expect_success 'checkout with autocrlf=input' '
177 rm -f tmp one dir/two three &&
178 git config core.autocrlf input &&
179 git read-tree --reset -u HEAD &&
181 for f in one dir/two
183 if remove_cr "$f" >/dev/null
184 then
185 echo "Eh? $f"
186 false
187 break
188 else
189 git update-index -- $f
191 done &&
192 test "$one" = `git hash-object --stdin <one` &&
193 test "$two" = `git hash-object --stdin <dir/two` &&
194 differs=`git diff-index --cached HEAD` &&
195 test -z "$differs" || {
196 echo Oops "$differs"
197 false
201 test_expect_success 'apply patch (autocrlf=input)' '
203 rm -f tmp one dir/two three &&
204 git config core.autocrlf input &&
205 git read-tree --reset -u HEAD &&
207 git apply patch.file &&
208 test "$patched" = "`git hash-object --stdin <one`" || {
209 echo "Eh? apply without index"
210 false
214 test_expect_success 'apply patch --cached (autocrlf=input)' '
216 rm -f tmp one dir/two three &&
217 git config core.autocrlf input &&
218 git read-tree --reset -u HEAD &&
220 git apply --cached patch.file &&
221 test "$patched" = `git rev-parse :one` || {
222 echo "Eh? apply with --cached"
223 false
227 test_expect_success 'apply patch --index (autocrlf=input)' '
229 rm -f tmp one dir/two three &&
230 git config core.autocrlf input &&
231 git read-tree --reset -u HEAD &&
233 git apply --index patch.file &&
234 test "$patched" = `git rev-parse :one` &&
235 test "$patched" = `git hash-object --stdin <one` || {
236 echo "Eh? apply with --index"
237 false
241 test_expect_success 'apply patch (autocrlf=true)' '
243 rm -f tmp one dir/two three &&
244 git config core.autocrlf true &&
245 git read-tree --reset -u HEAD &&
247 git apply patch.file &&
248 test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
249 echo "Eh? apply without index"
250 false
254 test_expect_success 'apply patch --cached (autocrlf=true)' '
256 rm -f tmp one dir/two three &&
257 git config core.autocrlf true &&
258 git read-tree --reset -u HEAD &&
260 git apply --cached patch.file &&
261 test "$patched" = `git rev-parse :one` || {
262 echo "Eh? apply without index"
263 false
267 test_expect_success 'apply patch --index (autocrlf=true)' '
269 rm -f tmp one dir/two three &&
270 git config core.autocrlf true &&
271 git read-tree --reset -u HEAD &&
273 git apply --index patch.file &&
274 test "$patched" = `git rev-parse :one` &&
275 test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
276 echo "Eh? apply with --index"
277 false
281 test_expect_success '.gitattributes says two is binary' '
283 rm -f tmp one dir/two three &&
284 echo "two -crlf" >.gitattributes &&
285 git config core.autocrlf true &&
286 git read-tree --reset -u HEAD &&
288 if remove_cr dir/two >/dev/null
289 then
290 echo "Huh?"
291 false
292 else
293 : happy
294 fi &&
296 if remove_cr one >/dev/null
297 then
298 : happy
299 else
300 echo "Huh?"
301 false
302 fi &&
304 if remove_cr three >/dev/null
305 then
306 echo "Huh?"
307 false
308 else
309 : happy
313 test_expect_success '.gitattributes says two is input' '
315 rm -f tmp one dir/two three &&
316 echo "two crlf=input" >.gitattributes &&
317 git read-tree --reset -u HEAD &&
319 if remove_cr dir/two >/dev/null
320 then
321 echo "Huh?"
322 false
323 else
324 : happy
328 test_expect_success '.gitattributes says two and three are text' '
330 rm -f tmp one dir/two three &&
331 echo "t* crlf" >.gitattributes &&
332 git read-tree --reset -u HEAD &&
334 if remove_cr dir/two >/dev/null
335 then
336 : happy
337 else
338 echo "Huh?"
339 false
340 fi &&
342 if remove_cr three >/dev/null
343 then
344 : happy
345 else
346 echo "Huh?"
347 false
351 test_expect_success 'in-tree .gitattributes (1)' '
353 echo "one -crlf" >>.gitattributes &&
354 git add .gitattributes &&
355 git commit -m "Add .gitattributes" &&
357 rm -rf tmp one dir .gitattributes patch.file three &&
358 git read-tree --reset -u HEAD &&
360 if remove_cr one >/dev/null
361 then
362 echo "Eh? one should not have CRLF"
363 false
364 else
365 : happy
366 fi &&
367 remove_cr three >/dev/null || {
368 echo "Eh? three should still have CRLF"
369 false
373 test_expect_success 'in-tree .gitattributes (2)' '
375 rm -rf tmp one dir .gitattributes patch.file three &&
376 git read-tree --reset HEAD &&
377 git checkout-index -f -q -u -a &&
379 if remove_cr one >/dev/null
380 then
381 echo "Eh? one should not have CRLF"
382 false
383 else
384 : happy
385 fi &&
386 remove_cr three >/dev/null || {
387 echo "Eh? three should still have CRLF"
388 false
392 test_expect_success 'in-tree .gitattributes (3)' '
394 rm -rf tmp one dir .gitattributes patch.file three &&
395 git read-tree --reset HEAD &&
396 git checkout-index -u .gitattributes &&
397 git checkout-index -u one dir/two three &&
399 if remove_cr one >/dev/null
400 then
401 echo "Eh? one should not have CRLF"
402 false
403 else
404 : happy
405 fi &&
406 remove_cr three >/dev/null || {
407 echo "Eh? three should still have CRLF"
408 false
412 test_expect_success 'in-tree .gitattributes (4)' '
414 rm -rf tmp one dir .gitattributes patch.file three &&
415 git read-tree --reset HEAD &&
416 git checkout-index -u one dir/two three &&
417 git checkout-index -u .gitattributes &&
419 if remove_cr one >/dev/null
420 then
421 echo "Eh? one should not have CRLF"
422 false
423 else
424 : happy
425 fi &&
426 remove_cr three >/dev/null || {
427 echo "Eh? three should still have CRLF"
428 false
432 test_expect_success 'invalid .gitattributes (must not crash)' '
434 echo "three +crlf" >>.gitattributes &&
435 git diff
439 test_done