]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0027-auto-crlf.sh
auto-crlf tests: don't lose exit code in loops and outside tests
[thirdparty/git.git] / t / t0027-auto-crlf.sh
CommitLineData
343151dc
TB
1#!/bin/sh
2
3test_description='CRLF conversion all combinations'
4
3e3b9321 5TEST_PASSES_SANITIZE_LEAK=true
343151dc
TB
6. ./test-lib.sh
7
f6975a6b
TB
8compare_files () {
9 tr '\015\000' QN <"$1" >"$1".expect &&
ded2444a 10 tr '\015\000' QN <"$2" | tr -d 'Z' >"$2".actual &&
343151dc
TB
11 test_cmp "$1".expect "$2".actual &&
12 rm "$1".expect "$2".actual
13}
14
f6975a6b 15compare_ws_file () {
343151dc
TB
16 pfx=$1
17 exp=$2.expect
18 act=$pfx.actual.$3
4772b338 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" &&
320d39cd
TB
23 test_cmp "$exp" "$act" &&
24 rm "$exp" "$act"
343151dc
TB
25}
26
f6975a6b 27create_gitattributes () {
320d39cd
TB
28 {
29 while test "$#" != 0
30 do
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 "") ;;
39 *)
40 echo >&2 invalid attribute: "$1"
41 exit 1
42 ;;
43 esac &&
44 shift
45 done
46 } >.gitattributes
343151dc
TB
47}
48
86ff70a0
TB
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.
55create_NNO_MIX_files () {
710b4e8a
TB
56 for crlf in false true input
57 do
67e9bff0 58 for attr in "" auto text -text
710b4e8a 59 do
67e9bff0
TB
60 for aeol in "" lf crlf
61 do
86ff70a0 62 pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} &&
67e9bff0
TB
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 &&
86ff70a0
TB
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 &&
fb18dd28
ÆAB
73 cp CRLF_nul ${pfx}_CRLF_nul.txt ||
74 return 1
67e9bff0 75 done
710b4e8a
TB
76 done
77 done
78}
79
0291973b
TB
80check_warning () {
81 case "$1" in
c970d30c
AH
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 ;;
d6d6673e 85 *) echo >&2 "Illegal 1": "$1" ; return false ;;
0291973b 86 esac
c970d30c 87 sed -e "s/^.* \([^ ]* will be replaced by [^ ]*\) .*$/\1/" "$2" | uniq >"$2".actual
1108cea7 88 test_cmp "$2".expect "$2".actual
0291973b
TB
89}
90
ad295bbc 91commit_check_warn () {
343151dc 92 crlf=$1
f6975a6b 93 attr=$2
0291973b
TB
94 lfname=$3
95 crlfname=$4
710b4e8a
TB
96 lfmixcrlf=$5
97 lfmixcr=$6
98 crlfnul=$7
0291973b 99 pfx=crlf_${crlf}_attr_${attr}
8eeab92f 100 create_gitattributes "$attr" &&
a7630bd4 101 for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul
343151dc 102 do
0291973b
TB
103 fname=${pfx}_$f.txt &&
104 cp $f $fname &&
fb18dd28
ÆAB
105 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" ||
106 return 1
343151dc 107 done &&
0291973b
TB
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
343151dc
TB
114}
115
710b4e8a 116commit_chk_wrnNNO () {
67e9bff0
TB
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}
fb18dd28
ÆAB
126
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
131 do
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
138 '
710b4e8a
TB
139
140 test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" '
141 check_warning "$lfwarn" ${pfx}_LF.err
142 '
67e9bff0 143 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF" '
710b4e8a
TB
144 check_warning "$crlfwarn" ${pfx}_CRLF.err
145 '
146
67e9bff0 147 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_mix_LF" '
710b4e8a
TB
148 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err
149 '
150
67e9bff0 151 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf LF_mix_cr" '
710b4e8a
TB
152 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err
153 '
154
67e9bff0 155 test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_nul" '
710b4e8a
TB
156 check_warning "$crlfnul" ${pfx}_CRLF_nul.err
157 '
158}
159
86ff70a0
TB
160# Commit a file with mixed line endings on top of different files
161# in the index. Check for warnings
162commit_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}
fb18dd28
ÆAB
172
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
177 do
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
184 '
86ff70a0 185
649f1f09 186 test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" '
86ff70a0
TB
187 check_warning "$lfwarn" ${pfx}_LF.err
188 '
649f1f09 189 test_expect_success "commit file with mixed EOL onto CLRF attr=$attr aeol=$aeol crlf=$crlf" '
86ff70a0
TB
190 check_warning "$crlfwarn" ${pfx}_CRLF.err
191 '
192
649f1f09 193 test_expect_success "commit file with mixed EOL onto CRLF_mix_LF attr=$attr aeol=$aeol crlf=$crlf" '
86ff70a0
TB
194 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err
195 '
196
649f1f09 197 test_expect_success "commit file with mixed EOL onto LF_mix_cr attr=$attr aeol=$aeol crlf=$crlf " '
86ff70a0
TB
198 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err
199 '
200
649f1f09 201 test_expect_success "commit file with mixed EOL onto CRLF_nul attr=$attr aeol=$aeol crlf=$crlf" '
86ff70a0
TB
202 check_warning "$crlfnul" ${pfx}_CRLF_nul.err
203 '
204}
205
206
a7630bd4
TB
207stats_ascii () {
208 case "$1" in
209 LF)
210 echo lf
211 ;;
212 CRLF)
213 echo crlf
214 ;;
215 CRLF_mix_LF)
216 echo mixed
217 ;;
218 LF_mix_CR|CRLF_nul|LF_nul|CRLF_mix_CR)
219 echo "-text"
220 ;;
221 *)
222 echo error_invalid $1
223 ;;
224 esac
225
226}
227
817a0c79 228
7a40cf15 229# construct the attr/ returned by git ls-files --eol
817a0c79 230# Take none (=empty), one or two args
67e9bff0 231# convert.c: eol=XX overrides text=auto
817a0c79
TB
232attr_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" ;;
65237284
TB
239 auto,lf) echo "text=auto eol=lf" ;;
240 auto,crlf) echo "text=auto eol=crlf" ;;
817a0c79
TB
241 lf,) echo "text eol=lf" ;;
242 crlf,) echo "text eol=crlf" ;;
243 ,) echo "" ;;
244 *) echo invalid_attr "$1,$2" ;;
245 esac
246}
247
f6975a6b 248check_files_in_repo () {
343151dc 249 crlf=$1
f6975a6b 250 attr=$2
343151dc
TB
251 lfname=$3
252 crlfname=$4
253 lfmixcrlf=$5
254 lfmixcr=$6
255 crlfnul=$7
f6975a6b 256 pfx=crlf_${crlf}_attr_${attr}_ &&
343151dc
TB
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
262}
263
710b4e8a 264check_in_repo_NNO () {
67e9bff0
TB
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
710b4e8a 276 '
67e9bff0
TB
277 test_expect_success "compare_files $crlfname ${pfx}_CRLF.txt" '
278 compare_files $crlfname ${pfx}_CRLF.txt
710b4e8a 279 '
67e9bff0
TB
280 test_expect_success "compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt" '
281 compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt
710b4e8a 282 '
67e9bff0
TB
283 test_expect_success "compare_files $lfmixcr ${pfx}_LF_mix_CR.txt" '
284 compare_files $lfmixcr ${pfx}_LF_mix_CR.txt
710b4e8a 285 '
67e9bff0
TB
286 test_expect_success "compare_files $crlfnul ${pfx}_CRLF_nul.txt" '
287 compare_files $crlfnul ${pfx}_CRLF_nul.txt
710b4e8a
TB
288 '
289}
343151dc 290
ad295bbc 291checkout_files () {
320d39cd
TB
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
fb18dd28
ÆAB
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
305 '
320d39cd 306 pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ &&
8eeab92f 307 for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul
343151dc 308 do
fb18dd28
ÆAB
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
312 '
343151dc
TB
313 done
314
67e9bff0 315 test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" '
a7630bd4
TB
316 test_when_finished "rm expect actual" &&
317 sort <<-EOF >expect &&
817a0c79
TB
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
a7630bd4 324 EOF
9b6d1fc4
SM
325 git ls-files --eol crlf_false_attr__* >tmp &&
326 sed -e "s/ / /g" -e "s/ */ /g" tmp |
a7630bd4
TB
327 sort >actual &&
328 test_cmp expect actual
329 '
67e9bff0 330 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF" "
a7630bd4 331 compare_ws_file $pfx $lfname crlf_false_attr__LF.txt
343151dc 332 "
67e9bff0 333 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF" "
a7630bd4 334 compare_ws_file $pfx $crlfname crlf_false_attr__CRLF.txt
343151dc 335 "
67e9bff0 336 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF_mix_LF" "
a7630bd4 337 compare_ws_file $pfx $lfmixcrlf crlf_false_attr__CRLF_mix_LF.txt
343151dc 338 "
67e9bff0 339 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_mix_CR" "
a7630bd4 340 compare_ws_file $pfx $lfmixcr crlf_false_attr__LF_mix_CR.txt
343151dc 341 "
67e9bff0 342 test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_nul" "
a7630bd4 343 compare_ws_file $pfx $crlfnul crlf_false_attr__LF_nul.txt
343151dc
TB
344 "
345}
346
a7630bd4
TB
347# Test control characters
348# NUL SOH CR EOF==^Z
349test_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
372 EOF
9b6d1fc4 373 git ls-files --eol -o >tmp &&
a7630bd4
TB
374 sed -n -e "/TeBi_/{s!attr/[ ]*!!g
375 s! ! !g
376 s! *! !g
377 p
9b6d1fc4 378 }" tmp | sort >actual &&
a7630bd4
TB
379 test_cmp expect actual
380'
381
06d53148 382test_expect_success 'setup main' '
343151dc 383 echo >.gitattributes &&
06d53148 384 git checkout -b main &&
343151dc 385 git add .gitattributes &&
229a95aa 386 git commit -m "add .gitattributes" . &&
320d39cd
TB
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 &&
649f1f09 394 create_NNO_MIX_files &&
86ff70a0 395 git -c core.autocrlf=false add NNO_*.txt MIX_*.txt &&
710b4e8a
TB
396 git commit -m "mixed line endings" &&
397 test_tick
343151dc 398'
f6975a6b 399
9fd91123 400
343151dc 401
0291973b
TB
402warn_LF_CRLF="LF will be replaced by CRLF"
403warn_CRLF_LF="CRLF will be replaced by LF"
404
d6d6673e
TB
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
408if test_have_prereq NATIVE_CRLF
409then
410 WILC=LF_CRLF
411 WICL=
412 WAMIX=LF_CRLF
413else
414 WILC=
415 WICL=CRLF_LF
416 WAMIX=CRLF_LF
417fi
418
710b4e8a 419# attr LF CRLF CRLFmixLF LFmixCR CRLFNUL
ad295bbc 420test_expect_success 'commit files empty attr' '
710b4e8a
TB
421 commit_check_warn false "" "" "" "" "" "" &&
422 commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "" "" &&
423 commit_check_warn input "" "" "CRLF_LF" "CRLF_LF" "" ""
0291973b
TB
424'
425
ad295bbc 426test_expect_success 'commit files attr=auto' '
710b4e8a
TB
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" "" ""
0291973b
TB
430'
431
ad295bbc 432test_expect_success 'commit files attr=text' '
710b4e8a
TB
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"
0291973b
TB
436'
437
ad295bbc 438test_expect_success 'commit files attr=-text' '
710b4e8a
TB
439 commit_check_warn false "-text" "" "" "" "" "" &&
440 commit_check_warn true "-text" "" "" "" "" "" &&
441 commit_check_warn input "-text" "" "" "" "" ""
0291973b
TB
442'
443
ad295bbc 444test_expect_success 'commit files attr=lf' '
710b4e8a
TB
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"
0291973b 448'
343151dc 449
ad295bbc 450test_expect_success 'commit files attr=crlf' '
710b4e8a
TB
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" ""
0291973b 454'
343151dc 455
86ff70a0 456# Commit "CRLFmixLF" on top of these files already in the repo:
649f1f09
TB
457# mixed mixed mixed mixed mixed
458# onto onto onto onto onto
86ff70a0
TB
459# attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL
460commit_MIX_chkwrn "" "" false "" "" "" "" ""
461commit_MIX_chkwrn "" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF"
462commit_MIX_chkwrn "" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF"
463
649f1f09 464commit_MIX_chkwrn "auto" "" false "$WAMIX" "" "" "$WAMIX" "$WAMIX"
86ff70a0
TB
465commit_MIX_chkwrn "auto" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF"
466commit_MIX_chkwrn "auto" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF"
467
67e9bff0
TB
468# attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL
469commit_chk_wrnNNO "" "" false "" "" "" "" ""
470commit_chk_wrnNNO "" "" true LF_CRLF "" "" "" ""
471commit_chk_wrnNNO "" "" input "" "" "" "" ""
710b4e8a 472
65237284
TB
473commit_chk_wrnNNO "auto" "" false "$WILC" "" "" "" ""
474commit_chk_wrnNNO "auto" "" true LF_CRLF "" "" "" ""
475commit_chk_wrnNNO "auto" "" input "" "" "" "" ""
67e9bff0
TB
476for crlf in true false input
477do
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 ""
65237284
TB
483 commit_chk_wrnNNO auto lf $crlf "" "" "" "" ""
484 commit_chk_wrnNNO auto crlf $crlf LF_CRLF "" "" "" ""
67e9bff0
TB
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 ""
487done
710b4e8a 488
67e9bff0
TB
489commit_chk_wrnNNO "text" "" false "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL"
490commit_chk_wrnNNO "text" "" true LF_CRLF "" LF_CRLF LF_CRLF ""
491commit_chk_wrnNNO "text" "" input "" CRLF_LF CRLF_LF "" CRLF_LF
710b4e8a 492
a0ad53c1
TB
493test_expect_success 'commit NNO and cleanup' '
494 git commit -m "commit files on top of NNO" &&
343151dc 495 rm -f *.txt &&
710b4e8a 496 git -c core.autocrlf=false reset --hard
343151dc
TB
497'
498
499test_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
503'
504
505test_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
509'
510
511test_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
515'
516
517test_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
521'
522
67e9bff0
TB
523for crlf in true false input
524do
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
65237284
TB
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
67e9bff0
TB
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
536done
343151dc
TB
537################################################################################
538# Check how files in the repo are changed when they are checked out
539# How to read the table below:
ad295bbc 540# - checkout_files will check multiple files with a combination of settings
f6975a6b 541# and attributes (core.autocrlf=input is forbidden with core.eol=crlf)
320d39cd
TB
542#
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)
553
8eeab92f 554if test_have_prereq NATIVE_CRLF
343151dc 555then
f6975a6b
TB
556MIX_CRLF_LF=CRLF
557MIX_LF_CR=CRLF_mix_CR
558NL=CRLF
8eeab92f 559LFNUL=CRLF_nul
f6975a6b
TB
560else
561MIX_CRLF_LF=CRLF_mix_LF
562MIX_LF_CR=LF_mix_CR
563NL=LF
8eeab92f 564LFNUL=LF_nul
343151dc 565fi
f6975a6b
TB
566export CRLF_MIX_LF_CR MIX NL
567
67e9bff0 568# Same handling with and without ident
caa47adc 569for id in "" ident
320d39cd 570do
67e9bff0
TB
571 for ceol in lf crlf native
572 do
573 for crlf in true false input
574 do
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
65237284 585 checkout_files auto "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
67e9bff0
TB
586 done
587
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
65237284 593 checkout_files auto "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
67e9bff0
TB
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
65237284
TB
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
ab961513 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
320d39cd 615done
343151dc 616
a7630bd4
TB
617# Should be the last test case: remove some files from the worktree
618test_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
625 EOF
9b6d1fc4
SM
626 git ls-files --eol -d >tmp &&
627 sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" tmp |
a7630bd4
TB
628 sort >actual &&
629 test_cmp expect actual
630'
631
343151dc 632test_done