]>
Commit | Line | Data |
---|---|---|
343151dc TB |
1 | #!/bin/sh |
2 | ||
3 | test_description='CRLF conversion all combinations' | |
4 | ||
3e3b9321 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
343151dc TB |
6 | . ./test-lib.sh |
7 | ||
f6975a6b TB |
8 | compare_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 | 15 | compare_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 | 27 | create_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. | |
55 | create_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 && | |
73 | cp CRLF_nul ${pfx}_CRLF_nul.txt | |
67e9bff0 | 74 | done |
710b4e8a TB |
75 | done |
76 | done | |
77 | } | |
78 | ||
0291973b TB |
79 | check_warning () { |
80 | case "$1" in | |
c970d30c AH |
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 ;; | |
d6d6673e | 84 | *) echo >&2 "Illegal 1": "$1" ; return false ;; |
0291973b | 85 | esac |
c970d30c | 86 | sed -e "s/^.* \([^ ]* will be replaced by [^ ]*\) .*$/\1/" "$2" | uniq >"$2".actual |
1108cea7 | 87 | test_cmp "$2".expect "$2".actual |
0291973b TB |
88 | } |
89 | ||
ad295bbc | 90 | commit_check_warn () { |
343151dc | 91 | crlf=$1 |
f6975a6b | 92 | attr=$2 |
0291973b TB |
93 | lfname=$3 |
94 | crlfname=$4 | |
710b4e8a TB |
95 | lfmixcrlf=$5 |
96 | lfmixcr=$6 | |
97 | crlfnul=$7 | |
0291973b | 98 | pfx=crlf_${crlf}_attr_${attr} |
8eeab92f | 99 | create_gitattributes "$attr" && |
a7630bd4 | 100 | for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul |
343151dc | 101 | do |
0291973b TB |
102 | fname=${pfx}_$f.txt && |
103 | cp $f $fname && | |
104 | git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" | |
343151dc | 105 | done && |
0291973b TB |
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 | |
343151dc TB |
112 | } |
113 | ||
710b4e8a | 114 | commit_chk_wrnNNO () { |
67e9bff0 TB |
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} | |
710b4e8a | 124 | #Commit files on top of existing file |
67e9bff0 | 125 | create_gitattributes "$attr" $aeol && |
710b4e8a TB |
126 | for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul |
127 | do | |
128 | fname=${pfx}_$f.txt && | |
129 | cp $f $fname && | |
ded2444a | 130 | printf Z >>"$fname" && |
a0ad53c1 | 131 | git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" |
710b4e8a TB |
132 | done |
133 | ||
134 | test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" ' | |
135 | check_warning "$lfwarn" ${pfx}_LF.err | |
136 | ' | |
67e9bff0 | 137 | test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF" ' |
710b4e8a TB |
138 | check_warning "$crlfwarn" ${pfx}_CRLF.err |
139 | ' | |
140 | ||
67e9bff0 | 141 | test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_mix_LF" ' |
710b4e8a TB |
142 | check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err |
143 | ' | |
144 | ||
67e9bff0 | 145 | test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf LF_mix_cr" ' |
710b4e8a TB |
146 | check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err |
147 | ' | |
148 | ||
67e9bff0 | 149 | test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_nul" ' |
710b4e8a TB |
150 | check_warning "$crlfnul" ${pfx}_CRLF_nul.err |
151 | ' | |
152 | } | |
153 | ||
86ff70a0 TB |
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 | |
169 | do | |
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 | |
175 | ||
649f1f09 | 176 | test_expect_success "commit file with mixed EOL onto LF crlf=$crlf attr=$attr" ' |
86ff70a0 TB |
177 | check_warning "$lfwarn" ${pfx}_LF.err |
178 | ' | |
649f1f09 | 179 | test_expect_success "commit file with mixed EOL onto CLRF attr=$attr aeol=$aeol crlf=$crlf" ' |
86ff70a0 TB |
180 | check_warning "$crlfwarn" ${pfx}_CRLF.err |
181 | ' | |
182 | ||
649f1f09 | 183 | test_expect_success "commit file with mixed EOL onto CRLF_mix_LF attr=$attr aeol=$aeol crlf=$crlf" ' |
86ff70a0 TB |
184 | check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err |
185 | ' | |
186 | ||
649f1f09 | 187 | test_expect_success "commit file with mixed EOL onto LF_mix_cr attr=$attr aeol=$aeol crlf=$crlf " ' |
86ff70a0 TB |
188 | check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err |
189 | ' | |
190 | ||
649f1f09 | 191 | test_expect_success "commit file with mixed EOL onto CRLF_nul attr=$attr aeol=$aeol crlf=$crlf" ' |
86ff70a0 TB |
192 | check_warning "$crlfnul" ${pfx}_CRLF_nul.err |
193 | ' | |
194 | } | |
195 | ||
196 | ||
a7630bd4 TB |
197 | stats_ascii () { |
198 | case "$1" in | |
199 | LF) | |
200 | echo lf | |
201 | ;; | |
202 | CRLF) | |
203 | echo crlf | |
204 | ;; | |
205 | CRLF_mix_LF) | |
206 | echo mixed | |
207 | ;; | |
208 | LF_mix_CR|CRLF_nul|LF_nul|CRLF_mix_CR) | |
209 | echo "-text" | |
210 | ;; | |
211 | *) | |
212 | echo error_invalid $1 | |
213 | ;; | |
214 | esac | |
215 | ||
216 | } | |
217 | ||
817a0c79 | 218 | |
7a40cf15 | 219 | # construct the attr/ returned by git ls-files --eol |
817a0c79 | 220 | # Take none (=empty), one or two args |
67e9bff0 | 221 | # convert.c: eol=XX overrides text=auto |
817a0c79 TB |
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" ;; | |
65237284 TB |
229 | auto,lf) echo "text=auto eol=lf" ;; |
230 | auto,crlf) echo "text=auto eol=crlf" ;; | |
817a0c79 TB |
231 | lf,) echo "text eol=lf" ;; |
232 | crlf,) echo "text eol=crlf" ;; | |
233 | ,) echo "" ;; | |
234 | *) echo invalid_attr "$1,$2" ;; | |
235 | esac | |
236 | } | |
237 | ||
f6975a6b | 238 | check_files_in_repo () { |
343151dc | 239 | crlf=$1 |
f6975a6b | 240 | attr=$2 |
343151dc TB |
241 | lfname=$3 |
242 | crlfname=$4 | |
243 | lfmixcrlf=$5 | |
244 | lfmixcr=$6 | |
245 | crlfnul=$7 | |
f6975a6b | 246 | pfx=crlf_${crlf}_attr_${attr}_ && |
343151dc TB |
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 | |
252 | } | |
253 | ||
710b4e8a | 254 | check_in_repo_NNO () { |
67e9bff0 TB |
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 | |
710b4e8a | 266 | ' |
67e9bff0 TB |
267 | test_expect_success "compare_files $crlfname ${pfx}_CRLF.txt" ' |
268 | compare_files $crlfname ${pfx}_CRLF.txt | |
710b4e8a | 269 | ' |
67e9bff0 TB |
270 | test_expect_success "compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt" ' |
271 | compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt | |
710b4e8a | 272 | ' |
67e9bff0 TB |
273 | test_expect_success "compare_files $lfmixcr ${pfx}_LF_mix_CR.txt" ' |
274 | compare_files $lfmixcr ${pfx}_LF_mix_CR.txt | |
710b4e8a | 275 | ' |
67e9bff0 TB |
276 | test_expect_success "compare_files $crlfnul ${pfx}_CRLF_nul.txt" ' |
277 | compare_files $crlfnul ${pfx}_CRLF_nul.txt | |
710b4e8a TB |
278 | ' |
279 | } | |
343151dc | 280 | |
ad295bbc | 281 | checkout_files () { |
320d39cd TB |
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 | |
67e9bff0 | 292 | create_gitattributes "$attr" $ident $aeol && |
343151dc | 293 | git config core.autocrlf $crlf && |
320d39cd | 294 | pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ && |
8eeab92f | 295 | for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul |
343151dc | 296 | do |
a7630bd4 | 297 | rm crlf_false_attr__$f.txt && |
320d39cd | 298 | if test -z "$ceol"; then |
774d44cc | 299 | git checkout -- crlf_false_attr__$f.txt |
343151dc | 300 | else |
774d44cc | 301 | git -c core.eol=$ceol checkout -- crlf_false_attr__$f.txt |
343151dc TB |
302 | fi |
303 | done | |
304 | ||
67e9bff0 | 305 | test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" ' |
a7630bd4 TB |
306 | test_when_finished "rm expect actual" && |
307 | sort <<-EOF >expect && | |
817a0c79 TB |
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 | |
a7630bd4 | 314 | EOF |
9b6d1fc4 SM |
315 | git ls-files --eol crlf_false_attr__* >tmp && |
316 | sed -e "s/ / /g" -e "s/ */ /g" tmp | | |
a7630bd4 TB |
317 | sort >actual && |
318 | test_cmp expect actual | |
319 | ' | |
67e9bff0 | 320 | test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF" " |
a7630bd4 | 321 | compare_ws_file $pfx $lfname crlf_false_attr__LF.txt |
343151dc | 322 | " |
67e9bff0 | 323 | test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF" " |
a7630bd4 | 324 | compare_ws_file $pfx $crlfname crlf_false_attr__CRLF.txt |
343151dc | 325 | " |
67e9bff0 | 326 | test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF_mix_LF" " |
a7630bd4 | 327 | compare_ws_file $pfx $lfmixcrlf crlf_false_attr__CRLF_mix_LF.txt |
343151dc | 328 | " |
67e9bff0 | 329 | test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_mix_CR" " |
a7630bd4 | 330 | compare_ws_file $pfx $lfmixcr crlf_false_attr__LF_mix_CR.txt |
343151dc | 331 | " |
67e9bff0 | 332 | test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_nul" " |
a7630bd4 | 333 | compare_ws_file $pfx $crlfnul crlf_false_attr__LF_nul.txt |
343151dc TB |
334 | " |
335 | } | |
336 | ||
a7630bd4 TB |
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 | |
362 | EOF | |
9b6d1fc4 | 363 | git ls-files --eol -o >tmp && |
a7630bd4 TB |
364 | sed -n -e "/TeBi_/{s!attr/[ ]*!!g |
365 | s! ! !g | |
366 | s! *! !g | |
367 | p | |
9b6d1fc4 | 368 | }" tmp | sort >actual && |
a7630bd4 TB |
369 | test_cmp expect actual |
370 | ' | |
371 | ||
06d53148 | 372 | test_expect_success 'setup main' ' |
343151dc | 373 | echo >.gitattributes && |
06d53148 | 374 | git checkout -b main && |
343151dc | 375 | git add .gitattributes && |
229a95aa | 376 | git commit -m "add .gitattributes" . && |
320d39cd TB |
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 && | |
649f1f09 | 384 | create_NNO_MIX_files && |
86ff70a0 | 385 | git -c core.autocrlf=false add NNO_*.txt MIX_*.txt && |
710b4e8a TB |
386 | git commit -m "mixed line endings" && |
387 | test_tick | |
343151dc | 388 | ' |
f6975a6b | 389 | |
2d86a962 JK |
390 | # Disable extra chain-linting for the next set of tests. There are many |
391 | # auto-generated ones that are not worth checking over and over. | |
392 | GIT_TEST_CHAIN_LINT_HARDER_DEFAULT=0 | |
343151dc | 393 | |
0291973b TB |
394 | warn_LF_CRLF="LF will be replaced by CRLF" |
395 | warn_CRLF_LF="CRLF will be replaced by LF" | |
396 | ||
d6d6673e TB |
397 | # WILC stands for "Warn if (this OS) converts LF into CRLF". |
398 | # WICL: Warn if CRLF becomes LF | |
399 | # WAMIX: Mixed line endings: either CRLF->LF or LF->CRLF | |
400 | if test_have_prereq NATIVE_CRLF | |
401 | then | |
402 | WILC=LF_CRLF | |
403 | WICL= | |
404 | WAMIX=LF_CRLF | |
405 | else | |
406 | WILC= | |
407 | WICL=CRLF_LF | |
408 | WAMIX=CRLF_LF | |
409 | fi | |
410 | ||
710b4e8a | 411 | # attr LF CRLF CRLFmixLF LFmixCR CRLFNUL |
ad295bbc | 412 | test_expect_success 'commit files empty attr' ' |
710b4e8a TB |
413 | commit_check_warn false "" "" "" "" "" "" && |
414 | commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "" "" && | |
415 | commit_check_warn input "" "" "CRLF_LF" "CRLF_LF" "" "" | |
0291973b TB |
416 | ' |
417 | ||
ad295bbc | 418 | test_expect_success 'commit files attr=auto' ' |
710b4e8a TB |
419 | commit_check_warn false "auto" "$WILC" "$WICL" "$WAMIX" "" "" && |
420 | commit_check_warn true "auto" "LF_CRLF" "" "LF_CRLF" "" "" && | |
421 | commit_check_warn input "auto" "" "CRLF_LF" "CRLF_LF" "" "" | |
0291973b TB |
422 | ' |
423 | ||
ad295bbc | 424 | test_expect_success 'commit files attr=text' ' |
710b4e8a TB |
425 | commit_check_warn false "text" "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" && |
426 | commit_check_warn true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && | |
427 | commit_check_warn input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" | |
0291973b TB |
428 | ' |
429 | ||
ad295bbc | 430 | test_expect_success 'commit files attr=-text' ' |
710b4e8a TB |
431 | commit_check_warn false "-text" "" "" "" "" "" && |
432 | commit_check_warn true "-text" "" "" "" "" "" && | |
433 | commit_check_warn input "-text" "" "" "" "" "" | |
0291973b TB |
434 | ' |
435 | ||
ad295bbc | 436 | test_expect_success 'commit files attr=lf' ' |
710b4e8a TB |
437 | commit_check_warn false "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" && |
438 | commit_check_warn true "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" && | |
439 | commit_check_warn input "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" | |
0291973b | 440 | ' |
343151dc | 441 | |
ad295bbc | 442 | test_expect_success 'commit files attr=crlf' ' |
710b4e8a TB |
443 | commit_check_warn false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && |
444 | commit_check_warn true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && | |
445 | commit_check_warn input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" | |
0291973b | 446 | ' |
343151dc | 447 | |
86ff70a0 | 448 | # Commit "CRLFmixLF" on top of these files already in the repo: |
649f1f09 TB |
449 | # mixed mixed mixed mixed mixed |
450 | # onto onto onto onto onto | |
86ff70a0 TB |
451 | # attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL |
452 | commit_MIX_chkwrn "" "" false "" "" "" "" "" | |
453 | commit_MIX_chkwrn "" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF" | |
454 | commit_MIX_chkwrn "" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF" | |
455 | ||
649f1f09 | 456 | commit_MIX_chkwrn "auto" "" false "$WAMIX" "" "" "$WAMIX" "$WAMIX" |
86ff70a0 TB |
457 | commit_MIX_chkwrn "auto" "" true "LF_CRLF" "" "" "LF_CRLF" "LF_CRLF" |
458 | commit_MIX_chkwrn "auto" "" input "CRLF_LF" "" "" "CRLF_LF" "CRLF_LF" | |
459 | ||
67e9bff0 TB |
460 | # attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL |
461 | commit_chk_wrnNNO "" "" false "" "" "" "" "" | |
462 | commit_chk_wrnNNO "" "" true LF_CRLF "" "" "" "" | |
463 | commit_chk_wrnNNO "" "" input "" "" "" "" "" | |
710b4e8a | 464 | |
65237284 TB |
465 | commit_chk_wrnNNO "auto" "" false "$WILC" "" "" "" "" |
466 | commit_chk_wrnNNO "auto" "" true LF_CRLF "" "" "" "" | |
467 | commit_chk_wrnNNO "auto" "" input "" "" "" "" "" | |
67e9bff0 TB |
468 | for crlf in true false input |
469 | do | |
470 | commit_chk_wrnNNO -text "" $crlf "" "" "" "" "" | |
471 | commit_chk_wrnNNO -text lf $crlf "" "" "" "" "" | |
472 | commit_chk_wrnNNO -text crlf $crlf "" "" "" "" "" | |
473 | commit_chk_wrnNNO "" lf $crlf "" CRLF_LF CRLF_LF "" CRLF_LF | |
474 | commit_chk_wrnNNO "" crlf $crlf LF_CRLF "" LF_CRLF LF_CRLF "" | |
65237284 TB |
475 | commit_chk_wrnNNO auto lf $crlf "" "" "" "" "" |
476 | commit_chk_wrnNNO auto crlf $crlf LF_CRLF "" "" "" "" | |
67e9bff0 TB |
477 | commit_chk_wrnNNO text lf $crlf "" CRLF_LF CRLF_LF "" CRLF_LF |
478 | commit_chk_wrnNNO text crlf $crlf LF_CRLF "" LF_CRLF LF_CRLF "" | |
479 | done | |
710b4e8a | 480 | |
67e9bff0 TB |
481 | commit_chk_wrnNNO "text" "" false "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" |
482 | commit_chk_wrnNNO "text" "" true LF_CRLF "" LF_CRLF LF_CRLF "" | |
483 | commit_chk_wrnNNO "text" "" input "" CRLF_LF CRLF_LF "" CRLF_LF | |
710b4e8a | 484 | |
a0ad53c1 TB |
485 | test_expect_success 'commit NNO and cleanup' ' |
486 | git commit -m "commit files on top of NNO" && | |
343151dc | 487 | rm -f *.txt && |
710b4e8a | 488 | git -c core.autocrlf=false reset --hard |
343151dc TB |
489 | ' |
490 | ||
491 | test_expect_success 'commit empty gitattribues' ' | |
492 | check_files_in_repo false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && | |
493 | check_files_in_repo true "" LF LF LF LF_mix_CR CRLF_nul && | |
494 | check_files_in_repo input "" LF LF LF LF_mix_CR CRLF_nul | |
495 | ' | |
496 | ||
497 | test_expect_success 'commit text=auto' ' | |
498 | check_files_in_repo false "auto" LF LF LF LF_mix_CR CRLF_nul && | |
499 | check_files_in_repo true "auto" LF LF LF LF_mix_CR CRLF_nul && | |
500 | check_files_in_repo input "auto" LF LF LF LF_mix_CR CRLF_nul | |
501 | ' | |
502 | ||
503 | test_expect_success 'commit text' ' | |
504 | check_files_in_repo false "text" LF LF LF LF_mix_CR LF_nul && | |
505 | check_files_in_repo true "text" LF LF LF LF_mix_CR LF_nul && | |
506 | check_files_in_repo input "text" LF LF LF LF_mix_CR LF_nul | |
507 | ' | |
508 | ||
509 | test_expect_success 'commit -text' ' | |
510 | check_files_in_repo false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && | |
511 | check_files_in_repo true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && | |
512 | check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
513 | ' | |
514 | ||
67e9bff0 TB |
515 | for crlf in true false input |
516 | do | |
517 | # attr aeol LF CRLF CRLF_mix_LF LF_mix_CR CRLFNUL | |
518 | check_in_repo_NNO "" "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
519 | check_in_repo_NNO -text "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
520 | check_in_repo_NNO -text lf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
521 | check_in_repo_NNO -text crlf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
65237284 TB |
522 | check_in_repo_NNO auto "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul |
523 | check_in_repo_NNO auto lf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
524 | check_in_repo_NNO auto crlf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
67e9bff0 TB |
525 | check_in_repo_NNO text "" $crlf LF LF LF LF_mix_CR LF_nul |
526 | check_in_repo_NNO text lf $crlf LF LF LF LF_mix_CR LF_nul | |
527 | check_in_repo_NNO text crlf $crlf LF LF LF LF_mix_CR LF_nul | |
528 | done | |
343151dc TB |
529 | ################################################################################ |
530 | # Check how files in the repo are changed when they are checked out | |
531 | # How to read the table below: | |
ad295bbc | 532 | # - checkout_files will check multiple files with a combination of settings |
f6975a6b | 533 | # and attributes (core.autocrlf=input is forbidden with core.eol=crlf) |
320d39cd TB |
534 | # |
535 | # - parameter $1 : text in .gitattributs "" (empty) | auto | text | -text | |
536 | # - parameter $2 : ident "" | i (i == ident) | |
537 | # - parameter $3 : eol in .gitattributs "" (empty) | lf | crlf | |
538 | # - parameter $4 : core.autocrlf false | true | input | |
539 | # - parameter $5 : core.eol "" | lf | crlf | "native" | |
540 | # - parameter $6 : reference for a file with only LF in the repo | |
541 | # - parameter $7 : reference for a file with only CRLF in the repo | |
542 | # - parameter $8 : reference for a file with mixed LF and CRLF in the repo | |
543 | # - parameter $9 : reference for a file with LF and CR in the repo | |
544 | # - parameter $10 : reference for a file with CRLF and a NUL (should be handled as binary when auto) | |
545 | ||
8eeab92f | 546 | if test_have_prereq NATIVE_CRLF |
343151dc | 547 | then |
f6975a6b TB |
548 | MIX_CRLF_LF=CRLF |
549 | MIX_LF_CR=CRLF_mix_CR | |
550 | NL=CRLF | |
8eeab92f | 551 | LFNUL=CRLF_nul |
f6975a6b TB |
552 | else |
553 | MIX_CRLF_LF=CRLF_mix_LF | |
554 | MIX_LF_CR=LF_mix_CR | |
555 | NL=LF | |
8eeab92f | 556 | LFNUL=LF_nul |
343151dc | 557 | fi |
f6975a6b TB |
558 | export CRLF_MIX_LF_CR MIX NL |
559 | ||
67e9bff0 | 560 | # Same handling with and without ident |
caa47adc | 561 | for id in "" ident |
320d39cd | 562 | do |
67e9bff0 TB |
563 | for ceol in lf crlf native |
564 | do | |
565 | for crlf in true false input | |
566 | do | |
567 | # -text overrides core.autocrlf and core.eol | |
568 | # text and eol=crlf or eol=lf override core.autocrlf and core.eol | |
569 | checkout_files -text "$id" "" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
570 | checkout_files -text "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
571 | checkout_files -text "$id" "crlf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
572 | # text | |
573 | checkout_files text "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
574 | checkout_files text "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul | |
575 | # currently the same as text, eol=XXX | |
576 | checkout_files auto "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
65237284 | 577 | checkout_files auto "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul |
67e9bff0 TB |
578 | done |
579 | ||
580 | # core.autocrlf false, different core.eol | |
581 | checkout_files "" "$id" "" false "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
582 | # core.autocrlf true | |
583 | checkout_files "" "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
584 | # text: core.autocrlf = true overrides core.eol | |
65237284 | 585 | checkout_files auto "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul |
67e9bff0 TB |
586 | checkout_files text "$id" "" true "$ceol" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul |
587 | # text: core.autocrlf = input overrides core.eol | |
588 | checkout_files text "$id" "" input "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
589 | checkout_files auto "$id" "" input "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
590 | # text=auto + eol=XXX | |
591 | done | |
592 | # text: core.autocrlf=false uses core.eol | |
593 | checkout_files text "$id" "" false crlf CRLF CRLF CRLF CRLF_mix_CR CRLF_nul | |
594 | checkout_files text "$id" "" false lf LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
595 | # text: core.autocrlf=false and core.eol unset(or native) uses native eol | |
596 | checkout_files text "$id" "" false "" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL | |
597 | checkout_files text "$id" "" false native $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL | |
598 | # auto: core.autocrlf=false and core.eol unset(or native) uses native eol | |
65237284 TB |
599 | checkout_files auto "$id" "" false "" $NL CRLF CRLF_mix_LF LF_mix_CR LF_nul |
600 | checkout_files auto "$id" "" false native $NL CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
ab961513 | 601 | # core.autocrlf false, .gitattributes sets eol |
602 | checkout_files "" "$id" "lf" false "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
603 | checkout_files "" "$id" "crlf" false "" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul | |
604 | # core.autocrlf true, .gitattributes sets eol | |
605 | checkout_files "" "$id" "lf" true "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
606 | checkout_files "" "$id" "crlf" true "" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul | |
320d39cd | 607 | done |
343151dc | 608 | |
2d86a962 JK |
609 | # The rest of the tests are unique; do the usual linting. |
610 | unset GIT_TEST_CHAIN_LINT_HARDER_DEFAULT | |
611 | ||
a7630bd4 TB |
612 | # Should be the last test case: remove some files from the worktree |
613 | test_expect_success 'ls-files --eol -d -z' ' | |
614 | rm crlf_false_attr__CRLF.txt crlf_false_attr__CRLF_mix_LF.txt crlf_false_attr__LF.txt .gitattributes && | |
615 | cat >expect <<-\EOF && | |
616 | i/crlf w/ crlf_false_attr__CRLF.txt | |
617 | i/lf w/ .gitattributes | |
618 | i/lf w/ crlf_false_attr__LF.txt | |
619 | i/mixed w/ crlf_false_attr__CRLF_mix_LF.txt | |
620 | EOF | |
9b6d1fc4 SM |
621 | git ls-files --eol -d >tmp && |
622 | sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" tmp | | |
a7630bd4 TB |
623 | sort >actual && |
624 | test_cmp expect actual | |
625 | ' | |
626 | ||
343151dc | 627 | test_done |