Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t0027-auto-crlf.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t0027-auto-crlf.sh` 631 lines ยท 23924 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='CRLF conversion all combinations' 4 5 . ./test-lib.sh 6 7 compare_files () { 8 tr '\015\000' QN <"$1" >"$1".expect && 9 tr '\015\000' QN <"$2" | tr -d 'Z' >"$2".actual && 10 test_cmp "$1".expect "$2".actual && 11 rm "$1".expect "$2".actual 12 } 13 14 compare_ws_file () { 15 pfx=$1 16 exp=$2.expect 17 act=$pfx.actual.$3 18 tr '\015\`000abcdef0123456789`' QN00000000000000000 <"$2" | 19 sed -e "s/0000*/$ZERO_OID/" >"$exp" && 20 tr '\015\`000abcdef0123456789`' QN00000000000000000 <"$3" | 21 sed -e "s/0000*/$ZERO_OID/" >"$act" && 22 test_cmp "$exp" "$act" && 23 rm "$exp" "$act" 24 } 25 26 create_gitattributes () { 27 { 28 while test "$#" != 0 29 do 30 case "$1" in 31 auto) echo '*.txt text=auto' ;; 32 ident) echo '*.txt ident' ;; 33 text) echo '*.txt text' ;; 34 -text) echo '*.txt -text' ;; 35 crlf) echo '*.txt eol=crlf' ;; 36 lf) echo '*.txt eol=lf' ;; 37 "") ;; 38 *) 39 echo >&2 invalid attribute: "$1" 40 exit 1 41 ;; 42 esac && 43 shift 44 done 45 } >.gitattributes 46 } 47 48 # Create 2 sets of files: 49 # The NNO files are "Not NOrmalized in the repo. We use CRLF_mix_LF and store 50 # it under different names for the different test cases, see ${pfx} 51 # Depending on .gitattributes they are normalized at the next commit (or not) 52 # The MIX files have different contents in the repo. 53 # Depending on its contents, the "new safer autocrlf" may kick in. 54 create_NNO_MIX_files () { 55 for crlf in false true input 56 do 57 for attr in "" auto text -text 58 do 59 for aeol in "" lf crlf 60 do 61 pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} && 62 cp CRLF_mix_LF ${pfx}_LF.txt && 63 cp CRLF_mix_LF ${pfx}_CRLF.txt && 64 cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt && 65 cp CRLF_mix_LF ${pfx}_LF_mix_CR.txt && 66 cp CRLF_mix_LF ${pfx}_CRLF_nul.txt && 67 pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf} && 68 cp LF ${pfx}_LF.txt && 69 cp CRLF ${pfx}_CRLF.txt && 70 cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt && 71 cp LF_mix_CR ${pfx}_LF_mix_CR.txt && 72 cp CRLF_nul ${pfx}_CRLF_nul.txt || 73 return 1 74 done 75 done 76 done 77 } 78 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 88 } 89 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 101 do 102 fname=${pfx}_$f.txt && 103 cp $f $fname && 104 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || 105 return 1 106 done && 107 git commit -m "core.autocrlf $crlf" && 108 check_warning "$lfname" ${pfx}_LF.err && 109 check_warning "$crlfname" ${pfx}_CRLF.err && 110 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err && 111 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err && 112 check_warning "$crlfnul" ${pfx}_CRLF_nul.err 113 } 114 115 commit_chk_wrnNNO () { 116 attr=$1 ; shift 117 aeol=$1 ; shift 118 crlf=$1 ; shift 119 lfwarn=$1 ; shift 120 crlfwarn=$1 ; shift 121 lfmixcrlf=$1 ; shift 122 lfmixcr=$1 ; shift 123 crlfnul=$1 ; shift 124 pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} 125 126 test_expect_success 'setup commit NNO files' ' 127 #Commit files on top of existing file 128 create_gitattributes "$attr" $aeol && 129 for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 130 do 131 fname=${pfx}_$f.txt && 132 cp $f $fname && 133 printf Z >>"$fname" && 134 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || 135 return 1 136 done 137 ' 138 139 test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" ' 140 check_warning "$lfwarn" ${pfx}_LF.err 141 ' 142 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF" ' 143 check_warning "$crlfwarn" ${pfx}_CRLF.err 144 ' 145 146 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_mix_LF" ' 147 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err 148 ' 149 150 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf LF_mix_cr" ' 151 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err 152 ' 153 154 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_nul" ' 155 check_warning "$crlfnul" ${pfx}_CRLF_nul.err 156 ' 157 } 158 159 # Commit a file with mixed line endings on top of different files 160 # in the index. Check for warnings 161 commit_MIX_chkwrn () { 162 attr=$1 ; shift 163 aeol=$1 ; shift 164 crlf=$1 ; shift 165 lfwarn=$1 ; shift 166 crlfwarn=$1 ; shift 167 lfmixcrlf=$1 ; shift 168 lfmixcr=$1 ; shift 169 crlfnul=$1 ; shift 170 pfx=MIX_attr_${attr}_aeol_${aeol}_${crlf} 171 172 test_expect_success 'setup commit file with mixed EOL' ' 173 #Commit file with CLRF_mix_LF on top of existing file 174 create_gitattributes "$attr" $aeol && 175 for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 176 do 177 fname=${pfx}_$f.txt && 178 cp CRLF_mix_LF $fname && 179 printf Z >>"$fname" && 180 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" || 181 return 1 182 done 183 ' 184 185 test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" ' 186 check_warning "$lfwarn" ${pfx}_LF.err 187 ' 188 test_expect_success "commit file with mixed EOL onto CLRF attr=$attr aeol=$aeol crlf=$crlf" ' 189 check_warning "$crlfwarn" ${pfx}_CRLF.err 190 ' 191 192 test_expect_success "commit file with mixed EOL onto CRLF_mix_LF attr=$attr aeol=$aeol crlf=$crlf" ' 193 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err 194 ' 195 196 test_expect_success "commit file with mixed EOL onto LF_mix_cr attr=$attr aeol=$aeol crlf=$crlf " ' 197 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err 198 ' 199 200 test_expect_success "commit file with mixed EOL onto CRLF_nul attr=$attr aeol=$aeol crlf=$crlf" ' 201 check_warning "$crlfnul" ${pfx}_CRLF_nul.err 202 ' 203 } 204 205 206 stats_ascii () { 207 case "$1" in 208 LF) 209 echo lf 210 ;; 211 CRLF) 212 echo crlf 213 ;; 214 CRLF_mix_LF) 215 echo mixed 216 ;; 217 LF_mix_CR|CRLF_nul|LF_nul|CRLF_mix_CR) 218 echo "-text" 219 ;; 220 *) 221 echo error_invalid $1 222 ;; 223 esac 224 225 } 226 227 228 # construct the attr/ returned by git ls-files --eol 229 # Take none (=empty), one or two args 230 # convert.c: eol=XX overrides text=auto 231 attr_ascii () { 232 case $1,$2 in 233 -text,*) echo "-text" ;; 234 text,) echo "text" ;; 235 text,lf) echo "text eol=lf" ;; 236 text,crlf) echo "text eol=crlf" ;; 237 auto,) echo "text=auto" ;; 238 auto,lf) echo "text=auto eol=lf" ;; 239 auto,crlf) echo "text=auto eol=crlf" ;; 240 lf,) echo "text eol=lf" ;; 241 crlf,) echo "text eol=crlf" ;; 242 ,) echo "" ;; 243 *) echo invalid_attr "$1,$2" ;; 244 esac 245 } 246 247 check_files_in_repo () { 248 crlf=$1 249 attr=$2 250 lfname=$3 251 crlfname=$4 252 lfmixcrlf=$5 253 lfmixcr=$6 254 crlfnul=$7 255 pfx=crlf_${crlf}_attr_${attr}_ && 256 compare_files $lfname ${pfx}LF.txt && 257 compare_files $crlfname ${pfx}CRLF.txt && 258 compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt && 259 compare_files $lfmixcr ${pfx}LF_mix_CR.txt && 260 compare_files $crlfnul ${pfx}CRLF_nul.txt 261 } 262 263 check_in_repo_NNO () { 264 attr=$1 ; shift 265 aeol=$1 ; shift 266 crlf=$1 ; shift 267 lfname=$1 ; shift 268 crlfname=$1 ; shift 269 lfmixcrlf=$1 ; shift 270 lfmixcr=$1 ; shift 271 crlfnul=$1 ; shift 272 pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} 273 test_expect_success "compare_files $lfname ${pfx}_LF.txt" ' 274 compare_files $lfname ${pfx}_LF.txt 275 ' 276 test_expect_success "compare_files $crlfname ${pfx}_CRLF.txt" ' 277 compare_files $crlfname ${pfx}_CRLF.txt 278 ' 279 test_expect_success "compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt" ' 280 compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt 281 ' 282 test_expect_success "compare_files $lfmixcr ${pfx}_LF_mix_CR.txt" ' 283 compare_files $lfmixcr ${pfx}_LF_mix_CR.txt 284 ' 285 test_expect_success "compare_files $crlfnul ${pfx}_CRLF_nul.txt" ' 286 compare_files $crlfnul ${pfx}_CRLF_nul.txt 287 ' 288 } 289 290 checkout_files () { 291 attr=$1 ; shift 292 ident=$1; shift 293 aeol=$1 ; shift 294 crlf=$1 ; shift 295 ceol=$1 ; shift 296 lfname=$1 ; shift 297 crlfname=$1 ; shift 298 lfmixcrlf=$1 ; shift 299 lfmixcr=$1 ; shift 300 crlfnul=$1 ; shift 301 test_expect_success "setup config for checkout attr=$attr ident=$ident aeol=$aeol core.autocrlf=$crlf" ' 302 create_gitattributes "$attr" $ident $aeol && 303 git config core.autocrlf $crlf 304 ' 305 pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ && 306 for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul 307 do 308 test_expect_success "setup $f checkout ${ceol:+ with -c core.eol=$ceol}" ' 309 rm -f crlf_false_attr__$f.txt && 310 git ${ceol:+-c core.eol=$ceol} checkout -- crlf_false_attr__$f.txt 311 ' 312 done 313 314 test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" ' 315 test_when_finished "rm expect actual" && 316 sort <<-EOF >expect && 317 i/crlf w/$(stats_ascii $crlfname) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF.txt 318 i/mixed w/$(stats_ascii $lfmixcrlf) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_mix_LF.txt 319 i/lf w/$(stats_ascii $lfname) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF.txt 320 i/-text w/$(stats_ascii $lfmixcr) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_mix_CR.txt 321 i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_nul.txt 322 i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_nul.txt 323 EOF 324 git ls-files --eol crlf_false_attr__* >tmp && 325 sed -e "s/ / /g" -e "s/ */ /g" tmp | 326 sort >actual && 327 test_cmp expect actual 328 ' 329 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF" " 330 compare_ws_file $pfx $lfname crlf_false_attr__LF.txt 331 " 332 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF" " 333 compare_ws_file $pfx $crlfname crlf_false_attr__CRLF.txt 334 " 335 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF_mix_LF" " 336 compare_ws_file $pfx $lfmixcrlf crlf_false_attr__CRLF_mix_LF.txt 337 " 338 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_mix_CR" " 339 compare_ws_file $pfx $lfmixcr crlf_false_attr__LF_mix_CR.txt 340 " 341 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_nul" " 342 compare_ws_file $pfx $crlfnul crlf_false_attr__LF_nul.txt 343 " 344 } 345 346 # Test control characters 347 # NUL SOH CR EOF==^Z 348 test_expect_success 'ls-files --eol -o Text/Binary' ' 349 test_when_finished "rm expect actual TeBi_*" && 350 STRT=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA && 351 STR=$STRT$STRT$STRT$STRT && 352 printf "${STR}BBB\001" >TeBi_127_S && 353 printf "${STR}BBBB\001">TeBi_128_S && 354 printf "${STR}BBB\032" >TeBi_127_E && 355 printf "\032${STR}BBB" >TeBi_E_127 && 356 printf "${STR}BBBB\000">TeBi_128_N && 357 printf "${STR}BBB\012">TeBi_128_L && 358 printf "${STR}BBB\015">TeBi_127_C && 359 printf "${STR}BB\015\012" >TeBi_126_CL && 360 printf "${STR}BB\015\012\015" >TeBi_126_CLC && 361 sort <<-\EOF >expect && 362 i/ w/-text TeBi_127_S 363 i/ w/none TeBi_128_S 364 i/ w/none TeBi_127_E 365 i/ w/-text TeBi_E_127 366 i/ w/-text TeBi_128_N 367 i/ w/lf TeBi_128_L 368 i/ w/-text TeBi_127_C 369 i/ w/crlf TeBi_126_CL 370 i/ w/-text TeBi_126_CLC 371 EOF 372 git ls-files --eol -o >tmp && 373 sed -n -e "/TeBi_/{s!attr/[ ]*!!g 374 s! ! !g 375 s! *! !g 376 p 377 }" tmp | sort >actual && 378 test_cmp expect actual 379 ' 380 381 test_expect_success 'setup main' ' 382 echo >.gitattributes && 383 git checkout -b main && 384 git add .gitattributes && 385 git commit -m "add .gitattributes" . && 386 printf "\$Id: `0000000000000000000000000000000000000000` \$\nLINEONE\nLINETWO\nLINETHREE" >LF && 387 printf "\$Id: `0000000000000000000000000000000000000000` \$\r\nLINEONE\r\nLINETWO\r\nLINETHREE" >CRLF && 388 printf "\$Id: `0000000000000000000000000000000000000000` \$\nLINEONE\r\nLINETWO\nLINETHREE" >CRLF_mix_LF && 389 printf "\$Id: `0000000000000000000000000000000000000000` \$\nLINEONE\nLINETWO\rLINETHREE" >LF_mix_CR && 390 printf "\$Id: `0000000000000000000000000000000000000000` \$\r\nLINEONE\r\nLINETWO\rLINETHREE" >CRLF_mix_CR && 391 printf "\$Id: `0000000000000000000000000000000000000000` \$\r\nLINEONEQ\r\nLINETWO\r\nLINETHREE" | q_to_nul >CRLF_nul && 392 printf "\$Id: `0000000000000000000000000000000000000000` \$\nLINEONEQ\nLINETWO\nLINETHREE" | q_to_nul >LF_nul && 393 create_NNO_MIX_files && 394 git -c core.autocrlf=false add NNO_*.txt MIX_*.txt && 395 git commit -m "mixed line endings" && 396 test_tick 397 ' 398 399 400 401 warn_LF_CRLF="LF will be replaced by CRLF" 402 warn_CRLF_LF="CRLF will be replaced by LF" 403 404 # WILC stands for "Warn if (this OS) converts LF into CRLF". 405 # WICL: Warn if CRLF becomes LF 406 # WAMIX: Mixed line endings: either CRLF->LF or LF->CRLF 407 if test_have_prereq NATIVE_CRLF 408 then 409 WILC=LF_CRLF 410 WICL= 411 WAMIX=LF_CRLF 412 else 413 WILC= 414 WICL=CRLF_LF 415 WAMIX=CRLF_LF 416 fi 417 418 # attr LF CRLF CRLFmixLF LFmixCR CRLFNUL 419 test_expect_success 'commit files empty attr' ' 420 commit_check_warn false "" "" "" "" "" "" && 421 commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "" "" && 422 commit_check_warn input "" "" "CRLF_LF" "CRLF_LF" "" "" 423 ' 424 425 test_expect_success 'commit files attr=auto' ' 426 commit_check_warn false "auto" "$WILC" "$WICL" "$WAMIX" "" "" && 427 commit_check_warn true "auto" "LF_CRLF" "" "LF_CRLF" "" "" && 428 commit_check_warn input "auto" "" "CRLF_LF" "CRLF_LF" "" "" 429 ' 430 431 test_expect_success 'commit files attr=text' ' 432 commit_check_warn false "text" "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" && 433 commit_check_warn true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && 434 commit_check_warn input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" 435 ' 436 437 test_expect_success 'commit files attr=-text' ' 438 commit_check_warn false "-text" "" "" "" "" "" && 439 commit_check_warn true "-text" "" "" "" "" "" && 440 commit_check_warn input "-text" "" "" "" "" "" 441 ' 442 443 test_expect_success 'commit files attr=lf' ' 444 commit_check_warn false "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" && 445 commit_check_warn true "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" && 446 commit_check_warn input "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" 447 ' 448 449 test_expect_success 'commit files attr=crlf' ' 450 commit_check_warn false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && 451 commit_check_warn true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && 452 commit_check_warn input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" 453 ' 454 455 # Commit "CRLFmixLF" on top of these files already in the repo: 456 # mixed mixed mixed mixed mixed 457 # onto onto onto onto onto 458 # attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL 459 commit_MIX_chkwrn "" "" false "" "" "" "" "" 460 commit_MIX_chkwrn "" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF" 461 commit_MIX_chkwrn "" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF" 462 463 commit_MIX_chkwrn "auto" "" false "$WAMIX" "" "" "$WAMIX" "$WAMIX" 464 commit_MIX_chkwrn "auto" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF" 465 commit_MIX_chkwrn "auto" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF" 466 467 # attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL 468 commit_chk_wrnNNO "" "" false "" "" "" "" "" 469 commit_chk_wrnNNO "" "" true LF_CRLF "" "" "" "" 470 commit_chk_wrnNNO "" "" input "" "" "" "" "" 471 472 commit_chk_wrnNNO "auto" "" false "$WILC" "" "" "" "" 473 commit_chk_wrnNNO "auto" "" true LF_CRLF "" "" "" "" 474 commit_chk_wrnNNO "auto" "" input "" "" "" "" "" 475 for crlf in true false input 476 do 477 commit_chk_wrnNNO -text "" $crlf "" "" "" "" "" 478 commit_chk_wrnNNO -text lf $crlf "" "" "" "" "" 479 commit_chk_wrnNNO -text crlf $crlf "" "" "" "" "" 480 commit_chk_wrnNNO "" lf $crlf "" CRLF_LF CRLF_LF "" CRLF_LF 481 commit_chk_wrnNNO "" crlf $crlf LF_CRLF "" LF_CRLF LF_CRLF "" 482 commit_chk_wrnNNO auto lf $crlf "" "" "" "" "" 483 commit_chk_wrnNNO auto crlf $crlf LF_CRLF "" "" "" "" 484 commit_chk_wrnNNO text lf $crlf "" CRLF_LF CRLF_LF "" CRLF_LF 485 commit_chk_wrnNNO text crlf $crlf LF_CRLF "" LF_CRLF LF_CRLF "" 486 done 487 488 commit_chk_wrnNNO "text" "" false "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" 489 commit_chk_wrnNNO "text" "" true LF_CRLF "" LF_CRLF LF_CRLF "" 490 commit_chk_wrnNNO "text" "" input "" CRLF_LF CRLF_LF "" CRLF_LF 491 492 test_expect_success 'commit NNO and cleanup' ' 493 git commit -m "commit files on top of NNO" && 494 rm -f *.txt && 495 git -c core.autocrlf=false reset --hard 496 ' 497 498 test_expect_success 'commit empty gitattribues' ' 499 check_files_in_repo false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && 500 check_files_in_repo true "" LF LF LF LF_mix_CR CRLF_nul && 501 check_files_in_repo input "" LF LF LF LF_mix_CR CRLF_nul 502 ' 503 504 test_expect_success 'commit text=auto' ' 505 check_files_in_repo false "auto" LF LF LF LF_mix_CR CRLF_nul && 506 check_files_in_repo true "auto" LF LF LF LF_mix_CR CRLF_nul && 507 check_files_in_repo input "auto" LF LF LF LF_mix_CR CRLF_nul 508 ' 509 510 test_expect_success 'commit text' ' 511 check_files_in_repo false "text" LF LF LF LF_mix_CR LF_nul && 512 check_files_in_repo true "text" LF LF LF LF_mix_CR LF_nul && 513 check_files_in_repo input "text" LF LF LF LF_mix_CR LF_nul 514 ' 515 516 test_expect_success 'commit -text' ' 517 check_files_in_repo false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && 518 check_files_in_repo true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && 519 check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 520 ' 521 522 for crlf in true false input 523 do 524 # attr aeol LF CRLF CRLF_mix_LF LF_mix_CR CRLFNUL 525 check_in_repo_NNO "" "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 526 check_in_repo_NNO -text "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 527 check_in_repo_NNO -text lf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 528 check_in_repo_NNO -text crlf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 529 check_in_repo_NNO auto "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 530 check_in_repo_NNO auto lf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 531 check_in_repo_NNO auto crlf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul 532 check_in_repo_NNO text "" $crlf LF LF LF LF_mix_CR LF_nul 533 check_in_repo_NNO text lf $crlf LF LF LF LF_mix_CR LF_nul 534 check_in_repo_NNO text crlf $crlf LF LF LF LF_mix_CR LF_nul 535 done 536 ################################################################################ 537 # Check how files in the repo are changed when they are checked out 538 # How to read the table below: 539 # - checkout_files will check multiple files with a combination of settings 540 # and attributes (core.autocrlf=input is forbidden with core.eol=crlf) 541 # 542 # - parameter $1 : text in .gitattributs "" (empty) | auto | text | -text 543 # - parameter $2 : ident "" | i (i == ident) 544 # - parameter $3 : eol in .gitattributs "" (empty) | lf | crlf 545 # - parameter $4 : core.autocrlf false | true | input 546 # - parameter $5 : core.eol "" | lf | crlf | "native" 547 # - parameter $6 : reference for a file with only LF in the repo 548 # - parameter $7 : reference for a file with only CRLF in the repo 549 # - parameter $8 : reference for a file with mixed LF and CRLF in the repo 550 # - parameter $9 : reference for a file with LF and CR in the repo 551 # - parameter $10 : reference for a file with CRLF and a NUL (should be handled as binary when auto) 552 553 if test_have_prereq NATIVE_CRLF 554 then 555 MIX_CRLF_LF=CRLF 556 MIX_LF_CR=CRLF_mix_CR 557 NL=CRLF 558 LFNUL=CRLF_nul 559 else 560 MIX_CRLF_LF=CRLF_mix_LF 561 MIX_LF_CR=LF_mix_CR 562 NL=LF 563 LFNUL=LF_nul 564 fi 565 export CRLF_MIX_LF_CR MIX NL 566 567 # Same handling with and without ident 568 for id in "" ident 569 do 570 for ceol in lf crlf native 571 do 572 for crlf in true false input 573 do 574 # -text overrides core.autocrlf and core.eol 575 # text and eol=crlf or eol=lf override core.autocrlf and core.eol 576 checkout_files -text "$id" "" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 577 checkout_files -text "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 578 checkout_files -text "$id" "crlf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 579 # text 580 checkout_files text "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 581 checkout_files text "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul 582 # currently the same as text, eol=XXX 583 checkout_files auto "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 584 checkout_files auto "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul 585 done 586 587 # core.autocrlf false, different core.eol 588 checkout_files "" "$id" "" false "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 589 # core.autocrlf true 590 checkout_files "" "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul 591 # text: core.autocrlf = true overrides core.eol 592 checkout_files auto "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul 593 checkout_files text "$id" "" true "$ceol" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul 594 # text: core.autocrlf = input overrides core.eol 595 checkout_files text "$id" "" input "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 596 checkout_files auto "$id" "" input "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 597 # text=auto + eol=XXX 598 done 599 # text: core.autocrlf=false uses core.eol 600 checkout_files text "$id" "" false crlf CRLF CRLF CRLF CRLF_mix_CR CRLF_nul 601 checkout_files text "$id" "" false lf LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 602 # text: core.autocrlf=false and core.eol unset(or native) uses native eol 603 checkout_files text "$id" "" false "" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL 604 checkout_files text "$id" "" false native $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL 605 # auto: core.autocrlf=false and core.eol unset(or native) uses native eol 606 checkout_files auto "$id" "" false "" $NL CRLF CRLF_mix_LF LF_mix_CR LF_nul 607 checkout_files auto "$id" "" false native $NL CRLF CRLF_mix_LF LF_mix_CR LF_nul 608 # core.autocrlf false, .gitattributes sets eol 609 checkout_files "" "$id" "lf" false "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 610 checkout_files "" "$id" "crlf" false "" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul 611 # core.autocrlf true, .gitattributes sets eol 612 checkout_files "" "$id" "lf" true "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul 613 checkout_files "" "$id" "crlf" true "" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul 614 done 615 616 # Should be the last test case: remove some files from the worktree 617 test_expect_success 'ls-files --eol -d -z' ' 618 rm crlf_false_attr__CRLF.txt crlf_false_attr__CRLF_mix_LF.txt crlf_false_attr__LF.txt .gitattributes && 619 cat >expect <<-\EOF && 620 i/crlf w/ crlf_false_attr__CRLF.txt 621 i/lf w/ .gitattributes 622 i/lf w/ crlf_false_attr__LF.txt 623 i/mixed w/ crlf_false_attr__CRLF_mix_LF.txt 624 EOF 625 git ls-files --eol -d >tmp && 626 sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" tmp | 627 sort >actual && 628 test_cmp expect actual 629 ' 630 631 test_done