Merge branch 'bc/clone-empty-repo-via-protocol-v0'
[alt-git.git] / t / t0027-auto-crlf.sh
blob2f57c8669cb5af3dd6fc79bfca4b486f50fa4d19
1 #!/bin/sh
3 test_description='CRLF conversion all combinations'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 compare_files () {
9 tr '\015\000' QN <"$1" >"$1".expect &&
10 tr '\015\000' QN <"$2" | tr -d 'Z' >"$2".actual &&
11 test_cmp "$1".expect "$2".actual &&
12 rm "$1".expect "$2".actual
15 compare_ws_file () {
16 pfx=$1
17 exp=$2.expect
18 act=$pfx.actual.$3
19 tr '\015\000abcdef0123456789' QN00000000000000000 <"$2" |
20 sed -e "s/0000*/$ZERO_OID/" >"$exp" &&
21 tr '\015\000abcdef0123456789' QN00000000000000000 <"$3" |
22 sed -e "s/0000*/$ZERO_OID/" >"$act" &&
23 test_cmp "$exp" "$act" &&
24 rm "$exp" "$act"
27 create_gitattributes () {
29 while test "$#" != 0
31 case "$1" in
32 auto) echo '*.txt text=auto' ;;
33 ident) echo '*.txt ident' ;;
34 text) echo '*.txt text' ;;
35 -text) echo '*.txt -text' ;;
36 crlf) echo '*.txt eol=crlf' ;;
37 lf) echo '*.txt eol=lf' ;;
38 "") ;;
40 echo >&2 invalid attribute: "$1"
41 exit 1
43 esac &&
44 shift
45 done
46 } >.gitattributes
49 # Create 2 sets of files:
50 # The NNO files are "Not NOrmalized in the repo. We use CRLF_mix_LF and store
51 # it under different names for the different test cases, see ${pfx}
52 # Depending on .gitattributes they are normalized at the next commit (or not)
53 # The MIX files have different contents in the repo.
54 # Depending on its contents, the "new safer autocrlf" may kick in.
55 create_NNO_MIX_files () {
56 for crlf in false true input
58 for attr in "" auto text -text
60 for aeol in "" lf crlf
62 pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} &&
63 cp CRLF_mix_LF ${pfx}_LF.txt &&
64 cp CRLF_mix_LF ${pfx}_CRLF.txt &&
65 cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt &&
66 cp CRLF_mix_LF ${pfx}_LF_mix_CR.txt &&
67 cp CRLF_mix_LF ${pfx}_CRLF_nul.txt &&
68 pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf} &&
69 cp LF ${pfx}_LF.txt &&
70 cp CRLF ${pfx}_CRLF.txt &&
71 cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt &&
72 cp LF_mix_CR ${pfx}_LF_mix_CR.txt &&
73 cp CRLF_nul ${pfx}_CRLF_nul.txt ||
74 return 1
75 done
76 done
77 done
80 check_warning () {
81 case "$1" in
82 LF_CRLF) echo "LF will be replaced by CRLF" >"$2".expect ;;
83 CRLF_LF) echo "CRLF will be replaced by LF" >"$2".expect ;;
84 '') >"$2".expect ;;
85 *) echo >&2 "Illegal 1": "$1" ; return false ;;
86 esac
87 sed -e "s/^.* \([^ ]* will be replaced by [^ ]*\) .*$/\1/" "$2" | uniq >"$2".actual
88 test_cmp "$2".expect "$2".actual
91 commit_check_warn () {
92 crlf=$1
93 attr=$2
94 lfname=$3
95 crlfname=$4
96 lfmixcrlf=$5
97 lfmixcr=$6
98 crlfnul=$7
99 pfx=crlf_${crlf}_attr_${attr}
100 create_gitattributes "$attr" &&
101 for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul
103 fname=${pfx}_$f.txt &&
104 cp $f $fname &&
105 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" ||
106 return 1
107 done &&
108 git commit -m "core.autocrlf $crlf" &&
109 check_warning "$lfname" ${pfx}_LF.err &&
110 check_warning "$crlfname" ${pfx}_CRLF.err &&
111 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err &&
112 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err &&
113 check_warning "$crlfnul" ${pfx}_CRLF_nul.err
116 commit_chk_wrnNNO () {
117 attr=$1 ; shift
118 aeol=$1 ; shift
119 crlf=$1 ; shift
120 lfwarn=$1 ; shift
121 crlfwarn=$1 ; shift
122 lfmixcrlf=$1 ; shift
123 lfmixcr=$1 ; shift
124 crlfnul=$1 ; shift
125 pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf}
127 test_expect_success 'setup commit NNO files' '
128 #Commit files on top of existing file
129 create_gitattributes "$attr" $aeol &&
130 for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
132 fname=${pfx}_$f.txt &&
133 cp $f $fname &&
134 printf Z >>"$fname" &&
135 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" ||
136 return 1
137 done
140 test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" '
141 check_warning "$lfwarn" ${pfx}_LF.err
143 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF" '
144 check_warning "$crlfwarn" ${pfx}_CRLF.err
147 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_mix_LF" '
148 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err
151 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf LF_mix_cr" '
152 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err
155 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_nul" '
156 check_warning "$crlfnul" ${pfx}_CRLF_nul.err
160 # Commit a file with mixed line endings on top of different files
161 # in the index. Check for warnings
162 commit_MIX_chkwrn () {
163 attr=$1 ; shift
164 aeol=$1 ; shift
165 crlf=$1 ; shift
166 lfwarn=$1 ; shift
167 crlfwarn=$1 ; shift
168 lfmixcrlf=$1 ; shift
169 lfmixcr=$1 ; shift
170 crlfnul=$1 ; shift
171 pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf}
173 test_expect_success 'setup commit file with mixed EOL' '
174 #Commit file with CLRF_mix_LF on top of existing file
175 create_gitattributes "$attr" $aeol &&
176 for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
178 fname=${pfx}_$f.txt &&
179 cp CRLF_mix_LF $fname &&
180 printf Z >>"$fname" &&
181 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" ||
182 return 1
183 done
186 test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" '
187 check_warning "$lfwarn" ${pfx}_LF.err
189 test_expect_success "commit file with mixed EOL onto CLRF attr=$attr aeol=$aeol crlf=$crlf" '
190 check_warning "$crlfwarn" ${pfx}_CRLF.err
193 test_expect_success "commit file with mixed EOL onto CRLF_mix_LF attr=$attr aeol=$aeol crlf=$crlf" '
194 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err
197 test_expect_success "commit file with mixed EOL onto LF_mix_cr attr=$attr aeol=$aeol crlf=$crlf " '
198 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err
201 test_expect_success "commit file with mixed EOL onto CRLF_nul attr=$attr aeol=$aeol crlf=$crlf" '
202 check_warning "$crlfnul" ${pfx}_CRLF_nul.err
207 stats_ascii () {
208 case "$1" in
210 echo lf
212 CRLF)
213 echo crlf
215 CRLF_mix_LF)
216 echo mixed
218 LF_mix_CR|CRLF_nul|LF_nul|CRLF_mix_CR)
219 echo "-text"
222 echo error_invalid $1
224 esac
229 # construct the attr/ returned by git ls-files --eol
230 # Take none (=empty), one or two args
231 # convert.c: eol=XX overrides text=auto
232 attr_ascii () {
233 case $1,$2 in
234 -text,*) echo "-text" ;;
235 text,) echo "text" ;;
236 text,lf) echo "text eol=lf" ;;
237 text,crlf) echo "text eol=crlf" ;;
238 auto,) echo "text=auto" ;;
239 auto,lf) echo "text=auto eol=lf" ;;
240 auto,crlf) echo "text=auto eol=crlf" ;;
241 lf,) echo "text eol=lf" ;;
242 crlf,) echo "text eol=crlf" ;;
243 ,) echo "" ;;
244 *) echo invalid_attr "$1,$2" ;;
245 esac
248 check_files_in_repo () {
249 crlf=$1
250 attr=$2
251 lfname=$3
252 crlfname=$4
253 lfmixcrlf=$5
254 lfmixcr=$6
255 crlfnul=$7
256 pfx=crlf_${crlf}_attr_${attr}_ &&
257 compare_files $lfname ${pfx}LF.txt &&
258 compare_files $crlfname ${pfx}CRLF.txt &&
259 compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt &&
260 compare_files $lfmixcr ${pfx}LF_mix_CR.txt &&
261 compare_files $crlfnul ${pfx}CRLF_nul.txt
264 check_in_repo_NNO () {
265 attr=$1 ; shift
266 aeol=$1 ; shift
267 crlf=$1 ; shift
268 lfname=$1 ; shift
269 crlfname=$1 ; shift
270 lfmixcrlf=$1 ; shift
271 lfmixcr=$1 ; shift
272 crlfnul=$1 ; shift
273 pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf}
274 test_expect_success "compare_files $lfname ${pfx}_LF.txt" '
275 compare_files $lfname ${pfx}_LF.txt
277 test_expect_success "compare_files $crlfname ${pfx}_CRLF.txt" '
278 compare_files $crlfname ${pfx}_CRLF.txt
280 test_expect_success "compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt" '
281 compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt
283 test_expect_success "compare_files $lfmixcr ${pfx}_LF_mix_CR.txt" '
284 compare_files $lfmixcr ${pfx}_LF_mix_CR.txt
286 test_expect_success "compare_files $crlfnul ${pfx}_CRLF_nul.txt" '
287 compare_files $crlfnul ${pfx}_CRLF_nul.txt
291 checkout_files () {
292 attr=$1 ; shift
293 ident=$1; shift
294 aeol=$1 ; shift
295 crlf=$1 ; shift
296 ceol=$1 ; shift
297 lfname=$1 ; shift
298 crlfname=$1 ; shift
299 lfmixcrlf=$1 ; shift
300 lfmixcr=$1 ; shift
301 crlfnul=$1 ; shift
302 test_expect_success "setup config for checkout attr=$attr ident=$ident aeol=$aeol core.autocrlf=$crlf" '
303 create_gitattributes "$attr" $ident $aeol &&
304 git config core.autocrlf $crlf
306 pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ &&
307 for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul
309 test_expect_success "setup $f checkout ${ceol:+ with -c core.eol=$ceol}" '
310 rm -f crlf_false_attr__$f.txt &&
311 git ${ceol:+-c core.eol=$ceol} checkout -- crlf_false_attr__$f.txt
313 done
315 test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" '
316 test_when_finished "rm expect actual" &&
317 sort <<-EOF >expect &&
318 i/crlf w/$(stats_ascii $crlfname) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF.txt
319 i/mixed w/$(stats_ascii $lfmixcrlf) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_mix_LF.txt
320 i/lf w/$(stats_ascii $lfname) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF.txt
321 i/-text w/$(stats_ascii $lfmixcr) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_mix_CR.txt
322 i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_nul.txt
323 i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_nul.txt
325 git ls-files --eol crlf_false_attr__* >tmp &&
326 sed -e "s/ / /g" -e "s/ */ /g" tmp |
327 sort >actual &&
328 test_cmp expect actual
330 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF" "
331 compare_ws_file $pfx $lfname crlf_false_attr__LF.txt
333 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF" "
334 compare_ws_file $pfx $crlfname crlf_false_attr__CRLF.txt
336 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF_mix_LF" "
337 compare_ws_file $pfx $lfmixcrlf crlf_false_attr__CRLF_mix_LF.txt
339 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_mix_CR" "
340 compare_ws_file $pfx $lfmixcr crlf_false_attr__LF_mix_CR.txt
342 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_nul" "
343 compare_ws_file $pfx $crlfnul crlf_false_attr__LF_nul.txt
347 # Test control characters
348 # NUL SOH CR EOF==^Z
349 test_expect_success 'ls-files --eol -o Text/Binary' '
350 test_when_finished "rm expect actual TeBi_*" &&
351 STRT=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA &&
352 STR=$STRT$STRT$STRT$STRT &&
353 printf "${STR}BBB\001" >TeBi_127_S &&
354 printf "${STR}BBBB\001">TeBi_128_S &&
355 printf "${STR}BBB\032" >TeBi_127_E &&
356 printf "\032${STR}BBB" >TeBi_E_127 &&
357 printf "${STR}BBBB\000">TeBi_128_N &&
358 printf "${STR}BBB\012">TeBi_128_L &&
359 printf "${STR}BBB\015">TeBi_127_C &&
360 printf "${STR}BB\015\012" >TeBi_126_CL &&
361 printf "${STR}BB\015\012\015" >TeBi_126_CLC &&
362 sort <<-\EOF >expect &&
363 i/ w/-text TeBi_127_S
364 i/ w/none TeBi_128_S
365 i/ w/none TeBi_127_E
366 i/ w/-text TeBi_E_127
367 i/ w/-text TeBi_128_N
368 i/ w/lf TeBi_128_L
369 i/ w/-text TeBi_127_C
370 i/ w/crlf TeBi_126_CL
371 i/ w/-text TeBi_126_CLC
373 git ls-files --eol -o >tmp &&
374 sed -n -e "/TeBi_/{s!attr/[ ]*!!g
375 s! ! !g
376 s! *! !g
378 }" tmp | sort >actual &&
379 test_cmp expect actual
382 test_expect_success 'setup main' '
383 echo >.gitattributes &&
384 git checkout -b main &&
385 git add .gitattributes &&
386 git commit -m "add .gitattributes" . &&
387 printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONE\nLINETWO\nLINETHREE" >LF &&
388 printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONE\r\nLINETWO\r\nLINETHREE" >CRLF &&
389 printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONE\r\nLINETWO\nLINETHREE" >CRLF_mix_LF &&
390 printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONE\nLINETWO\rLINETHREE" >LF_mix_CR &&
391 printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONE\r\nLINETWO\rLINETHREE" >CRLF_mix_CR &&
392 printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONEQ\r\nLINETWO\r\nLINETHREE" | q_to_nul >CRLF_nul &&
393 printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONEQ\nLINETWO\nLINETHREE" | q_to_nul >LF_nul &&
394 create_NNO_MIX_files &&
395 git -c core.autocrlf=false add NNO_*.txt MIX_*.txt &&
396 git commit -m "mixed line endings" &&
397 test_tick
402 warn_LF_CRLF="LF will be replaced by CRLF"
403 warn_CRLF_LF="CRLF will be replaced by LF"
405 # WILC stands for "Warn if (this OS) converts LF into CRLF".
406 # WICL: Warn if CRLF becomes LF
407 # WAMIX: Mixed line endings: either CRLF->LF or LF->CRLF
408 if test_have_prereq NATIVE_CRLF
409 then
410 WILC=LF_CRLF
411 WICL=
412 WAMIX=LF_CRLF
413 else
414 WILC=
415 WICL=CRLF_LF
416 WAMIX=CRLF_LF
419 # attr LF CRLF CRLFmixLF LFmixCR CRLFNUL
420 test_expect_success 'commit files empty attr' '
421 commit_check_warn false "" "" "" "" "" "" &&
422 commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "" "" &&
423 commit_check_warn input "" "" "CRLF_LF" "CRLF_LF" "" ""
426 test_expect_success 'commit files attr=auto' '
427 commit_check_warn false "auto" "$WILC" "$WICL" "$WAMIX" "" "" &&
428 commit_check_warn true "auto" "LF_CRLF" "" "LF_CRLF" "" "" &&
429 commit_check_warn input "auto" "" "CRLF_LF" "CRLF_LF" "" ""
432 test_expect_success 'commit files attr=text' '
433 commit_check_warn false "text" "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" &&
434 commit_check_warn true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
435 commit_check_warn input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
438 test_expect_success 'commit files attr=-text' '
439 commit_check_warn false "-text" "" "" "" "" "" &&
440 commit_check_warn true "-text" "" "" "" "" "" &&
441 commit_check_warn input "-text" "" "" "" "" ""
444 test_expect_success 'commit files attr=lf' '
445 commit_check_warn false "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
446 commit_check_warn true "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
447 commit_check_warn input "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
450 test_expect_success 'commit files attr=crlf' '
451 commit_check_warn false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
452 commit_check_warn true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
453 commit_check_warn input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" ""
456 # Commit "CRLFmixLF" on top of these files already in the repo:
457 # mixed mixed mixed mixed mixed
458 # onto onto onto onto onto
459 # attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL
460 commit_MIX_chkwrn "" "" false "" "" "" "" ""
461 commit_MIX_chkwrn "" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF"
462 commit_MIX_chkwrn "" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF"
464 commit_MIX_chkwrn "auto" "" false "$WAMIX" "" "" "$WAMIX" "$WAMIX"
465 commit_MIX_chkwrn "auto" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF"
466 commit_MIX_chkwrn "auto" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF"
468 # attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL
469 commit_chk_wrnNNO "" "" false "" "" "" "" ""
470 commit_chk_wrnNNO "" "" true LF_CRLF "" "" "" ""
471 commit_chk_wrnNNO "" "" input "" "" "" "" ""
473 commit_chk_wrnNNO "auto" "" false "$WILC" "" "" "" ""
474 commit_chk_wrnNNO "auto" "" true LF_CRLF "" "" "" ""
475 commit_chk_wrnNNO "auto" "" input "" "" "" "" ""
476 for crlf in true false input
478 commit_chk_wrnNNO -text "" $crlf "" "" "" "" ""
479 commit_chk_wrnNNO -text lf $crlf "" "" "" "" ""
480 commit_chk_wrnNNO -text crlf $crlf "" "" "" "" ""
481 commit_chk_wrnNNO "" lf $crlf "" CRLF_LF CRLF_LF "" CRLF_LF
482 commit_chk_wrnNNO "" crlf $crlf LF_CRLF "" LF_CRLF LF_CRLF ""
483 commit_chk_wrnNNO auto lf $crlf "" "" "" "" ""
484 commit_chk_wrnNNO auto crlf $crlf LF_CRLF "" "" "" ""
485 commit_chk_wrnNNO text lf $crlf "" CRLF_LF CRLF_LF "" CRLF_LF
486 commit_chk_wrnNNO text crlf $crlf LF_CRLF "" LF_CRLF LF_CRLF ""
487 done
489 commit_chk_wrnNNO "text" "" false "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL"
490 commit_chk_wrnNNO "text" "" true LF_CRLF "" LF_CRLF LF_CRLF ""
491 commit_chk_wrnNNO "text" "" input "" CRLF_LF CRLF_LF "" CRLF_LF
493 test_expect_success 'commit NNO and cleanup' '
494 git commit -m "commit files on top of NNO" &&
495 rm -f *.txt &&
496 git -c core.autocrlf=false reset --hard
499 test_expect_success 'commit empty gitattribues' '
500 check_files_in_repo false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
501 check_files_in_repo true "" LF LF LF LF_mix_CR CRLF_nul &&
502 check_files_in_repo input "" LF LF LF LF_mix_CR CRLF_nul
505 test_expect_success 'commit text=auto' '
506 check_files_in_repo false "auto" LF LF LF LF_mix_CR CRLF_nul &&
507 check_files_in_repo true "auto" LF LF LF LF_mix_CR CRLF_nul &&
508 check_files_in_repo input "auto" LF LF LF LF_mix_CR CRLF_nul
511 test_expect_success 'commit text' '
512 check_files_in_repo false "text" LF LF LF LF_mix_CR LF_nul &&
513 check_files_in_repo true "text" LF LF LF LF_mix_CR LF_nul &&
514 check_files_in_repo input "text" LF LF LF LF_mix_CR LF_nul
517 test_expect_success 'commit -text' '
518 check_files_in_repo false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
519 check_files_in_repo true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
520 check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
523 for crlf in true false input
525 # attr aeol LF CRLF CRLF_mix_LF LF_mix_CR CRLFNUL
526 check_in_repo_NNO "" "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
527 check_in_repo_NNO -text "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
528 check_in_repo_NNO -text lf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
529 check_in_repo_NNO -text crlf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
530 check_in_repo_NNO auto "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
531 check_in_repo_NNO auto lf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
532 check_in_repo_NNO auto crlf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
533 check_in_repo_NNO text "" $crlf LF LF LF LF_mix_CR LF_nul
534 check_in_repo_NNO text lf $crlf LF LF LF LF_mix_CR LF_nul
535 check_in_repo_NNO text crlf $crlf LF LF LF LF_mix_CR LF_nul
536 done
537 ################################################################################
538 # Check how files in the repo are changed when they are checked out
539 # How to read the table below:
540 # - checkout_files will check multiple files with a combination of settings
541 # and attributes (core.autocrlf=input is forbidden with core.eol=crlf)
543 # - parameter $1 : text in .gitattributs "" (empty) | auto | text | -text
544 # - parameter $2 : ident "" | i (i == ident)
545 # - parameter $3 : eol in .gitattributs "" (empty) | lf | crlf
546 # - parameter $4 : core.autocrlf false | true | input
547 # - parameter $5 : core.eol "" | lf | crlf | "native"
548 # - parameter $6 : reference for a file with only LF in the repo
549 # - parameter $7 : reference for a file with only CRLF in the repo
550 # - parameter $8 : reference for a file with mixed LF and CRLF in the repo
551 # - parameter $9 : reference for a file with LF and CR in the repo
552 # - parameter $10 : reference for a file with CRLF and a NUL (should be handled as binary when auto)
554 if test_have_prereq NATIVE_CRLF
555 then
556 MIX_CRLF_LF=CRLF
557 MIX_LF_CR=CRLF_mix_CR
558 NL=CRLF
559 LFNUL=CRLF_nul
560 else
561 MIX_CRLF_LF=CRLF_mix_LF
562 MIX_LF_CR=LF_mix_CR
563 NL=LF
564 LFNUL=LF_nul
566 export CRLF_MIX_LF_CR MIX NL
568 # Same handling with and without ident
569 for id in "" ident
571 for ceol in lf crlf native
573 for crlf in true false input
575 # -text overrides core.autocrlf and core.eol
576 # text and eol=crlf or eol=lf override core.autocrlf and core.eol
577 checkout_files -text "$id" "" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
578 checkout_files -text "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
579 checkout_files -text "$id" "crlf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
580 # text
581 checkout_files text "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
582 checkout_files text "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
583 # currently the same as text, eol=XXX
584 checkout_files auto "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
585 checkout_files auto "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
586 done
588 # core.autocrlf false, different core.eol
589 checkout_files "" "$id" "" false "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
590 # core.autocrlf true
591 checkout_files "" "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
592 # text: core.autocrlf = true overrides core.eol
593 checkout_files auto "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
594 checkout_files text "$id" "" true "$ceol" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
595 # text: core.autocrlf = input overrides core.eol
596 checkout_files text "$id" "" input "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
597 checkout_files auto "$id" "" input "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
598 # text=auto + eol=XXX
599 done
600 # text: core.autocrlf=false uses core.eol
601 checkout_files text "$id" "" false crlf CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
602 checkout_files text "$id" "" false lf LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
603 # text: core.autocrlf=false and core.eol unset(or native) uses native eol
604 checkout_files text "$id" "" false "" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL
605 checkout_files text "$id" "" false native $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL
606 # auto: core.autocrlf=false and core.eol unset(or native) uses native eol
607 checkout_files auto "$id" "" false "" $NL CRLF CRLF_mix_LF LF_mix_CR LF_nul
608 checkout_files auto "$id" "" false native $NL CRLF CRLF_mix_LF LF_mix_CR LF_nul
609 # core.autocrlf false, .gitattributes sets eol
610 checkout_files "" "$id" "lf" false "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
611 checkout_files "" "$id" "crlf" false "" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
612 # core.autocrlf true, .gitattributes sets eol
613 checkout_files "" "$id" "lf" true "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
614 checkout_files "" "$id" "crlf" true "" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
615 done
617 # Should be the last test case: remove some files from the worktree
618 test_expect_success 'ls-files --eol -d -z' '
619 rm crlf_false_attr__CRLF.txt crlf_false_attr__CRLF_mix_LF.txt crlf_false_attr__LF.txt .gitattributes &&
620 cat >expect <<-\EOF &&
621 i/crlf w/ crlf_false_attr__CRLF.txt
622 i/lf w/ .gitattributes
623 i/lf w/ crlf_false_attr__LF.txt
624 i/mixed w/ crlf_false_attr__CRLF_mix_LF.txt
626 git ls-files --eol -d >tmp &&
627 sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" tmp |
628 sort >actual &&
629 test_cmp expect actual
632 test_done