@@ -4,36 +4,32 @@ test_description='CRLF conversion all combinations'
44
55. ./test-lib.sh
66
7- if ! test_have_prereq EXPENSIVE
7+ if ! test_have_prereq EXPENSIVE && ! test_have_prereq MINGW
88then
9- skip_all=" EXPENSIVE not set"
9+ skip_all=" Neither EXPENSIVE nor MINGW set"
1010 test_done
1111fi
1212
13-
14- compare_files ()
15- {
16- od -c < " $1 " > " $1 " .expect &&
17- od -c < " $2 " > " $2 " .actual &&
13+ compare_files () {
14+ tr ' \015\000' QN < " $1 " > " $1 " .expect &&
15+ tr ' \015\000' QN < " $2 " > " $2 " .actual &&
1816 test_cmp " $1 " .expect " $2 " .actual &&
1917 rm " $1 " .expect " $2 " .actual
2018}
2119
22- compare_ws_file ()
23- {
20+ compare_ws_file () {
2421 pfx=$1
2522 exp=$2 .expect
2623 act=$pfx .actual.$3
27- od -c < " $2 " > " $exp " &&
28- od -c < " $3 " > " $act " &&
24+ tr ' \015\000 ' QN < " $2 " > " $exp " &&
25+ tr ' \015\000 ' QN < " $3 " > " $act " &&
2926 test_cmp $exp $act &&
3027 rm $exp $act
3128}
3229
33- create_gitattributes ()
34- {
35- txtbin=$1
36- case " $txtbin " in
30+ create_gitattributes () {
31+ attr=$1
32+ case " $attr " in
3733 auto)
3834 echo " *.txt text=auto" > .gitattributes
3935 ;;
@@ -43,35 +39,43 @@ create_gitattributes()
4339 -text)
4440 echo " *.txt -text" > .gitattributes
4541 ;;
46- * )
42+ crlf)
43+ echo " *.txt eol=crlf" > .gitattributes
44+ ;;
45+ lf)
46+ echo " *.txt eol=lf" > .gitattributes
47+ ;;
48+ " " )
4749 echo > .gitattributes
4850 ;;
51+ * )
52+ echo >&2 invalid attribute: $attr
53+ exit 1
54+ ;;
4955 esac
5056}
5157
52- create_file_in_repo ()
53- {
58+ create_file_in_repo () {
5459 crlf=$1
55- txtbin =$2
56- create_gitattributes " $txtbin " &&
60+ attr =$2
61+ create_gitattributes " $attr " &&
5762 for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul
5863 do
59- pfx=crlf_${crlf} _attr_${txtbin } _$f .txt &&
64+ pfx=crlf_${crlf} _attr_${attr } _$f .txt &&
6065 cp $f $pfx && git -c core.autocrlf=$crlf add $pfx
6166 done &&
6267 git commit -m " core.autocrlf $crlf "
6368}
6469
65- check_files_in_repo ()
66- {
70+ check_files_in_repo () {
6771 crlf=$1
68- txtbin =$2
72+ attr =$2
6973 lfname=$3
7074 crlfname=$4
7175 lfmixcrlf=$5
7276 lfmixcr=$6
7377 crlfnul=$7
74- pfx=crlf_${crlf} _attr_${txtbin } _ &&
78+ pfx=crlf_${crlf} _attr_${attr } _ &&
7579 compare_files $lfname ${pfx} LF.txt &&
7680 compare_files $crlfname ${pfx} CRLF.txt &&
7781 compare_files $lfmixcrlf ${pfx} CRLF_mix_LF.txt &&
@@ -80,19 +84,18 @@ check_files_in_repo()
8084}
8185
8286
83- check_files_in_ws ()
84- {
87+ check_files_in_ws () {
8588 eol=$1
8689 crlf=$2
87- txtbin =$3
90+ attr =$3
8891 lfname=$4
8992 crlfname=$5
9093 lfmixcrlf=$6
9194 lfmixcr=$7
9295 crlfnul=$8
93- create_gitattributes $txtbin &&
96+ create_gitattributes $attr &&
9497 git config core.autocrlf $crlf &&
95- pfx=eol_${eol} _crlf_${crlf} _attr_${txtbin } _ &&
98+ pfx=eol_${eol} _crlf_${crlf} _attr_${attr } _ &&
9699 src=crlf_false_attr__ &&
97100 for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul
98101 do
@@ -104,42 +107,24 @@ check_files_in_ws()
104107 fi
105108 done
106109
107-
108- test_expect_success " checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=LF" "
110+ test_expect_success " checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF" "
109111 compare_ws_file $pfx $lfname ${src} LF.txt
110112 "
111- test_expect_success " checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF" "
113+ test_expect_success " checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF" "
112114 compare_ws_file $pfx $crlfname ${src} CRLF.txt
113115 "
114- test_expect_success " checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF_mix_LF" "
116+ test_expect_success " checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF_mix_LF" "
115117 compare_ws_file $pfx $lfmixcrlf ${src} CRLF_mix_LF.txt
116118 "
117- test_expect_success " checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=LF_mix_CR" "
119+ test_expect_success " checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF_mix_CR" "
118120 compare_ws_file $pfx $lfmixcr ${src} LF_mix_CR.txt
119121 "
120- test_expect_success " checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF_nul" "
122+ test_expect_success " checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF_nul" "
121123 compare_ws_file $pfx $crlfnul ${src} CRLF_nul.txt
122124 "
123125}
124126
125127# ######
126- (
127- type od > /dev/null &&
128- printf " line1Q\r\nline2\r\nline3" | q_to_nul > CRLF_nul &&
129- cat > expect << -EOF &&
130- 0000000 l i n e 1 \0 \r \n l i n e 2 \r \n l
131- 0000020 i n e 3
132- 0000024
133- EOF
134- od -c CRLF_nul | sed -e " s/[ ][ ]*/ /g" -e " s/ *$//" > actual
135- test_cmp expect actual &&
136- rm expect actual
137- ) || {
138- skip_all=" od not found or od -c not usable"
139- exit 0
140- test_done
141- }
142-
143128test_expect_success ' setup master' '
144129 echo >.gitattributes &&
145130 git checkout -b master &&
@@ -150,9 +135,10 @@ test_expect_success 'setup master' '
150135 printf "line1\r\nline2\nline3" >CRLF_mix_LF &&
151136 printf "line1\nline2\rline3" >LF_mix_CR &&
152137 printf "line1\r\nline2\rline3" >CRLF_mix_CR &&
138+ printf "line1Q\r\nline2\r\nline3" | q_to_nul >CRLF_nul &&
153139 printf "line1Q\nline2\nline3" | q_to_nul >LF_nul
154140'
155- # CRLF_nul had been created above
141+
156142
157143test_expect_success ' create files' '
158144 create_file_in_repo false "" &&
@@ -201,7 +187,8 @@ test_expect_success 'commit -text' '
201187# ###############################################################################
202188# Check how files in the repo are changed when they are checked out
203189# How to read the table below:
204- # - check_files_in_ws will check multiple files, see below
190+ # - check_files_in_ws will check multiple files with a combination of settings
191+ # and attributes (core.autocrlf=input is forbidden with core.eol=crlf)
205192# - parameter $1 : core.eol lf | crlf
206193# - parameter $2 : core.autocrlf false | true | input
207194# - parameter $3 : text in .gitattributs "" (empty) | auto | text | -text
@@ -211,55 +198,88 @@ test_expect_success 'commit -text' '
211198# - parameter $7 : reference for a file with LF and CR in the repo (does somebody uses this ?)
212199# - parameter $8 : reference for a file with CRLF and a NUL (should be handled as binary when auto)
213200
214- check_files_in_ws lf false " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
215- check_files_in_ws lf true " " CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
216- check_files_in_ws lf input " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
217-
218- check_files_in_ws lf false " auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
219- check_files_in_ws lf true " auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul
220- check_files_in_ws lf input " auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
221-
222- check_files_in_ws lf false " text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
223- check_files_in_ws lf true " text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
224- check_files_in_ws lf input " text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
225-
226- check_files_in_ws lf false " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
227- check_files_in_ws lf true " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
228- check_files_in_ws lf input " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
229-
230- # ##########
231- # core.autocrlf=input is forbidden with core.eol=crlf
232- check_files_in_ws crlf false " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
233- check_files_in_ws crlf true " " CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
234-
235- check_files_in_ws crlf false " auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul
236- check_files_in_ws crlf true " auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul
237-
238- check_files_in_ws crlf false " text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
239- check_files_in_ws crlf true " text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
240-
241- check_files_in_ws crlf false " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
242- check_files_in_ws crlf true " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
243-
201+ # What we have in the repo:
202+ # ----------------- EOL in repo ----------------
203+ # LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
204+ # settings with checkout:
205+ # core. core. .gitattr
206+ # eol acrlf
207+ # ----------------------------------------------
208+ # What we want to have in the working tree:
244209if test_have_prereq MINGW
245210then
246- check_files_in_ws " " false " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
247- check_files_in_ws " " true " " CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
248- check_files_in_ws " " false " auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
249- check_files_in_ws " " true " auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul
250- check_files_in_ws " " false " text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
251- check_files_in_ws " " true " text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
252- check_files_in_ws " " false " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
253- check_files_in_ws " " true " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
254-
255- check_files_in_ws native false " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
256- check_files_in_ws native true " " CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
257- check_files_in_ws native false " auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
258- check_files_in_ws native true " auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul
259- check_files_in_ws native false " text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
260- check_files_in_ws native true " text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
261- check_files_in_ws native false " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
262- check_files_in_ws native true " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
211+ MIX_CRLF_LF=CRLF
212+ MIX_LF_CR=CRLF_mix_CR
213+ NL=CRLF
214+ else
215+ MIX_CRLF_LF=CRLF_mix_LF
216+ MIX_LF_CR=LF_mix_CR
217+ NL=LF
263218fi
219+ export CRLF_MIX_LF_CR MIX NL
220+
221+ check_files_in_ws lf false " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
222+ check_files_in_ws lf true " " CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
223+ check_files_in_ws lf input " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
224+ check_files_in_ws lf false " auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
225+ check_files_in_ws lf true " auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul
226+ check_files_in_ws lf input " auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
227+ check_files_in_ws lf false " text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
228+ check_files_in_ws lf true " text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
229+ check_files_in_ws lf input " text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
230+ check_files_in_ws lf false " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
231+ check_files_in_ws lf true " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
232+ check_files_in_ws lf input " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
233+ check_files_in_ws lf false " lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
234+ check_files_in_ws lf true " lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
235+ check_files_in_ws lf input " lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
236+ check_files_in_ws lf false " crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
237+ check_files_in_ws lf true " crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
238+ check_files_in_ws lf input " crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
239+
240+ check_files_in_ws crlf false " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
241+ check_files_in_ws crlf true " " CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
242+ check_files_in_ws crlf false " auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul
243+ check_files_in_ws crlf true " auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul
244+ check_files_in_ws crlf false " text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
245+ check_files_in_ws crlf true " text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
246+ check_files_in_ws crlf false " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
247+ check_files_in_ws crlf true " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
248+ check_files_in_ws crlf false " lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
249+ check_files_in_ws crlf true " lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
250+ check_files_in_ws crlf false " crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
251+ check_files_in_ws crlf true " crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
252+
253+ check_files_in_ws " " false " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
254+ check_files_in_ws " " true " " CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
255+ check_files_in_ws " " input " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
256+ check_files_in_ws " " false " auto" $NL CRLF $MIX_CRLF_LF LF_mix_CR CRLF_nul
257+ check_files_in_ws " " true " auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul
258+ check_files_in_ws " " input " auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
259+ check_files_in_ws " " false " text" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR CRLF_nul
260+ check_files_in_ws " " true " text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
261+ check_files_in_ws " " input " text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
262+ check_files_in_ws " " false " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
263+ check_files_in_ws " " true " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
264+ check_files_in_ws " " input " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
265+ check_files_in_ws " " false " lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
266+ check_files_in_ws " " true " lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
267+ check_files_in_ws " " input " lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
268+ check_files_in_ws " " false " crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
269+ check_files_in_ws " " true " crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
270+ check_files_in_ws " " input " crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
271+
272+ check_files_in_ws native false " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
273+ check_files_in_ws native true " " CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
274+ check_files_in_ws native false " auto" $NL CRLF $MIX_CRLF_LF LF_mix_CR CRLF_nul
275+ check_files_in_ws native true " auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul
276+ check_files_in_ws native false " text" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR CRLF_nul
277+ check_files_in_ws native true " text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
278+ check_files_in_ws native false " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
279+ check_files_in_ws native true " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
280+ check_files_in_ws native false " lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
281+ check_files_in_ws native true " lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
282+ check_files_in_ws native false " crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
283+ check_files_in_ws native true " crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
264284
265285test_done
0 commit comments