http.c: cookie file tightening
[git/debian.git] / t / t0027-auto-crlf.sh
bloba94ac1eae377c023ae3e02eaae393db6e8d232d3
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 done
75 done
76 done
79 check_warning () {
80 case "$1" in
81 LF_CRLF) echo "LF will be replaced by CRLF" >"$2".expect ;;
82 CRLF_LF) echo "CRLF will be replaced by LF" >"$2".expect ;;
83 '') >"$2".expect ;;
84 *) echo >&2 "Illegal 1": "$1" ; return false ;;
85 esac
86 sed -e "s/^.* \([^ ]* will be replaced by [^ ]*\) .*$/\1/" "$2" | uniq >"$2".actual
87 test_cmp "$2".expect "$2".actual
90 commit_check_warn () {
91 crlf=$1
92 attr=$2
93 lfname=$3
94 crlfname=$4
95 lfmixcrlf=$5
96 lfmixcr=$6
97 crlfnul=$7
98 pfx=crlf_${crlf}_attr_${attr}
99 create_gitattributes "$attr" &&
100 for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul
102 fname=${pfx}_$f.txt &&
103 cp $f $fname &&
104 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err"
105 done &&
106 git commit -m "core.autocrlf $crlf" &&
107 check_warning "$lfname" ${pfx}_LF.err &&
108 check_warning "$crlfname" ${pfx}_CRLF.err &&
109 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err &&
110 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err &&
111 check_warning "$crlfnul" ${pfx}_CRLF_nul.err
114 commit_chk_wrnNNO () {
115 attr=$1 ; shift
116 aeol=$1 ; shift
117 crlf=$1 ; shift
118 lfwarn=$1 ; shift
119 crlfwarn=$1 ; shift
120 lfmixcrlf=$1 ; shift
121 lfmixcr=$1 ; shift
122 crlfnul=$1 ; shift
123 pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf}
124 #Commit files on top of existing file
125 create_gitattributes "$attr" $aeol &&
126 for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
128 fname=${pfx}_$f.txt &&
129 cp $f $fname &&
130 printf Z >>"$fname" &&
131 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err"
132 done
134 test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" '
135 check_warning "$lfwarn" ${pfx}_LF.err
137 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF" '
138 check_warning "$crlfwarn" ${pfx}_CRLF.err
141 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_mix_LF" '
142 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err
145 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf LF_mix_cr" '
146 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err
149 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_nul" '
150 check_warning "$crlfnul" ${pfx}_CRLF_nul.err
154 # Commit a file with mixed line endings on top of different files
155 # in the index. Check for warnings
156 commit_MIX_chkwrn () {
157 attr=$1 ; shift
158 aeol=$1 ; shift
159 crlf=$1 ; shift
160 lfwarn=$1 ; shift
161 crlfwarn=$1 ; shift
162 lfmixcrlf=$1 ; shift
163 lfmixcr=$1 ; shift
164 crlfnul=$1 ; shift
165 pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf}
166 #Commit file with CLRF_mix_LF on top of existing file
167 create_gitattributes "$attr" $aeol &&
168 for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
170 fname=${pfx}_$f.txt &&
171 cp CRLF_mix_LF $fname &&
172 printf Z >>"$fname" &&
173 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err"
174 done
176 test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" '
177 check_warning "$lfwarn" ${pfx}_LF.err
179 test_expect_success "commit file with mixed EOL onto CLRF attr=$attr aeol=$aeol crlf=$crlf" '
180 check_warning "$crlfwarn" ${pfx}_CRLF.err
183 test_expect_success "commit file with mixed EOL onto CRLF_mix_LF attr=$attr aeol=$aeol crlf=$crlf" '
184 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err
187 test_expect_success "commit file with mixed EOL onto LF_mix_cr attr=$attr aeol=$aeol crlf=$crlf " '
188 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err
191 test_expect_success "commit file with mixed EOL onto CRLF_nul attr=$attr aeol=$aeol crlf=$crlf" '
192 check_warning "$crlfnul" ${pfx}_CRLF_nul.err
197 stats_ascii () {
198 case "$1" in
200 echo lf
202 CRLF)
203 echo crlf
205 CRLF_mix_LF)
206 echo mixed
208 LF_mix_CR|CRLF_nul|LF_nul|CRLF_mix_CR)
209 echo "-text"
212 echo error_invalid $1
214 esac
219 # construct the attr/ returned by git ls-files --eol
220 # Take none (=empty), one or two args
221 # convert.c: eol=XX overrides text=auto
222 attr_ascii () {
223 case $1,$2 in
224 -text,*) echo "-text" ;;
225 text,) echo "text" ;;
226 text,lf) echo "text eol=lf" ;;
227 text,crlf) echo "text eol=crlf" ;;
228 auto,) echo "text=auto" ;;
229 auto,lf) echo "text=auto eol=lf" ;;
230 auto,crlf) echo "text=auto eol=crlf" ;;
231 lf,) echo "text eol=lf" ;;
232 crlf,) echo "text eol=crlf" ;;
233 ,) echo "" ;;
234 *) echo invalid_attr "$1,$2" ;;
235 esac
238 check_files_in_repo () {
239 crlf=$1
240 attr=$2
241 lfname=$3
242 crlfname=$4
243 lfmixcrlf=$5
244 lfmixcr=$6
245 crlfnul=$7
246 pfx=crlf_${crlf}_attr_${attr}_ &&
247 compare_files $lfname ${pfx}LF.txt &&
248 compare_files $crlfname ${pfx}CRLF.txt &&
249 compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt &&
250 compare_files $lfmixcr ${pfx}LF_mix_CR.txt &&
251 compare_files $crlfnul ${pfx}CRLF_nul.txt
254 check_in_repo_NNO () {
255 attr=$1 ; shift
256 aeol=$1 ; shift
257 crlf=$1 ; shift
258 lfname=$1 ; shift
259 crlfname=$1 ; shift
260 lfmixcrlf=$1 ; shift
261 lfmixcr=$1 ; shift
262 crlfnul=$1 ; shift
263 pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf}
264 test_expect_success "compare_files $lfname ${pfx}_LF.txt" '
265 compare_files $lfname ${pfx}_LF.txt
267 test_expect_success "compare_files $crlfname ${pfx}_CRLF.txt" '
268 compare_files $crlfname ${pfx}_CRLF.txt
270 test_expect_success "compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt" '
271 compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt
273 test_expect_success "compare_files $lfmixcr ${pfx}_LF_mix_CR.txt" '
274 compare_files $lfmixcr ${pfx}_LF_mix_CR.txt
276 test_expect_success "compare_files $crlfnul ${pfx}_CRLF_nul.txt" '
277 compare_files $crlfnul ${pfx}_CRLF_nul.txt
281 checkout_files () {
282 attr=$1 ; shift
283 ident=$1; shift
284 aeol=$1 ; shift
285 crlf=$1 ; shift
286 ceol=$1 ; shift
287 lfname=$1 ; shift
288 crlfname=$1 ; shift
289 lfmixcrlf=$1 ; shift
290 lfmixcr=$1 ; shift
291 crlfnul=$1 ; shift
292 create_gitattributes "$attr" $ident $aeol &&
293 git config core.autocrlf $crlf &&
294 pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ &&
295 for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul
297 rm crlf_false_attr__$f.txt &&
298 if test -z "$ceol"; then
299 git checkout -- crlf_false_attr__$f.txt
300 else
301 git -c core.eol=$ceol checkout -- crlf_false_attr__$f.txt
303 done
305 test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" '
306 test_when_finished "rm expect actual" &&
307 sort <<-EOF >expect &&
308 i/crlf w/$(stats_ascii $crlfname) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF.txt
309 i/mixed w/$(stats_ascii $lfmixcrlf) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_mix_LF.txt
310 i/lf w/$(stats_ascii $lfname) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF.txt
311 i/-text w/$(stats_ascii $lfmixcr) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_mix_CR.txt
312 i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_nul.txt
313 i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_nul.txt
315 git ls-files --eol crlf_false_attr__* >tmp &&
316 sed -e "s/ / /g" -e "s/ */ /g" tmp |
317 sort >actual &&
318 test_cmp expect actual
320 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF" "
321 compare_ws_file $pfx $lfname crlf_false_attr__LF.txt
323 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF" "
324 compare_ws_file $pfx $crlfname crlf_false_attr__CRLF.txt
326 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF_mix_LF" "
327 compare_ws_file $pfx $lfmixcrlf crlf_false_attr__CRLF_mix_LF.txt
329 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_mix_CR" "
330 compare_ws_file $pfx $lfmixcr crlf_false_attr__LF_mix_CR.txt
332 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_nul" "
333 compare_ws_file $pfx $crlfnul crlf_false_attr__LF_nul.txt
337 # Test control characters
338 # NUL SOH CR EOF==^Z
339 test_expect_success 'ls-files --eol -o Text/Binary' '
340 test_when_finished "rm expect actual TeBi_*" &&
341 STRT=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA &&
342 STR=$STRT$STRT$STRT$STRT &&
343 printf "${STR}BBB\001" >TeBi_127_S &&
344 printf "${STR}BBBB\001">TeBi_128_S &&
345 printf "${STR}BBB\032" >TeBi_127_E &&
346 printf "\032${STR}BBB" >TeBi_E_127 &&
347 printf "${STR}BBBB\000">TeBi_128_N &&
348 printf "${STR}BBB\012">TeBi_128_L &&
349 printf "${STR}BBB\015">TeBi_127_C &&
350 printf "${STR}BB\015\012" >TeBi_126_CL &&
351 printf "${STR}BB\015\012\015" >TeBi_126_CLC &&
352 sort <<-\EOF >expect &&
353 i/ w/-text TeBi_127_S
354 i/ w/none TeBi_128_S
355 i/ w/none TeBi_127_E
356 i/ w/-text TeBi_E_127
357 i/ w/-text TeBi_128_N
358 i/ w/lf TeBi_128_L
359 i/ w/-text TeBi_127_C
360 i/ w/crlf TeBi_126_CL
361 i/ w/-text TeBi_126_CLC
363 git ls-files --eol -o >tmp &&
364 sed -n -e "/TeBi_/{s!attr/[ ]*!!g
365 s! ! !g
366 s! *! !g
368 }" tmp | sort >actual &&
369 test_cmp expect actual
372 test_expect_success 'setup main' '
373 echo >.gitattributes &&
374 git checkout -b main &&
375 git add .gitattributes &&
376 git commit -m "add .gitattributes" . &&
377 printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONE\nLINETWO\nLINETHREE" >LF &&
378 printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONE\r\nLINETWO\r\nLINETHREE" >CRLF &&
379 printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONE\r\nLINETWO\nLINETHREE" >CRLF_mix_LF &&
380 printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONE\nLINETWO\rLINETHREE" >LF_mix_CR &&
381 printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONE\r\nLINETWO\rLINETHREE" >CRLF_mix_CR &&
382 printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONEQ\r\nLINETWO\r\nLINETHREE" | q_to_nul >CRLF_nul &&
383 printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONEQ\nLINETWO\nLINETHREE" | q_to_nul >LF_nul &&
384 create_NNO_MIX_files &&
385 git -c core.autocrlf=false add NNO_*.txt MIX_*.txt &&
386 git commit -m "mixed line endings" &&
387 test_tick
392 warn_LF_CRLF="LF will be replaced by CRLF"
393 warn_CRLF_LF="CRLF will be replaced by LF"
395 # WILC stands for "Warn if (this OS) converts LF into CRLF".
396 # WICL: Warn if CRLF becomes LF
397 # WAMIX: Mixed line endings: either CRLF->LF or LF->CRLF
398 if test_have_prereq NATIVE_CRLF
399 then
400 WILC=LF_CRLF
401 WICL=
402 WAMIX=LF_CRLF
403 else
404 WILC=
405 WICL=CRLF_LF
406 WAMIX=CRLF_LF
409 # attr LF CRLF CRLFmixLF LFmixCR CRLFNUL
410 test_expect_success 'commit files empty attr' '
411 commit_check_warn false "" "" "" "" "" "" &&
412 commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "" "" &&
413 commit_check_warn input "" "" "CRLF_LF" "CRLF_LF" "" ""
416 test_expect_success 'commit files attr=auto' '
417 commit_check_warn false "auto" "$WILC" "$WICL" "$WAMIX" "" "" &&
418 commit_check_warn true "auto" "LF_CRLF" "" "LF_CRLF" "" "" &&
419 commit_check_warn input "auto" "" "CRLF_LF" "CRLF_LF" "" ""
422 test_expect_success 'commit files attr=text' '
423 commit_check_warn false "text" "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" &&
424 commit_check_warn true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
425 commit_check_warn input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
428 test_expect_success 'commit files attr=-text' '
429 commit_check_warn false "-text" "" "" "" "" "" &&
430 commit_check_warn true "-text" "" "" "" "" "" &&
431 commit_check_warn input "-text" "" "" "" "" ""
434 test_expect_success 'commit files attr=lf' '
435 commit_check_warn false "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
436 commit_check_warn true "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
437 commit_check_warn input "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
440 test_expect_success 'commit files attr=crlf' '
441 commit_check_warn false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
442 commit_check_warn true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
443 commit_check_warn input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" ""
446 # Commit "CRLFmixLF" on top of these files already in the repo:
447 # mixed mixed mixed mixed mixed
448 # onto onto onto onto onto
449 # attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL
450 commit_MIX_chkwrn "" "" false "" "" "" "" ""
451 commit_MIX_chkwrn "" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF"
452 commit_MIX_chkwrn "" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF"
454 commit_MIX_chkwrn "auto" "" false "$WAMIX" "" "" "$WAMIX" "$WAMIX"
455 commit_MIX_chkwrn "auto" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF"
456 commit_MIX_chkwrn "auto" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF"
458 # attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL
459 commit_chk_wrnNNO "" "" false "" "" "" "" ""
460 commit_chk_wrnNNO "" "" true LF_CRLF "" "" "" ""
461 commit_chk_wrnNNO "" "" input "" "" "" "" ""
463 commit_chk_wrnNNO "auto" "" false "$WILC" "" "" "" ""
464 commit_chk_wrnNNO "auto" "" true LF_CRLF "" "" "" ""
465 commit_chk_wrnNNO "auto" "" input "" "" "" "" ""
466 for crlf in true false input
468 commit_chk_wrnNNO -text "" $crlf "" "" "" "" ""
469 commit_chk_wrnNNO -text lf $crlf "" "" "" "" ""
470 commit_chk_wrnNNO -text crlf $crlf "" "" "" "" ""
471 commit_chk_wrnNNO "" lf $crlf "" CRLF_LF CRLF_LF "" CRLF_LF
472 commit_chk_wrnNNO "" crlf $crlf LF_CRLF "" LF_CRLF LF_CRLF ""
473 commit_chk_wrnNNO auto lf $crlf "" "" "" "" ""
474 commit_chk_wrnNNO auto crlf $crlf LF_CRLF "" "" "" ""
475 commit_chk_wrnNNO text lf $crlf "" CRLF_LF CRLF_LF "" CRLF_LF
476 commit_chk_wrnNNO text crlf $crlf LF_CRLF "" LF_CRLF LF_CRLF ""
477 done
479 commit_chk_wrnNNO "text" "" false "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL"
480 commit_chk_wrnNNO "text" "" true LF_CRLF "" LF_CRLF LF_CRLF ""
481 commit_chk_wrnNNO "text" "" input "" CRLF_LF CRLF_LF "" CRLF_LF
483 test_expect_success 'commit NNO and cleanup' '
484 git commit -m "commit files on top of NNO" &&
485 rm -f *.txt &&
486 git -c core.autocrlf=false reset --hard
489 test_expect_success 'commit empty gitattribues' '
490 check_files_in_repo false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
491 check_files_in_repo true "" LF LF LF LF_mix_CR CRLF_nul &&
492 check_files_in_repo input "" LF LF LF LF_mix_CR CRLF_nul
495 test_expect_success 'commit text=auto' '
496 check_files_in_repo false "auto" LF LF LF LF_mix_CR CRLF_nul &&
497 check_files_in_repo true "auto" LF LF LF LF_mix_CR CRLF_nul &&
498 check_files_in_repo input "auto" LF LF LF LF_mix_CR CRLF_nul
501 test_expect_success 'commit text' '
502 check_files_in_repo false "text" LF LF LF LF_mix_CR LF_nul &&
503 check_files_in_repo true "text" LF LF LF LF_mix_CR LF_nul &&
504 check_files_in_repo input "text" LF LF LF LF_mix_CR LF_nul
507 test_expect_success 'commit -text' '
508 check_files_in_repo false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
509 check_files_in_repo true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
510 check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
513 for crlf in true false input
515 # attr aeol LF CRLF CRLF_mix_LF LF_mix_CR CRLFNUL
516 check_in_repo_NNO "" "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
517 check_in_repo_NNO -text "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
518 check_in_repo_NNO -text lf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
519 check_in_repo_NNO -text crlf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
520 check_in_repo_NNO auto "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
521 check_in_repo_NNO auto lf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
522 check_in_repo_NNO auto crlf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
523 check_in_repo_NNO text "" $crlf LF LF LF LF_mix_CR LF_nul
524 check_in_repo_NNO text lf $crlf LF LF LF LF_mix_CR LF_nul
525 check_in_repo_NNO text crlf $crlf LF LF LF LF_mix_CR LF_nul
526 done
527 ################################################################################
528 # Check how files in the repo are changed when they are checked out
529 # How to read the table below:
530 # - checkout_files will check multiple files with a combination of settings
531 # and attributes (core.autocrlf=input is forbidden with core.eol=crlf)
533 # - parameter $1 : text in .gitattributs "" (empty) | auto | text | -text
534 # - parameter $2 : ident "" | i (i == ident)
535 # - parameter $3 : eol in .gitattributs "" (empty) | lf | crlf
536 # - parameter $4 : core.autocrlf false | true | input
537 # - parameter $5 : core.eol "" | lf | crlf | "native"
538 # - parameter $6 : reference for a file with only LF in the repo
539 # - parameter $7 : reference for a file with only CRLF in the repo
540 # - parameter $8 : reference for a file with mixed LF and CRLF in the repo
541 # - parameter $9 : reference for a file with LF and CR in the repo
542 # - parameter $10 : reference for a file with CRLF and a NUL (should be handled as binary when auto)
544 if test_have_prereq NATIVE_CRLF
545 then
546 MIX_CRLF_LF=CRLF
547 MIX_LF_CR=CRLF_mix_CR
548 NL=CRLF
549 LFNUL=CRLF_nul
550 else
551 MIX_CRLF_LF=CRLF_mix_LF
552 MIX_LF_CR=LF_mix_CR
553 NL=LF
554 LFNUL=LF_nul
556 export CRLF_MIX_LF_CR MIX NL
558 # Same handling with and without ident
559 for id in "" ident
561 for ceol in lf crlf native
563 for crlf in true false input
565 # -text overrides core.autocrlf and core.eol
566 # text and eol=crlf or eol=lf override core.autocrlf and core.eol
567 checkout_files -text "$id" "" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
568 checkout_files -text "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
569 checkout_files -text "$id" "crlf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
570 # text
571 checkout_files text "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
572 checkout_files text "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
573 # currently the same as text, eol=XXX
574 checkout_files auto "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
575 checkout_files auto "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
576 done
578 # core.autocrlf false, different core.eol
579 checkout_files "" "$id" "" false "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
580 # core.autocrlf true
581 checkout_files "" "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
582 # text: core.autocrlf = true overrides core.eol
583 checkout_files auto "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
584 checkout_files text "$id" "" true "$ceol" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
585 # text: core.autocrlf = input overrides core.eol
586 checkout_files text "$id" "" input "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
587 checkout_files auto "$id" "" input "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
588 # text=auto + eol=XXX
589 done
590 # text: core.autocrlf=false uses core.eol
591 checkout_files text "$id" "" false crlf CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
592 checkout_files text "$id" "" false lf LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
593 # text: core.autocrlf=false and core.eol unset(or native) uses native eol
594 checkout_files text "$id" "" false "" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL
595 checkout_files text "$id" "" false native $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL
596 # auto: core.autocrlf=false and core.eol unset(or native) uses native eol
597 checkout_files auto "$id" "" false "" $NL CRLF CRLF_mix_LF LF_mix_CR LF_nul
598 checkout_files auto "$id" "" false native $NL CRLF CRLF_mix_LF LF_mix_CR LF_nul
599 # core.autocrlf false, .gitattributes sets eol
600 checkout_files "" "$id" "lf" false "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
601 checkout_files "" "$id" "crlf" false "" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
602 # core.autocrlf true, .gitattributes sets eol
603 checkout_files "" "$id" "lf" true "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
604 checkout_files "" "$id" "crlf" true "" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
605 done
607 # Should be the last test case: remove some files from the worktree
608 test_expect_success 'ls-files --eol -d -z' '
609 rm crlf_false_attr__CRLF.txt crlf_false_attr__CRLF_mix_LF.txt crlf_false_attr__LF.txt .gitattributes &&
610 cat >expect <<-\EOF &&
611 i/crlf w/ crlf_false_attr__CRLF.txt
612 i/lf w/ .gitattributes
613 i/lf w/ crlf_false_attr__LF.txt
614 i/mixed w/ crlf_false_attr__CRLF_mix_LF.txt
616 git ls-files --eol -d >tmp &&
617 sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" tmp |
618 sort >actual &&
619 test_cmp expect actual
622 test_done