]>
Commit | Line | Data |
---|---|---|
343151dc TB |
1 | #!/bin/sh |
2 | ||
3 | test_description='CRLF conversion all combinations' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
f6975a6b TB |
7 | compare_files () { |
8 | tr '\015\000' QN <"$1" >"$1".expect && | |
ded2444a | 9 | tr '\015\000' QN <"$2" | tr -d 'Z' >"$2".actual && |
343151dc TB |
10 | test_cmp "$1".expect "$2".actual && |
11 | rm "$1".expect "$2".actual | |
12 | } | |
13 | ||
f6975a6b | 14 | compare_ws_file () { |
343151dc TB |
15 | pfx=$1 |
16 | exp=$2.expect | |
17 | act=$pfx.actual.$3 | |
320d39cd TB |
18 | tr '\015\000abcdef0123456789' QN00000000000000000 <"$2" >"$exp" && |
19 | tr '\015\000abcdef0123456789' QN00000000000000000 <"$3" >"$act" && | |
20 | test_cmp "$exp" "$act" && | |
21 | rm "$exp" "$act" | |
343151dc TB |
22 | } |
23 | ||
f6975a6b | 24 | create_gitattributes () { |
320d39cd TB |
25 | { |
26 | while test "$#" != 0 | |
27 | do | |
28 | case "$1" in | |
29 | auto) echo '*.txt text=auto' ;; | |
30 | ident) echo '*.txt ident' ;; | |
31 | text) echo '*.txt text' ;; | |
32 | -text) echo '*.txt -text' ;; | |
33 | crlf) echo '*.txt eol=crlf' ;; | |
34 | lf) echo '*.txt eol=lf' ;; | |
35 | "") ;; | |
36 | *) | |
37 | echo >&2 invalid attribute: "$1" | |
38 | exit 1 | |
39 | ;; | |
40 | esac && | |
41 | shift | |
42 | done | |
43 | } >.gitattributes | |
343151dc TB |
44 | } |
45 | ||
710b4e8a | 46 | create_NNO_files () { |
710b4e8a TB |
47 | for crlf in false true input |
48 | do | |
67e9bff0 | 49 | for attr in "" auto text -text |
710b4e8a | 50 | do |
67e9bff0 TB |
51 | for aeol in "" lf crlf |
52 | do | |
53 | pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} | |
54 | cp CRLF_mix_LF ${pfx}_LF.txt && | |
55 | cp CRLF_mix_LF ${pfx}_CRLF.txt && | |
56 | cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt && | |
57 | cp CRLF_mix_LF ${pfx}_LF_mix_CR.txt && | |
58 | cp CRLF_mix_LF ${pfx}_CRLF_nul.txt | |
59 | done | |
710b4e8a TB |
60 | done |
61 | done | |
62 | } | |
63 | ||
0291973b TB |
64 | check_warning () { |
65 | case "$1" in | |
d6d6673e TB |
66 | LF_CRLF) echo "warning: LF will be replaced by CRLF" >"$2".expect ;; |
67 | CRLF_LF) echo "warning: CRLF will be replaced by LF" >"$2".expect ;; | |
68 | '') >"$2".expect ;; | |
69 | *) echo >&2 "Illegal 1": "$1" ; return false ;; | |
0291973b | 70 | esac |
710b4e8a | 71 | grep "will be replaced by" "$2" | sed -e "s/\(.*\) in [^ ]*$/\1/" | uniq >"$2".actual |
0d75bfe6 | 72 | test_i18ncmp "$2".expect "$2".actual |
0291973b TB |
73 | } |
74 | ||
ad295bbc | 75 | commit_check_warn () { |
343151dc | 76 | crlf=$1 |
f6975a6b | 77 | attr=$2 |
0291973b TB |
78 | lfname=$3 |
79 | crlfname=$4 | |
710b4e8a TB |
80 | lfmixcrlf=$5 |
81 | lfmixcr=$6 | |
82 | crlfnul=$7 | |
0291973b | 83 | pfx=crlf_${crlf}_attr_${attr} |
8eeab92f | 84 | create_gitattributes "$attr" && |
a7630bd4 | 85 | for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul |
343151dc | 86 | do |
0291973b TB |
87 | fname=${pfx}_$f.txt && |
88 | cp $f $fname && | |
89 | git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" | |
343151dc | 90 | done && |
0291973b TB |
91 | git commit -m "core.autocrlf $crlf" && |
92 | check_warning "$lfname" ${pfx}_LF.err && | |
93 | check_warning "$crlfname" ${pfx}_CRLF.err && | |
94 | check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err && | |
95 | check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err && | |
96 | check_warning "$crlfnul" ${pfx}_CRLF_nul.err | |
343151dc TB |
97 | } |
98 | ||
710b4e8a | 99 | commit_chk_wrnNNO () { |
67e9bff0 TB |
100 | attr=$1 ; shift |
101 | aeol=$1 ; shift | |
102 | crlf=$1 ; shift | |
103 | lfwarn=$1 ; shift | |
104 | crlfwarn=$1 ; shift | |
105 | lfmixcrlf=$1 ; shift | |
106 | lfmixcr=$1 ; shift | |
107 | crlfnul=$1 ; shift | |
108 | pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} | |
710b4e8a | 109 | #Commit files on top of existing file |
67e9bff0 | 110 | create_gitattributes "$attr" $aeol && |
710b4e8a TB |
111 | for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul |
112 | do | |
113 | fname=${pfx}_$f.txt && | |
114 | cp $f $fname && | |
ded2444a | 115 | printf Z >>"$fname" && |
a0ad53c1 | 116 | git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" |
710b4e8a TB |
117 | done |
118 | ||
119 | test_expect_success "commit NNO files crlf=$crlf attr=$attr LF" ' | |
120 | check_warning "$lfwarn" ${pfx}_LF.err | |
121 | ' | |
67e9bff0 | 122 | test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF" ' |
710b4e8a TB |
123 | check_warning "$crlfwarn" ${pfx}_CRLF.err |
124 | ' | |
125 | ||
67e9bff0 | 126 | test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_mix_LF" ' |
710b4e8a TB |
127 | check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err |
128 | ' | |
129 | ||
67e9bff0 | 130 | test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf LF_mix_cr" ' |
710b4e8a TB |
131 | check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err |
132 | ' | |
133 | ||
67e9bff0 | 134 | test_expect_success "commit NNO files attr=$attr aeol=$aeol crlf=$crlf CRLF_nul" ' |
710b4e8a TB |
135 | check_warning "$crlfnul" ${pfx}_CRLF_nul.err |
136 | ' | |
137 | } | |
138 | ||
a7630bd4 TB |
139 | stats_ascii () { |
140 | case "$1" in | |
141 | LF) | |
142 | echo lf | |
143 | ;; | |
144 | CRLF) | |
145 | echo crlf | |
146 | ;; | |
147 | CRLF_mix_LF) | |
148 | echo mixed | |
149 | ;; | |
150 | LF_mix_CR|CRLF_nul|LF_nul|CRLF_mix_CR) | |
151 | echo "-text" | |
152 | ;; | |
153 | *) | |
154 | echo error_invalid $1 | |
155 | ;; | |
156 | esac | |
157 | ||
158 | } | |
159 | ||
817a0c79 TB |
160 | |
161 | # contruct the attr/ returned by git ls-files --eol | |
162 | # Take none (=empty), one or two args | |
67e9bff0 | 163 | # convert.c: eol=XX overrides text=auto |
817a0c79 TB |
164 | attr_ascii () { |
165 | case $1,$2 in | |
166 | -text,*) echo "-text" ;; | |
167 | text,) echo "text" ;; | |
168 | text,lf) echo "text eol=lf" ;; | |
169 | text,crlf) echo "text eol=crlf" ;; | |
170 | auto,) echo "text=auto" ;; | |
65237284 TB |
171 | auto,lf) echo "text=auto eol=lf" ;; |
172 | auto,crlf) echo "text=auto eol=crlf" ;; | |
817a0c79 TB |
173 | lf,) echo "text eol=lf" ;; |
174 | crlf,) echo "text eol=crlf" ;; | |
175 | ,) echo "" ;; | |
176 | *) echo invalid_attr "$1,$2" ;; | |
177 | esac | |
178 | } | |
179 | ||
f6975a6b | 180 | check_files_in_repo () { |
343151dc | 181 | crlf=$1 |
f6975a6b | 182 | attr=$2 |
343151dc TB |
183 | lfname=$3 |
184 | crlfname=$4 | |
185 | lfmixcrlf=$5 | |
186 | lfmixcr=$6 | |
187 | crlfnul=$7 | |
f6975a6b | 188 | pfx=crlf_${crlf}_attr_${attr}_ && |
343151dc TB |
189 | compare_files $lfname ${pfx}LF.txt && |
190 | compare_files $crlfname ${pfx}CRLF.txt && | |
191 | compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt && | |
192 | compare_files $lfmixcr ${pfx}LF_mix_CR.txt && | |
193 | compare_files $crlfnul ${pfx}CRLF_nul.txt | |
194 | } | |
195 | ||
710b4e8a | 196 | check_in_repo_NNO () { |
67e9bff0 TB |
197 | attr=$1 ; shift |
198 | aeol=$1 ; shift | |
199 | crlf=$1 ; shift | |
200 | lfname=$1 ; shift | |
201 | crlfname=$1 ; shift | |
202 | lfmixcrlf=$1 ; shift | |
203 | lfmixcr=$1 ; shift | |
204 | crlfnul=$1 ; shift | |
205 | pfx=NNO_attr_${attr}_aeol_${aeol}_${crlf} | |
206 | test_expect_success "compare_files $lfname ${pfx}_LF.txt" ' | |
207 | compare_files $lfname ${pfx}_LF.txt | |
710b4e8a | 208 | ' |
67e9bff0 TB |
209 | test_expect_success "compare_files $crlfname ${pfx}_CRLF.txt" ' |
210 | compare_files $crlfname ${pfx}_CRLF.txt | |
710b4e8a | 211 | ' |
67e9bff0 TB |
212 | test_expect_success "compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt" ' |
213 | compare_files $lfmixcrlf ${pfx}_CRLF_mix_LF.txt | |
710b4e8a | 214 | ' |
67e9bff0 TB |
215 | test_expect_success "compare_files $lfmixcr ${pfx}_LF_mix_CR.txt" ' |
216 | compare_files $lfmixcr ${pfx}_LF_mix_CR.txt | |
710b4e8a | 217 | ' |
67e9bff0 TB |
218 | test_expect_success "compare_files $crlfnul ${pfx}_CRLF_nul.txt" ' |
219 | compare_files $crlfnul ${pfx}_CRLF_nul.txt | |
710b4e8a TB |
220 | ' |
221 | } | |
343151dc | 222 | |
ad295bbc | 223 | checkout_files () { |
320d39cd TB |
224 | attr=$1 ; shift |
225 | ident=$1; shift | |
226 | aeol=$1 ; shift | |
227 | crlf=$1 ; shift | |
228 | ceol=$1 ; shift | |
229 | lfname=$1 ; shift | |
230 | crlfname=$1 ; shift | |
231 | lfmixcrlf=$1 ; shift | |
232 | lfmixcr=$1 ; shift | |
233 | crlfnul=$1 ; shift | |
67e9bff0 | 234 | create_gitattributes "$attr" $ident $aeol && |
343151dc | 235 | git config core.autocrlf $crlf && |
320d39cd | 236 | pfx=eol_${ceol}_crlf_${crlf}_attr_${attr}_ && |
8eeab92f | 237 | for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul |
343151dc | 238 | do |
a7630bd4 | 239 | rm crlf_false_attr__$f.txt && |
320d39cd | 240 | if test -z "$ceol"; then |
a7630bd4 | 241 | git checkout crlf_false_attr__$f.txt |
343151dc | 242 | else |
320d39cd | 243 | git -c core.eol=$ceol checkout crlf_false_attr__$f.txt |
343151dc TB |
244 | fi |
245 | done | |
246 | ||
67e9bff0 | 247 | test_expect_success "ls-files --eol attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol" ' |
a7630bd4 TB |
248 | test_when_finished "rm expect actual" && |
249 | sort <<-EOF >expect && | |
817a0c79 TB |
250 | i/crlf w/$(stats_ascii $crlfname) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF.txt |
251 | i/mixed w/$(stats_ascii $lfmixcrlf) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_mix_LF.txt | |
252 | i/lf w/$(stats_ascii $lfname) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF.txt | |
253 | i/-text w/$(stats_ascii $lfmixcr) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_mix_CR.txt | |
254 | i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_nul.txt | |
255 | i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_nul.txt | |
a7630bd4 TB |
256 | EOF |
257 | git ls-files --eol crlf_false_attr__* | | |
817a0c79 | 258 | sed -e "s/ / /g" -e "s/ */ /g" | |
a7630bd4 TB |
259 | sort >actual && |
260 | test_cmp expect actual | |
261 | ' | |
67e9bff0 | 262 | test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF" " |
a7630bd4 | 263 | compare_ws_file $pfx $lfname crlf_false_attr__LF.txt |
343151dc | 264 | " |
67e9bff0 | 265 | test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF" " |
a7630bd4 | 266 | compare_ws_file $pfx $crlfname crlf_false_attr__CRLF.txt |
343151dc | 267 | " |
67e9bff0 | 268 | test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=CRLF_mix_LF" " |
a7630bd4 | 269 | compare_ws_file $pfx $lfmixcrlf crlf_false_attr__CRLF_mix_LF.txt |
343151dc | 270 | " |
67e9bff0 | 271 | test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_mix_CR" " |
a7630bd4 | 272 | compare_ws_file $pfx $lfmixcr crlf_false_attr__LF_mix_CR.txt |
343151dc | 273 | " |
67e9bff0 | 274 | test_expect_success "checkout attr=$attr $ident aeol=$aeol core.autocrlf=$crlf core.eol=$ceol file=LF_nul" " |
a7630bd4 | 275 | compare_ws_file $pfx $crlfnul crlf_false_attr__LF_nul.txt |
343151dc TB |
276 | " |
277 | } | |
278 | ||
a7630bd4 TB |
279 | # Test control characters |
280 | # NUL SOH CR EOF==^Z | |
281 | test_expect_success 'ls-files --eol -o Text/Binary' ' | |
282 | test_when_finished "rm expect actual TeBi_*" && | |
283 | STRT=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA && | |
284 | STR=$STRT$STRT$STRT$STRT && | |
285 | printf "${STR}BBB\001" >TeBi_127_S && | |
286 | printf "${STR}BBBB\001">TeBi_128_S && | |
287 | printf "${STR}BBB\032" >TeBi_127_E && | |
288 | printf "\032${STR}BBB" >TeBi_E_127 && | |
289 | printf "${STR}BBBB\000">TeBi_128_N && | |
290 | printf "${STR}BBB\012">TeBi_128_L && | |
291 | printf "${STR}BBB\015">TeBi_127_C && | |
292 | printf "${STR}BB\015\012" >TeBi_126_CL && | |
293 | printf "${STR}BB\015\012\015" >TeBi_126_CLC && | |
294 | sort <<-\EOF >expect && | |
295 | i/ w/-text TeBi_127_S | |
296 | i/ w/none TeBi_128_S | |
297 | i/ w/none TeBi_127_E | |
298 | i/ w/-text TeBi_E_127 | |
299 | i/ w/-text TeBi_128_N | |
300 | i/ w/lf TeBi_128_L | |
301 | i/ w/-text TeBi_127_C | |
302 | i/ w/crlf TeBi_126_CL | |
303 | i/ w/-text TeBi_126_CLC | |
304 | EOF | |
305 | git ls-files --eol -o | | |
306 | sed -n -e "/TeBi_/{s!attr/[ ]*!!g | |
307 | s! ! !g | |
308 | s! *! !g | |
309 | p | |
310 | }" | sort >actual && | |
311 | test_cmp expect actual | |
312 | ' | |
313 | ||
343151dc TB |
314 | test_expect_success 'setup master' ' |
315 | echo >.gitattributes && | |
316 | git checkout -b master && | |
317 | git add .gitattributes && | |
318 | git commit -m "add .gitattributes" "" && | |
320d39cd TB |
319 | printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONE\nLINETWO\nLINETHREE" >LF && |
320 | printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONE\r\nLINETWO\r\nLINETHREE" >CRLF && | |
321 | printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONE\r\nLINETWO\nLINETHREE" >CRLF_mix_LF && | |
322 | printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONE\nLINETWO\rLINETHREE" >LF_mix_CR && | |
323 | printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONE\r\nLINETWO\rLINETHREE" >CRLF_mix_CR && | |
324 | printf "\$Id: 0000000000000000000000000000000000000000 \$\r\nLINEONEQ\r\nLINETWO\r\nLINETHREE" | q_to_nul >CRLF_nul && | |
325 | printf "\$Id: 0000000000000000000000000000000000000000 \$\nLINEONEQ\nLINETWO\nLINETHREE" | q_to_nul >LF_nul && | |
710b4e8a TB |
326 | create_NNO_files CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF && |
327 | git -c core.autocrlf=false add NNO_*.txt && | |
328 | git commit -m "mixed line endings" && | |
329 | test_tick | |
343151dc | 330 | ' |
f6975a6b | 331 | |
343151dc | 332 | |
343151dc | 333 | |
0291973b TB |
334 | warn_LF_CRLF="LF will be replaced by CRLF" |
335 | warn_CRLF_LF="CRLF will be replaced by LF" | |
336 | ||
d6d6673e TB |
337 | # WILC stands for "Warn if (this OS) converts LF into CRLF". |
338 | # WICL: Warn if CRLF becomes LF | |
339 | # WAMIX: Mixed line endings: either CRLF->LF or LF->CRLF | |
340 | if test_have_prereq NATIVE_CRLF | |
341 | then | |
342 | WILC=LF_CRLF | |
343 | WICL= | |
344 | WAMIX=LF_CRLF | |
345 | else | |
346 | WILC= | |
347 | WICL=CRLF_LF | |
348 | WAMIX=CRLF_LF | |
349 | fi | |
350 | ||
710b4e8a | 351 | # attr LF CRLF CRLFmixLF LFmixCR CRLFNUL |
ad295bbc | 352 | test_expect_success 'commit files empty attr' ' |
710b4e8a TB |
353 | commit_check_warn false "" "" "" "" "" "" && |
354 | commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "" "" && | |
355 | commit_check_warn input "" "" "CRLF_LF" "CRLF_LF" "" "" | |
0291973b TB |
356 | ' |
357 | ||
ad295bbc | 358 | test_expect_success 'commit files attr=auto' ' |
710b4e8a TB |
359 | commit_check_warn false "auto" "$WILC" "$WICL" "$WAMIX" "" "" && |
360 | commit_check_warn true "auto" "LF_CRLF" "" "LF_CRLF" "" "" && | |
361 | commit_check_warn input "auto" "" "CRLF_LF" "CRLF_LF" "" "" | |
0291973b TB |
362 | ' |
363 | ||
ad295bbc | 364 | test_expect_success 'commit files attr=text' ' |
710b4e8a TB |
365 | commit_check_warn false "text" "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" && |
366 | commit_check_warn true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && | |
367 | commit_check_warn input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" | |
0291973b TB |
368 | ' |
369 | ||
ad295bbc | 370 | test_expect_success 'commit files attr=-text' ' |
710b4e8a TB |
371 | commit_check_warn false "-text" "" "" "" "" "" && |
372 | commit_check_warn true "-text" "" "" "" "" "" && | |
373 | commit_check_warn input "-text" "" "" "" "" "" | |
0291973b TB |
374 | ' |
375 | ||
ad295bbc | 376 | test_expect_success 'commit files attr=lf' ' |
710b4e8a TB |
377 | commit_check_warn false "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" && |
378 | commit_check_warn true "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" && | |
379 | commit_check_warn input "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" | |
0291973b | 380 | ' |
343151dc | 381 | |
ad295bbc | 382 | test_expect_success 'commit files attr=crlf' ' |
710b4e8a TB |
383 | commit_check_warn false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && |
384 | commit_check_warn true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && | |
385 | commit_check_warn input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" | |
0291973b | 386 | ' |
343151dc | 387 | |
67e9bff0 TB |
388 | # attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL |
389 | commit_chk_wrnNNO "" "" false "" "" "" "" "" | |
390 | commit_chk_wrnNNO "" "" true LF_CRLF "" "" "" "" | |
391 | commit_chk_wrnNNO "" "" input "" "" "" "" "" | |
710b4e8a | 392 | |
65237284 TB |
393 | commit_chk_wrnNNO "auto" "" false "$WILC" "" "" "" "" |
394 | commit_chk_wrnNNO "auto" "" true LF_CRLF "" "" "" "" | |
395 | commit_chk_wrnNNO "auto" "" input "" "" "" "" "" | |
67e9bff0 TB |
396 | for crlf in true false input |
397 | do | |
398 | commit_chk_wrnNNO -text "" $crlf "" "" "" "" "" | |
399 | commit_chk_wrnNNO -text lf $crlf "" "" "" "" "" | |
400 | commit_chk_wrnNNO -text crlf $crlf "" "" "" "" "" | |
401 | commit_chk_wrnNNO "" lf $crlf "" CRLF_LF CRLF_LF "" CRLF_LF | |
402 | commit_chk_wrnNNO "" crlf $crlf LF_CRLF "" LF_CRLF LF_CRLF "" | |
65237284 TB |
403 | commit_chk_wrnNNO auto lf $crlf "" "" "" "" "" |
404 | commit_chk_wrnNNO auto crlf $crlf LF_CRLF "" "" "" "" | |
67e9bff0 TB |
405 | commit_chk_wrnNNO text lf $crlf "" CRLF_LF CRLF_LF "" CRLF_LF |
406 | commit_chk_wrnNNO text crlf $crlf LF_CRLF "" LF_CRLF LF_CRLF "" | |
407 | done | |
710b4e8a | 408 | |
67e9bff0 TB |
409 | commit_chk_wrnNNO "text" "" false "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" |
410 | commit_chk_wrnNNO "text" "" true LF_CRLF "" LF_CRLF LF_CRLF "" | |
411 | commit_chk_wrnNNO "text" "" input "" CRLF_LF CRLF_LF "" CRLF_LF | |
710b4e8a | 412 | |
a0ad53c1 TB |
413 | test_expect_success 'commit NNO and cleanup' ' |
414 | git commit -m "commit files on top of NNO" && | |
343151dc | 415 | rm -f *.txt && |
710b4e8a | 416 | git -c core.autocrlf=false reset --hard |
343151dc TB |
417 | ' |
418 | ||
419 | test_expect_success 'commit empty gitattribues' ' | |
420 | check_files_in_repo false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && | |
421 | check_files_in_repo true "" LF LF LF LF_mix_CR CRLF_nul && | |
422 | check_files_in_repo input "" LF LF LF LF_mix_CR CRLF_nul | |
423 | ' | |
424 | ||
425 | test_expect_success 'commit text=auto' ' | |
426 | check_files_in_repo false "auto" LF LF LF LF_mix_CR CRLF_nul && | |
427 | check_files_in_repo true "auto" LF LF LF LF_mix_CR CRLF_nul && | |
428 | check_files_in_repo input "auto" LF LF LF LF_mix_CR CRLF_nul | |
429 | ' | |
430 | ||
431 | test_expect_success 'commit text' ' | |
432 | check_files_in_repo false "text" LF LF LF LF_mix_CR LF_nul && | |
433 | check_files_in_repo true "text" LF LF LF LF_mix_CR LF_nul && | |
434 | check_files_in_repo input "text" LF LF LF LF_mix_CR LF_nul | |
435 | ' | |
436 | ||
437 | test_expect_success 'commit -text' ' | |
438 | check_files_in_repo false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && | |
439 | check_files_in_repo true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && | |
440 | check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
441 | ' | |
442 | ||
67e9bff0 TB |
443 | for crlf in true false input |
444 | do | |
445 | # attr aeol LF CRLF CRLF_mix_LF LF_mix_CR CRLFNUL | |
446 | check_in_repo_NNO "" "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
447 | check_in_repo_NNO -text "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
448 | check_in_repo_NNO -text lf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
449 | check_in_repo_NNO -text crlf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
65237284 TB |
450 | check_in_repo_NNO auto "" $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul |
451 | check_in_repo_NNO auto lf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
452 | check_in_repo_NNO auto crlf $crlf LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul | |
67e9bff0 TB |
453 | check_in_repo_NNO text "" $crlf LF LF LF LF_mix_CR LF_nul |
454 | check_in_repo_NNO text lf $crlf LF LF LF LF_mix_CR LF_nul | |
455 | check_in_repo_NNO text crlf $crlf LF LF LF LF_mix_CR LF_nul | |
456 | done | |
343151dc TB |
457 | ################################################################################ |
458 | # Check how files in the repo are changed when they are checked out | |
459 | # How to read the table below: | |
ad295bbc | 460 | # - checkout_files will check multiple files with a combination of settings |
f6975a6b | 461 | # and attributes (core.autocrlf=input is forbidden with core.eol=crlf) |
320d39cd TB |
462 | # |
463 | # - parameter $1 : text in .gitattributs "" (empty) | auto | text | -text | |
464 | # - parameter $2 : ident "" | i (i == ident) | |
465 | # - parameter $3 : eol in .gitattributs "" (empty) | lf | crlf | |
466 | # - parameter $4 : core.autocrlf false | true | input | |
467 | # - parameter $5 : core.eol "" | lf | crlf | "native" | |
468 | # - parameter $6 : reference for a file with only LF in the repo | |
469 | # - parameter $7 : reference for a file with only CRLF in the repo | |
470 | # - parameter $8 : reference for a file with mixed LF and CRLF in the repo | |
471 | # - parameter $9 : reference for a file with LF and CR in the repo | |
472 | # - parameter $10 : reference for a file with CRLF and a NUL (should be handled as binary when auto) | |
473 | ||
8eeab92f | 474 | if test_have_prereq NATIVE_CRLF |
343151dc | 475 | then |
f6975a6b TB |
476 | MIX_CRLF_LF=CRLF |
477 | MIX_LF_CR=CRLF_mix_CR | |
478 | NL=CRLF | |
8eeab92f | 479 | LFNUL=CRLF_nul |
f6975a6b TB |
480 | else |
481 | MIX_CRLF_LF=CRLF_mix_LF | |
482 | MIX_LF_CR=LF_mix_CR | |
483 | NL=LF | |
8eeab92f | 484 | LFNUL=LF_nul |
343151dc | 485 | fi |
f6975a6b TB |
486 | export CRLF_MIX_LF_CR MIX NL |
487 | ||
67e9bff0 | 488 | # Same handling with and without ident |
caa47adc | 489 | for id in "" ident |
320d39cd | 490 | do |
67e9bff0 TB |
491 | for ceol in lf crlf native |
492 | do | |
493 | for crlf in true false input | |
494 | do | |
495 | # -text overrides core.autocrlf and core.eol | |
496 | # text and eol=crlf or eol=lf override core.autocrlf and core.eol | |
497 | checkout_files -text "$id" "" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
498 | checkout_files -text "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
499 | checkout_files -text "$id" "crlf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
500 | # text | |
501 | checkout_files text "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
502 | checkout_files text "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul | |
503 | # currently the same as text, eol=XXX | |
504 | checkout_files auto "$id" "lf" "$crlf" "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
65237284 | 505 | checkout_files auto "$id" "crlf" "$crlf" "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul |
67e9bff0 TB |
506 | done |
507 | ||
508 | # core.autocrlf false, different core.eol | |
509 | checkout_files "" "$id" "" false "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
510 | # core.autocrlf true | |
511 | checkout_files "" "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
512 | # text: core.autocrlf = true overrides core.eol | |
65237284 | 513 | checkout_files auto "$id" "" true "$ceol" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul |
67e9bff0 TB |
514 | checkout_files text "$id" "" true "$ceol" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul |
515 | # text: core.autocrlf = input overrides core.eol | |
516 | checkout_files text "$id" "" input "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
517 | checkout_files auto "$id" "" input "$ceol" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
518 | # text=auto + eol=XXX | |
519 | done | |
520 | # text: core.autocrlf=false uses core.eol | |
521 | checkout_files text "$id" "" false crlf CRLF CRLF CRLF CRLF_mix_CR CRLF_nul | |
522 | checkout_files text "$id" "" false lf LF CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
523 | # text: core.autocrlf=false and core.eol unset(or native) uses native eol | |
524 | checkout_files text "$id" "" false "" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL | |
525 | checkout_files text "$id" "" false native $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL | |
526 | # auto: core.autocrlf=false and core.eol unset(or native) uses native eol | |
65237284 TB |
527 | checkout_files auto "$id" "" false "" $NL CRLF CRLF_mix_LF LF_mix_CR LF_nul |
528 | checkout_files auto "$id" "" false native $NL CRLF CRLF_mix_LF LF_mix_CR LF_nul | |
320d39cd | 529 | done |
343151dc | 530 | |
a7630bd4 TB |
531 | # Should be the last test case: remove some files from the worktree |
532 | test_expect_success 'ls-files --eol -d -z' ' | |
533 | rm crlf_false_attr__CRLF.txt crlf_false_attr__CRLF_mix_LF.txt crlf_false_attr__LF.txt .gitattributes && | |
534 | cat >expect <<-\EOF && | |
535 | i/crlf w/ crlf_false_attr__CRLF.txt | |
536 | i/lf w/ .gitattributes | |
537 | i/lf w/ crlf_false_attr__LF.txt | |
538 | i/mixed w/ crlf_false_attr__CRLF_mix_LF.txt | |
539 | EOF | |
540 | git ls-files --eol -d | | |
541 | sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" | | |
542 | sort >actual && | |
543 | test_cmp expect actual | |
544 | ' | |
545 | ||
343151dc | 546 | test_done |