56
}
57
58
create_NNO_files () {
59
- lfname=$1
60
- crlfname=$2
61
- lfmixcrlf=$3
62
- lfmixcr=$4
63
- crlfnul=$5
59
for crlf in false true input
60
do
61
for attr in "" auto text -text lf crlf
62
do
63
pfx=NNO_${crlf}_attr_${attr} &&
69
- cp $lfname ${pfx}_LF.txt &&
70
- cp $crlfname ${pfx}_CRLF.txt &&
71
- cp $lfmixcrlf ${pfx}_CRLF_mix_LF.txt &&
72
- cp $lfmixcr ${pfx}_LF_mix_CR.txt &&
73
- cp $crlfnul ${pfx}_CRLF_nul.txt
64
+ cp CRLF_mix_LF ${pfx}_LF.txt &&
65
+ cp CRLF_mix_LF ${pfx}_CRLF.txt &&
66
+ cp CRLF_mix_LF ${pfx}_CRLF_mix_LF.txt &&
67
+ cp CRLF_mix_LF ${pfx}_LF_mix_CR.txt &&
68
+ cp CRLF_mix_LF ${pfx}_CRLF_nul.txt
69
done
70
done
71
}
91
crlfnul=$7
92
pfx=crlf_${crlf}_attr_${attr}
93
create_gitattributes "$attr" &&
99
- for f in LF CRLF repoMIX LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul
94
+ for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul
95
do
96
fname=${pfx}_$f.txt &&
97
cp $f $fname &&
144
'
145
}
146
147
+stats_ascii () {
148
+ case "$1" in
149
+ LF)
150
+ echo lf
151
+ ;;
152
+ CRLF)
153
+ echo crlf
154
+ ;;
155
+ CRLF_mix_LF)
156
+ echo mixed
157
+ ;;
158
+ LF_mix_CR|CRLF_nul|LF_nul|CRLF_mix_CR)
159
+ echo "-text"
160
+ ;;
161
+ *)
162
+ echo error_invalid $1
163
+ ;;
164
+ esac
165
+
166
+}
167
+
168
check_files_in_repo () {
169
crlf=$1
170
attr=$2
219
create_gitattributes $attr &&
220
git config core.autocrlf $crlf &&
221
pfx=eol_${eol}_crlf_${crlf}_attr_${attr}_ &&
206
- src=crlf_false_attr__ &&
222
for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul
223
do
209
- rm $src$f.txt &&
224
+ rm crlf_false_attr__$f.txt &&
225
if test -z "$eol"; then
211
- git checkout $src$f.txt
226
+ git checkout crlf_false_attr__$f.txt
227
else
213
- git -c core.eol=$eol checkout $src$f.txt
228
+ git -c core.eol=$eol checkout crlf_false_attr__$f.txt
229
fi
230
done
231
232
+ test_expect_success "ls-files --eol $lfname ${pfx}LF.txt" '
233
+ test_when_finished "rm expect actual" &&
234
+ sort <<-EOF >expect &&
235
+ i/crlf w/$(stats_ascii $crlfname) crlf_false_attr__CRLF.txt
236
+ i/mixed w/$(stats_ascii $lfmixcrlf) crlf_false_attr__CRLF_mix_LF.txt
237
+ i/lf w/$(stats_ascii $lfname) crlf_false_attr__LF.txt
238
+ i/-text w/$(stats_ascii $lfmixcr) crlf_false_attr__LF_mix_CR.txt
239
+ i/-text w/$(stats_ascii $crlfnul) crlf_false_attr__CRLF_nul.txt
240
+ i/-text w/$(stats_ascii $crlfnul) crlf_false_attr__LF_nul.txt
241
+ EOF
242
+ git ls-files --eol crlf_false_attr__* |
243
+ sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" |
244
+ sort >actual &&
245
+ test_cmp expect actual
246
+ '
247
test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF" "
218
- compare_ws_file $pfx $lfname ${src}LF.txt
248
+ compare_ws_file $pfx $lfname crlf_false_attr__LF.txt
249
"
250
test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF" "
221
- compare_ws_file $pfx $crlfname ${src}CRLF.txt
251
+ compare_ws_file $pfx $crlfname crlf_false_attr__CRLF.txt
252
"
253
test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF_mix_LF" "
224
- compare_ws_file $pfx $lfmixcrlf ${src}CRLF_mix_LF.txt
254
+ compare_ws_file $pfx $lfmixcrlf crlf_false_attr__CRLF_mix_LF.txt
255
"
256
test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF_mix_CR" "
227
- compare_ws_file $pfx $lfmixcr ${src}LF_mix_CR.txt
257
+ compare_ws_file $pfx $lfmixcr crlf_false_attr__LF_mix_CR.txt
258
"
259
test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF_nul" "
230
- compare_ws_file $pfx $crlfnul ${src}LF_nul.txt
260
+ compare_ws_file $pfx $crlfnul crlf_false_attr__LF_nul.txt
261
"
262
}
263
234
-#######
264
+# Test control characters
265
+# NUL SOH CR EOF==^Z
266
+test_expect_success 'ls-files --eol -o Text/Binary' '
267
+ test_when_finished "rm expect actual TeBi_*" &&
268
+ STRT=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA &&
269
+ STR=$STRT$STRT$STRT$STRT &&
270
+ printf "${STR}BBB\001" >TeBi_127_S &&
271
+ printf "${STR}BBBB\001">TeBi_128_S &&
272
+ printf "${STR}BBB\032" >TeBi_127_E &&
273
+ printf "\032${STR}BBB" >TeBi_E_127 &&
274
+ printf "${STR}BBBB\000">TeBi_128_N &&
275
+ printf "${STR}BBB\012">TeBi_128_L &&
276
+ printf "${STR}BBB\015">TeBi_127_C &&
277
+ printf "${STR}BB\015\012" >TeBi_126_CL &&
278
+ printf "${STR}BB\015\012\015" >TeBi_126_CLC &&
279
+ sort <<-\EOF >expect &&
280
+ i/ w/-text TeBi_127_S
281
+ i/ w/none TeBi_128_S
282
+ i/ w/none TeBi_127_E
283
+ i/ w/-text TeBi_E_127
284
+ i/ w/-text TeBi_128_N
285
+ i/ w/lf TeBi_128_L
286
+ i/ w/-text TeBi_127_C
287
+ i/ w/crlf TeBi_126_CL
288
+ i/ w/-text TeBi_126_CLC
289
+ EOF
290
+ git ls-files --eol -o |
291
+ sed -n -e "/TeBi_/{s!attr/[ ]*!!g
292
+ s! ! !g
293
+ s! *! !g
294
+ p
295
+ }" | sort >actual &&
296
+ test_cmp expect actual
297
+'
298
+
299
test_expect_success 'setup master' '
300
echo >.gitattributes &&
301
git checkout -b master &&
544
checkout_files native false "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
545
checkout_files native true "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
546
547
+# Should be the last test case: remove some files from the worktree
548
+test_expect_success 'ls-files --eol -d -z' '
549
+ rm crlf_false_attr__CRLF.txt crlf_false_attr__CRLF_mix_LF.txt crlf_false_attr__LF.txt .gitattributes &&
550
+ cat >expect <<-\EOF &&
551
+ i/crlf w/ crlf_false_attr__CRLF.txt
552
+ i/lf w/ .gitattributes
553
+ i/lf w/ crlf_false_attr__LF.txt
554
+ i/mixed w/ crlf_false_attr__CRLF_mix_LF.txt
555
+ EOF
556
+ git ls-files --eol -d |
557
+ sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" |
558
+ sort >actual &&
559
+ test_cmp expect actual
560
+'
561
+
562
test_done