3 test_description='CRLF conversion all combinations'
7 if ! test_have_prereq EXPENSIVE
9 skip_all="EXPENSIVE not set"
14 tr '\015\000' QN <"$1" >"$1".expect &&
15 tr '\015\000' QN <"$2" >"$2".actual &&
16 test_cmp "$1".expect "$2".actual &&
17 rm "$1".expect "$2".actual
24 tr '\015\000' QN <"$2" >"$exp" &&
25 tr '\015\000' QN <"$3" >"$act" &&
30 create_gitattributes () {
34 echo "*.txt text=auto" >.gitattributes
37 echo "*.txt text" >.gitattributes
40 echo "*.txt -text" >.gitattributes
43 echo "*.txt eol=crlf" >.gitattributes
46 echo "*.txt eol=lf" >.gitattributes
52 echo >&2 invalid attribute: $attr
60 LF_CRLF) echo "warning: LF will be replaced by CRLF" >"$2".expect ;;
61 CRLF_LF) echo "warning: CRLF will be replaced by LF" >"$2".expect ;;
63 *) echo >&2 "Illegal 1": "$1" ; return false ;;
65 grep "will be replaced by" "$2" | sed -e "s/\(.*\) in [^ ]*$/\1/" >"$2".actual
66 test_cmp "$2".expect "$2".actual
69 commit_check_warn () {
78 pfx=crlf_${crlf}_attr_${attr}
79 # Special handling for repoMIX: It should already be in the repo
83 echo >.gitattributes &&
85 git -c core.autocrlf=false add $fname 2>"${pfx}_$f.err" &&
86 git commit -m "repoMIX" &&
87 create_gitattributes "$attr" &&
88 for f in LF CRLF repoMIX LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul
90 fname=${pfx}_$f.txt &&
92 git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err"
94 git commit -m "core.autocrlf $crlf" &&
95 check_warning "$lfname" ${pfx}_LF.err &&
96 check_warning "$crlfname" ${pfx}_CRLF.err &&
97 check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err &&
98 check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err &&
99 check_warning "$crlfnul" ${pfx}_CRLF_nul.err
102 check_files_in_repo () {
110 pfx=crlf_${crlf}_attr_${attr}_ &&
111 compare_files $lfname ${pfx}LF.txt &&
112 compare_files $crlfname ${pfx}CRLF.txt &&
113 compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt &&
114 compare_files $lfmixcr ${pfx}LF_mix_CR.txt &&
115 compare_files $crlfnul ${pfx}CRLF_nul.txt
128 create_gitattributes $attr &&
129 git config core.autocrlf $crlf &&
130 pfx=eol_${eol}_crlf_${crlf}_attr_${attr}_ &&
131 src=crlf_false_attr__ &&
132 for f in LF CRLF LF_mix_CR CRLF_mix_LF LF_nul
135 if test -z "$eol"; then
136 git checkout $src$f.txt
138 git -c core.eol=$eol checkout $src$f.txt
142 test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF" "
143 compare_ws_file $pfx $lfname ${src}LF.txt
145 test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF" "
146 compare_ws_file $pfx $crlfname ${src}CRLF.txt
148 test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF_mix_LF" "
149 compare_ws_file $pfx $lfmixcrlf ${src}CRLF_mix_LF.txt
151 test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF_mix_CR" "
152 compare_ws_file $pfx $lfmixcr ${src}LF_mix_CR.txt
154 test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF_nul" "
155 compare_ws_file $pfx $crlfnul ${src}LF_nul.txt
160 test_expect_success 'setup master' '
161 echo >.gitattributes &&
162 git checkout -b master &&
163 git add .gitattributes &&
164 git commit -m "add .gitattributes" "" &&
165 printf "line1\nline2\nline3" >LF &&
166 printf "line1\r\nline2\r\nline3" >CRLF &&
167 printf "line1\r\nline2\nline3" >repoMIX &&
168 printf "line1\r\nline2\nline3" >CRLF_mix_LF &&
169 printf "line1\nline2\rline3" >LF_mix_CR &&
170 printf "line1\r\nline2\rline3" >CRLF_mix_CR &&
171 printf "line1Q\r\nline2\r\nline3" | q_to_nul >CRLF_nul &&
172 printf "line1Q\nline2\nline3" | q_to_nul >LF_nul
177 warn_LF_CRLF="LF will be replaced by CRLF"
178 warn_CRLF_LF="CRLF will be replaced by LF"
180 # WILC stands for "Warn if (this OS) converts LF into CRLF".
181 # WICL: Warn if CRLF becomes LF
182 # WAMIX: Mixed line endings: either CRLF->LF or LF->CRLF
183 if test_have_prereq NATIVE_CRLF
194 # attr LF CRLF repoMIX CRLFmixLF LFmixCR CRLFNUL
195 test_expect_success 'commit files empty attr' '
196 commit_check_warn false "" "" "" "" "" "" "" &&
197 commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" "" &&
198 commit_check_warn input "" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" ""
201 test_expect_success 'commit files attr=auto' '
202 commit_check_warn false "auto" "$WILC" "$WICL" "$WAMIX" "$WAMIX" "" "" &&
203 commit_check_warn true "auto" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" "" &&
204 commit_check_warn input "auto" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" ""
207 test_expect_success 'commit files attr=text' '
208 commit_check_warn false "text" "$WILC" "$WICL" "$WAMIX" "$WAMIX" "$WILC" "$WICL" &&
209 commit_check_warn true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "LF_CRLF" "" &&
210 commit_check_warn input "text" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
213 test_expect_success 'commit files attr=-text' '
214 commit_check_warn false "-text" "" "" "" "" "" "" &&
215 commit_check_warn true "-text" "" "" "" "" "" "" &&
216 commit_check_warn input "-text" "" "" "" "" "" ""
219 test_expect_success 'commit files attr=lf' '
220 commit_check_warn false "lf" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
221 commit_check_warn true "lf" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
222 commit_check_warn input "lf" "" "CRLF_LF" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
225 test_expect_success 'commit files attr=crlf' '
226 commit_check_warn false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "LF_CRLF" "" &&
227 commit_check_warn true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "LF_CRLF" "" &&
228 commit_check_warn input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "LF_CRLF" ""
231 test_expect_success 'create files cleanup' '
236 test_expect_success 'commit empty gitattribues' '
237 check_files_in_repo false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
238 check_files_in_repo true "" LF LF LF LF_mix_CR CRLF_nul &&
239 check_files_in_repo input "" LF LF LF LF_mix_CR CRLF_nul
242 test_expect_success 'commit text=auto' '
243 check_files_in_repo false "auto" LF LF LF LF_mix_CR CRLF_nul &&
244 check_files_in_repo true "auto" LF LF LF LF_mix_CR CRLF_nul &&
245 check_files_in_repo input "auto" LF LF LF LF_mix_CR CRLF_nul
248 test_expect_success 'commit text' '
249 check_files_in_repo false "text" LF LF LF LF_mix_CR LF_nul &&
250 check_files_in_repo true "text" LF LF LF LF_mix_CR LF_nul &&
251 check_files_in_repo input "text" LF LF LF LF_mix_CR LF_nul
254 test_expect_success 'commit -text' '
255 check_files_in_repo false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
256 check_files_in_repo true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul &&
257 check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
260 ################################################################################
261 # Check how files in the repo are changed when they are checked out
262 # How to read the table below:
263 # - checkout_files will check multiple files with a combination of settings
264 # and attributes (core.autocrlf=input is forbidden with core.eol=crlf)
265 # - parameter $1 : core.eol lf | crlf
266 # - parameter $2 : core.autocrlf false | true | input
267 # - parameter $3 : text in .gitattributs "" (empty) | auto | text | -text
268 # - parameter $4 : reference for a file with only LF in the repo
269 # - parameter $5 : reference for a file with only CRLF in the repo
270 # - parameter $6 : reference for a file with mixed LF and CRLF in the repo
271 # - parameter $7 : reference for a file with LF and CR in the repo (does somebody uses this ?)
272 # - parameter $8 : reference for a file with CRLF and a NUL (should be handled as binary when auto)
274 # What we have in the repo:
275 # ----------------- EOL in repo ----------------
276 # LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
277 # settings with checkout:
278 # core. core. .gitattr
280 # ----------------------------------------------
281 # What we want to have in the working tree:
282 if test_have_prereq NATIVE_CRLF
285 MIX_LF_CR=CRLF_mix_CR
289 MIX_CRLF_LF=CRLF_mix_LF
294 export CRLF_MIX_LF_CR MIX NL
296 checkout_files lf false "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
297 checkout_files lf true "" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
298 checkout_files lf input "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
299 checkout_files lf false "auto" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
300 checkout_files lf true "auto" CRLF CRLF CRLF LF_mix_CR LF_nul
301 checkout_files lf input "auto" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
302 checkout_files lf false "text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
303 checkout_files lf true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
304 checkout_files lf input "text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
305 checkout_files lf false "-text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
306 checkout_files lf true "-text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
307 checkout_files lf input "-text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
308 checkout_files lf false "lf" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
309 checkout_files lf true "lf" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
310 checkout_files lf input "lf" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
311 checkout_files lf false "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
312 checkout_files lf true "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
313 checkout_files lf input "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
315 checkout_files crlf false "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
316 checkout_files crlf true "" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
317 checkout_files crlf false "auto" CRLF CRLF CRLF LF_mix_CR LF_nul
318 checkout_files crlf true "auto" CRLF CRLF CRLF LF_mix_CR LF_nul
319 checkout_files crlf false "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
320 checkout_files crlf true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
321 checkout_files crlf false "-text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
322 checkout_files crlf true "-text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
323 checkout_files crlf false "lf" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
324 checkout_files crlf true "lf" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
325 checkout_files crlf false "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
326 checkout_files crlf true "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
328 checkout_files "" false "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
329 checkout_files "" true "" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
330 checkout_files "" input "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
331 checkout_files "" false "auto" $NL CRLF $MIX_CRLF_LF LF_mix_CR LF_nul
332 checkout_files "" true "auto" CRLF CRLF CRLF LF_mix_CR LF_nul
333 checkout_files "" input "auto" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
334 checkout_files "" false "text" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL
335 checkout_files "" true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
336 checkout_files "" input "text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
337 checkout_files "" false "-text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
338 checkout_files "" true "-text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
339 checkout_files "" input "-text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
340 checkout_files "" false "lf" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
341 checkout_files "" true "lf" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
342 checkout_files "" input "lf" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
343 checkout_files "" false "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
344 checkout_files "" true "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
345 checkout_files "" input "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
347 checkout_files native false "" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
348 checkout_files native true "" CRLF CRLF CRLF_mix_LF LF_mix_CR LF_nul
349 checkout_files native false "auto" $NL CRLF $MIX_CRLF_LF LF_mix_CR LF_nul
350 checkout_files native true "auto" CRLF CRLF CRLF LF_mix_CR LF_nul
351 checkout_files native false "text" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR $LFNUL
352 checkout_files native true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
353 checkout_files native false "-text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
354 checkout_files native true "-text" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
355 checkout_files native false "lf" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
356 checkout_files native true "lf" LF CRLF CRLF_mix_LF LF_mix_CR LF_nul
357 checkout_files native false "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul
358 checkout_files native true "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul