3 test_description
='CRLF conversion'
8 tr '\015' Q
<"$1" |
grep Q
>/dev
/null
11 test_expect_success setup
'
13 git config core.autocrlf false &&
15 for w in Hello world how are you; do echo $w; done >one &&
17 for w in I am very very fine thank you; do echo $w; done >dir/two &&
18 for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three &&
21 git commit -m initial &&
23 one=`git rev-parse HEAD:one` &&
24 dir=`git rev-parse HEAD:dir` &&
25 two=`git rev-parse HEAD:dir/two` &&
26 three=`git rev-parse HEAD:three` &&
28 for w in Some extra lines here; do echo $w; done >>one &&
29 git diff >patch.file &&
30 patched=`git hash-object --stdin <one` &&
31 git read-tree --reset -u HEAD &&
36 test_expect_success
'safecrlf: autocrlf=input, all CRLF' '
38 git config core.autocrlf input &&
39 git config core.safecrlf true &&
41 for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
42 test_must_fail git add allcrlf
45 test_expect_success
'safecrlf: autocrlf=input, mixed LF/CRLF' '
47 git config core.autocrlf input &&
48 git config core.safecrlf true &&
50 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
51 test_must_fail git add mixed
54 test_expect_success
'safecrlf: autocrlf=true, all LF' '
56 git config core.autocrlf true &&
57 git config core.safecrlf true &&
59 for w in I am all LF; do echo $w; done >alllf &&
60 test_must_fail git add alllf
63 test_expect_success
'safecrlf: autocrlf=true mixed LF/CRLF' '
65 git config core.autocrlf true &&
66 git config core.safecrlf true &&
68 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
69 test_must_fail git add mixed
72 test_expect_success
'safecrlf: print warning only once' '
74 git config core.autocrlf input &&
75 git config core.safecrlf warn &&
77 for w in I am all LF; do echo $w; done >doublewarn &&
79 git commit -m "nowarn" &&
80 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >doublewarn &&
81 test $(git add doublewarn 2>&1 | grep "CRLF will be replaced by LF" | wc -l) = 1
84 test_expect_success
'switch off autocrlf, safecrlf, reset HEAD' '
85 git config core.autocrlf false &&
86 git config core.safecrlf false &&
87 git reset --hard HEAD^
90 test_expect_success
'update with autocrlf=input' '
92 rm -f tmp one dir/two three &&
93 git read-tree --reset -u HEAD &&
94 git config core.autocrlf input &&
98 append_cr <$f >tmp && mv -f tmp $f &&
99 git update-index -- $f || {
106 differs=`git diff-index --cached HEAD` &&
107 test -z "$differs" || {
114 test_expect_success
'update with autocrlf=true' '
116 rm -f tmp one dir/two three &&
117 git read-tree --reset -u HEAD &&
118 git config core.autocrlf true &&
122 append_cr <$f >tmp && mv -f tmp $f &&
123 git update-index -- $f || {
130 differs=`git diff-index --cached HEAD` &&
131 test -z "$differs" || {
138 test_expect_success
'checkout with autocrlf=true' '
140 rm -f tmp one dir/two three &&
141 git config core.autocrlf true &&
142 git read-tree --reset -u HEAD &&
146 remove_cr <"$f" >tmp && mv -f tmp $f &&
147 git update-index -- $f || {
153 test "$one" = `git hash-object --stdin <one` &&
154 test "$two" = `git hash-object --stdin <dir/two` &&
155 differs=`git diff-index --cached HEAD` &&
156 test -z "$differs" || {
162 test_expect_success
'checkout with autocrlf=input' '
164 rm -f tmp one dir/two three &&
165 git config core.autocrlf input &&
166 git read-tree --reset -u HEAD &&
176 git update-index -- $f
179 test "$one" = `git hash-object --stdin <one` &&
180 test "$two" = `git hash-object --stdin <dir/two` &&
181 differs=`git diff-index --cached HEAD` &&
182 test -z "$differs" || {
188 test_expect_success
'apply patch (autocrlf=input)' '
190 rm -f tmp one dir/two three &&
191 git config core.autocrlf input &&
192 git read-tree --reset -u HEAD &&
194 git apply patch.file &&
195 test "$patched" = "`git hash-object --stdin <one`" || {
196 echo "Eh? apply without index"
201 test_expect_success
'apply patch --cached (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 --cached patch.file &&
208 test "$patched" = `git rev-parse :one` || {
209 echo "Eh? apply with --cached"
214 test_expect_success
'apply patch --index (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 --index patch.file &&
221 test "$patched" = `git rev-parse :one` &&
222 test "$patched" = `git hash-object --stdin <one` || {
223 echo "Eh? apply with --index"
228 test_expect_success
'apply patch (autocrlf=true)' '
230 rm -f tmp one dir/two three &&
231 git config core.autocrlf true &&
232 git read-tree --reset -u HEAD &&
234 git apply patch.file &&
235 test "$patched" = "`remove_cr <one | git hash-object --stdin`" || {
236 echo "Eh? apply without index"
241 test_expect_success
'apply patch --cached (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 --cached patch.file &&
248 test "$patched" = `git rev-parse :one` || {
249 echo "Eh? apply without index"
254 test_expect_success
'apply patch --index (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 --index patch.file &&
261 test "$patched" = `git rev-parse :one` &&
262 test "$patched" = "`remove_cr <one | git hash-object --stdin`" || {
263 echo "Eh? apply with --index"
268 test_expect_success
'.gitattributes says two is binary' '
270 rm -f tmp one dir/two three &&
271 echo "two -crlf" >.gitattributes &&
272 git config core.autocrlf true &&
273 git read-tree --reset -u HEAD &&
300 test_expect_success
'.gitattributes says two is input' '
302 rm -f tmp one dir/two three &&
303 echo "two crlf=input" >.gitattributes &&
304 git read-tree --reset -u HEAD &&
315 test_expect_success
'.gitattributes says two and three are text' '
317 rm -f tmp one dir/two three &&
318 echo "t* crlf" >.gitattributes &&
319 git read-tree --reset -u HEAD &&
338 test_expect_success
'in-tree .gitattributes (1)' '
340 echo "one -crlf" >>.gitattributes &&
341 git add .gitattributes &&
342 git commit -m "Add .gitattributes" &&
344 rm -rf tmp one dir .gitattributes patch.file three &&
345 git read-tree --reset -u HEAD &&
349 echo "Eh? one should not have CRLF"
355 echo "Eh? three should still have CRLF"
360 test_expect_success
'in-tree .gitattributes (2)' '
362 rm -rf tmp one dir .gitattributes patch.file three &&
363 git read-tree --reset HEAD &&
364 git checkout-index -f -q -u -a &&
368 echo "Eh? one should not have CRLF"
374 echo "Eh? three should still have CRLF"
379 test_expect_success
'in-tree .gitattributes (3)' '
381 rm -rf tmp one dir .gitattributes patch.file three &&
382 git read-tree --reset HEAD &&
383 git checkout-index -u .gitattributes &&
384 git checkout-index -u one dir/two three &&
388 echo "Eh? one should not have CRLF"
394 echo "Eh? three should still have CRLF"
399 test_expect_success
'in-tree .gitattributes (4)' '
401 rm -rf tmp one dir .gitattributes patch.file three &&
402 git read-tree --reset HEAD &&
403 git checkout-index -u one dir/two three &&
404 git checkout-index -u .gitattributes &&
408 echo "Eh? one should not have CRLF"
414 echo "Eh? three should still have CRLF"
419 test_expect_success
'checkout with existing .gitattributes' '
421 git config core.autocrlf true &&
422 git config --unset core.safecrlf &&
423 echo ".file2 -crlfQ" | q_to_cr >> .gitattributes &&
424 git add .gitattributes &&
425 git commit -m initial &&
426 echo ".file -crlfQ" | q_to_cr >> .gitattributes &&
427 echo "contents" > .file &&
428 git add .gitattributes .file &&
429 git commit -m second &&
431 git checkout master~1 &&
432 git checkout master &&
433 test "$(git diff-files --raw)" = ""
437 test_expect_success
'checkout when deleting .gitattributes' '
439 git rm .gitattributes &&
440 echo "contentsQ" | q_to_cr > .file2 &&
442 git commit -m third &&
444 git checkout master~1 &&
445 git checkout master &&
450 test_expect_success
'invalid .gitattributes (must not crash)' '
452 echo "three +crlf" >>.gitattributes &&
456 # Some more tests here to add new autocrlf functionality.
457 # We want to have a known state here, so start a bit from scratch
459 test_expect_success
'setting up for new autocrlf tests' '
460 git config core.autocrlf false &&
461 git config core.safecrlf false &&
463 for w in I am all LF; do echo $w; done >alllf &&
464 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
465 for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
467 git commit -m "alllf, allcrlf and mixed only" &&
468 git tag -a -m "message" autocrlf-checkpoint
471 test_expect_success
'report no change after setting autocrlf' '
472 git config core.autocrlf true &&
477 test_expect_success
'files are clean after checkout' '
484 tr '\015' Q |
tr -d '\012'
487 test_expect_success
'LF only file gets CRLF with autocrlf' '
488 test "$(cr_to_Q_no_NL < alllf)" = "IQamQallQLFQ"
491 test_expect_success
'Mixed file is still mixed with autocrlf' '
492 test "$(cr_to_Q_no_NL < mixed)" = "OhhereisCRLFQintext"
495 test_expect_success
'CRLF only file has CRLF with autocrlf' '
496 test "$(cr_to_Q_no_NL < allcrlf)" = "IQamQallQCRLFQ"
499 test_expect_success
'New CRLF file gets LF in repo' '
500 tr -d "\015" < alllf | append_cr > alllf2 &&
502 git commit -m "alllf2 added" &&
503 git config core.autocrlf false &&
506 test_cmp alllf alllf2