t0027: check the eol conversion warnings

Depending on the file content, eol parameters and .gitattributes "git add" may give a warning when the eol of a file will change when the file is checked out again. There are 2 different warnings, either "CRLF will be replaced..." or "LF will be replaced...". Let t0027 check for these warnings by adding new parameters to create_file_in_repo(), which tells what warnings are expected. When a file has eol=lf or eol=crlf in .gitattributes, it is handled as text and should be normalized. Add tests for these cases that were not covered. Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Nov 30, 2014 at 21:15 UTC 0291973b361bb739df9052d17bfbf2d1e63f2004
1 file changed +66 -16
t/t0027-auto-crlf.sh
+66 -16
@@ -55,16 +55,41 @@ create_gitattributes () {
55 esac
56 }
57
58 +check_warning () {
59 + case "$1" in
60 + LF_CRLF) grep "LF will be replaced by CRLF" $2;;
61 + CRLF_LF) grep "CRLF will be replaced by LF" $2;;
62 + '')
63 + >expect
64 + grep "will be replaced by" $2 >actual
65 + test_cmp expect actual
66 + ;;
67 + *) false ;;
68 + esac
69 +}
70 +
71 create_file_in_repo () {
72 crlf=$1
73 attr=$2
74 + lfname=$3
75 + crlfname=$4
76 + lfmixcrlf=$5
77 + lfmixcr=$6
78 + crlfnul=$7
79 create_gitattributes "$attr" &&
80 + pfx=crlf_${crlf}_attr_${attr}
81 for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul
82 do
64 - pfx=crlf_${crlf}_attr_${attr}_$f.txt &&
65 - cp $f $pfx && git -c core.autocrlf=$crlf add $pfx
83 + fname=${pfx}_$f.txt &&
84 + cp $f $fname &&
85 + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err"
86 done &&
67 - git commit -m "core.autocrlf $crlf"
87 + git commit -m "core.autocrlf $crlf" &&
88 + check_warning "$lfname" ${pfx}_LF.err &&
89 + check_warning "$crlfname" ${pfx}_CRLF.err &&
90 + check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err &&
91 + check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err &&
92 + check_warning "$crlfnul" ${pfx}_CRLF_nul.err
93 }
94
95 check_files_in_repo () {
@@ -140,22 +165,47 @@ test_expect_success 'setup master' '
165 '
166
167
143 -test_expect_success 'create files' '
144 - create_file_in_repo false "" &&
145 - create_file_in_repo true "" &&
146 - create_file_in_repo input "" &&
168
148 - create_file_in_repo false "auto" &&
149 - create_file_in_repo true "auto" &&
150 - create_file_in_repo input "auto" &&
169 +warn_LF_CRLF="LF will be replaced by CRLF"
170 +warn_CRLF_LF="CRLF will be replaced by LF"
171 +
172 +test_expect_success 'add files empty attr' '
173 + create_file_in_repo false "" "" "" "" "" "" &&
174 + create_file_in_repo true "" "LF_CRLF" "" "LF_CRLF" "" "" &&
175 + create_file_in_repo input "" "" "CRLF_LF" "CRLF_LF" "" ""
176 +'
177 +
178 +test_expect_success 'add files attr=auto' '
179 + create_file_in_repo false "auto" "" "CRLF_LF" "CRLF_LF" "" "" &&
180 + create_file_in_repo true "auto" "LF_CRLF" "" "LF_CRLF" "" "" &&
181 + create_file_in_repo input "auto" "" "CRLF_LF" "CRLF_LF" "" ""
182 +'
183 +
184 +test_expect_success 'add files attr=text' '
185 + create_file_in_repo false "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
186 + create_file_in_repo true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
187 + create_file_in_repo input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
188 +'
189 +
190 +test_expect_success 'add files attr=-text' '
191 + create_file_in_repo false "-text" "" "" "" "" "" &&
192 + create_file_in_repo true "-text" "" "" "" "" "" &&
193 + create_file_in_repo input "-text" "" "" "" "" ""
194 +'
195 +
196 +test_expect_success 'add files attr=lf' '
197 + create_file_in_repo false "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
198 + create_file_in_repo true "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
199 + create_file_in_repo input "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
200 +'
201
152 - create_file_in_repo false "text" &&
153 - create_file_in_repo true "text" &&
154 - create_file_in_repo input "text" &&
202 +test_expect_success 'add files attr=crlf' '
203 + create_file_in_repo false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
204 + create_file_in_repo true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
205 + create_file_in_repo input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" ""
206 +'
207
156 - create_file_in_repo false "-text" &&
157 - create_file_in_repo true "-text" &&
158 - create_file_in_repo input "-text" &&
208 +test_expect_success 'create files cleanup' '
209 rm -f *.txt &&
210 git reset --hard
211 '