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
85 test_expect_success
'safecrlf: git diff demotes safecrlf=true to warn' '
86 git config core.autocrlf input &&
87 git config core.safecrlf true &&
92 test_expect_success
'switch off autocrlf, safecrlf, reset HEAD' '
93 git config core.autocrlf false &&
94 git config core.safecrlf false &&
95 git reset --hard HEAD^
98 test_expect_success
'update with autocrlf=input' '
100 rm -f tmp one dir/two three &&
101 git read-tree --reset -u HEAD &&
102 git config core.autocrlf input &&
106 append_cr <$f >tmp && mv -f tmp $f &&
107 git update-index -- $f || {
114 differs=$(git diff-index --cached HEAD) &&
115 test -z "$differs" || {
122 test_expect_success
'update with autocrlf=true' '
124 rm -f tmp one dir/two three &&
125 git read-tree --reset -u HEAD &&
126 git config core.autocrlf true &&
130 append_cr <$f >tmp && mv -f tmp $f &&
131 git update-index -- $f || {
138 differs=$(git diff-index --cached HEAD) &&
139 test -z "$differs" || {
146 test_expect_success
'checkout with autocrlf=true' '
148 rm -f tmp one dir/two three &&
149 git config core.autocrlf true &&
150 git read-tree --reset -u HEAD &&
154 remove_cr <"$f" >tmp && mv -f tmp $f &&
155 git update-index -- $f || {
161 test "$one" = $(git hash-object --stdin <one) &&
162 test "$two" = $(git hash-object --stdin <dir/two) &&
163 differs=$(git diff-index --cached HEAD) &&
164 test -z "$differs" || {
170 test_expect_success
'checkout with autocrlf=input' '
172 rm -f tmp one dir/two three &&
173 git config core.autocrlf input &&
174 git read-tree --reset -u HEAD &&
184 git update-index -- $f
187 test "$one" = $(git hash-object --stdin <one) &&
188 test "$two" = $(git hash-object --stdin <dir/two) &&
189 differs=$(git diff-index --cached HEAD) &&
190 test -z "$differs" || {
196 test_expect_success
'apply patch (autocrlf=input)' '
198 rm -f tmp one dir/two three &&
199 git config core.autocrlf input &&
200 git read-tree --reset -u HEAD &&
202 git apply patch.file &&
203 test "$patched" = "$(git hash-object --stdin <one)" || {
204 echo "Eh? apply without index"
209 test_expect_success
'apply patch --cached (autocrlf=input)' '
211 rm -f tmp one dir/two three &&
212 git config core.autocrlf input &&
213 git read-tree --reset -u HEAD &&
215 git apply --cached patch.file &&
216 test "$patched" = $(git rev-parse :one) || {
217 echo "Eh? apply with --cached"
222 test_expect_success
'apply patch --index (autocrlf=input)' '
224 rm -f tmp one dir/two three &&
225 git config core.autocrlf input &&
226 git read-tree --reset -u HEAD &&
228 git apply --index patch.file &&
229 test "$patched" = $(git rev-parse :one) &&
230 test "$patched" = $(git hash-object --stdin <one) || {
231 echo "Eh? apply with --index"
236 test_expect_success
'apply patch (autocrlf=true)' '
238 rm -f tmp one dir/two three &&
239 git config core.autocrlf true &&
240 git read-tree --reset -u HEAD &&
242 git apply patch.file &&
243 test "$patched" = "$(remove_cr <one | git hash-object --stdin)" || {
244 echo "Eh? apply without index"
249 test_expect_success
'apply patch --cached (autocrlf=true)' '
251 rm -f tmp one dir/two three &&
252 git config core.autocrlf true &&
253 git read-tree --reset -u HEAD &&
255 git apply --cached patch.file &&
256 test "$patched" = $(git rev-parse :one) || {
257 echo "Eh? apply without index"
262 test_expect_success
'apply patch --index (autocrlf=true)' '
264 rm -f tmp one dir/two three &&
265 git config core.autocrlf true &&
266 git read-tree --reset -u HEAD &&
268 git apply --index patch.file &&
269 test "$patched" = $(git rev-parse :one) &&
270 test "$patched" = "$(remove_cr <one | git hash-object --stdin)" || {
271 echo "Eh? apply with --index"
276 test_expect_success
'.gitattributes says two is binary' '
278 rm -f tmp one dir/two three &&
279 echo "two -crlf" >.gitattributes &&
280 git config core.autocrlf true &&
281 git read-tree --reset -u HEAD &&
308 test_expect_success
'.gitattributes says two is input' '
310 rm -f tmp one dir/two three &&
311 echo "two crlf=input" >.gitattributes &&
312 git read-tree --reset -u HEAD &&
323 test_expect_success
'.gitattributes says two and three are text' '
325 rm -f tmp one dir/two three &&
326 echo "t* crlf" >.gitattributes &&
327 git read-tree --reset -u HEAD &&
346 test_expect_success
'in-tree .gitattributes (1)' '
348 echo "one -crlf" >>.gitattributes &&
349 git add .gitattributes &&
350 git commit -m "Add .gitattributes" &&
352 rm -rf tmp one dir .gitattributes patch.file three &&
353 git read-tree --reset -u HEAD &&
357 echo "Eh? one should not have CRLF"
363 echo "Eh? three should still have CRLF"
368 test_expect_success
'in-tree .gitattributes (2)' '
370 rm -rf tmp one dir .gitattributes patch.file three &&
371 git read-tree --reset HEAD &&
372 git checkout-index -f -q -u -a &&
376 echo "Eh? one should not have CRLF"
382 echo "Eh? three should still have CRLF"
387 test_expect_success
'in-tree .gitattributes (3)' '
389 rm -rf tmp one dir .gitattributes patch.file three &&
390 git read-tree --reset HEAD &&
391 git checkout-index -u .gitattributes &&
392 git checkout-index -u one dir/two three &&
396 echo "Eh? one should not have CRLF"
402 echo "Eh? three should still have CRLF"
407 test_expect_success
'in-tree .gitattributes (4)' '
409 rm -rf tmp one dir .gitattributes patch.file three &&
410 git read-tree --reset HEAD &&
411 git checkout-index -u one dir/two three &&
412 git checkout-index -u .gitattributes &&
416 echo "Eh? one should not have CRLF"
422 echo "Eh? three should still have CRLF"
427 test_expect_success
'checkout with existing .gitattributes' '
429 git config core.autocrlf true &&
430 git config --unset core.safecrlf &&
431 echo ".file2 -crlfQ" | q_to_cr >> .gitattributes &&
432 git add .gitattributes &&
433 git commit -m initial &&
434 echo ".file -crlfQ" | q_to_cr >> .gitattributes &&
435 echo "contents" > .file &&
436 git add .gitattributes .file &&
437 git commit -m second &&
439 git checkout master~1 &&
440 git checkout master &&
441 test "$(git diff-files --raw)" = ""
445 test_expect_success
'checkout when deleting .gitattributes' '
447 git rm .gitattributes &&
448 echo "contentsQ" | q_to_cr > .file2 &&
450 git commit -m third &&
452 git checkout master~1 &&
453 git checkout master &&
458 test_expect_success
'invalid .gitattributes (must not crash)' '
460 echo "three +crlf" >>.gitattributes &&
464 # Some more tests here to add new autocrlf functionality.
465 # We want to have a known state here, so start a bit from scratch
467 test_expect_success
'setting up for new autocrlf tests' '
468 git config core.autocrlf false &&
469 git config core.safecrlf false &&
471 for w in I am all LF; do echo $w; done >alllf &&
472 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
473 for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
475 git commit -m "alllf, allcrlf and mixed only" &&
476 git tag -a -m "message" autocrlf-checkpoint
479 test_expect_success
'report no change after setting autocrlf' '
480 git config core.autocrlf true &&
485 test_expect_success
'files are clean after checkout' '
492 tr '\015' Q |
tr -d '\012'
495 test_expect_success
'LF only file gets CRLF with autocrlf' '
496 test "$(cr_to_Q_no_NL < alllf)" = "IQamQallQLFQ"
499 test_expect_success
'Mixed file is still mixed with autocrlf' '
500 test "$(cr_to_Q_no_NL < mixed)" = "OhhereisCRLFQintext"
503 test_expect_success
'CRLF only file has CRLF with autocrlf' '
504 test "$(cr_to_Q_no_NL < allcrlf)" = "IQamQallQCRLFQ"
507 test_expect_success
'New CRLF file gets LF in repo' '
508 tr -d "\015" < alllf | append_cr > alllf2 &&
510 git commit -m "alllf2 added" &&
511 git config core.autocrlf false &&
514 test_cmp alllf alllf2