@@ -55,16 +55,41 @@ create_gitattributes () {
5555 esac
5656}
5757
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+
5871create_file_in_repo () {
5972 crlf=$1
6073 attr=$2
74+ lfname=$3
75+ crlfname=$4
76+ lfmixcrlf=$5
77+ lfmixcr=$6
78+ crlfnul=$7
6179 create_gitattributes " $attr " &&
80+ pfx=crlf_${crlf} _attr_${attr}
6281 for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul
6382 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"
6686 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
6893}
6994
7095check_files_in_repo () {
@@ -140,22 +165,47 @@ test_expect_success 'setup master' '
140165'
141166
142167
143- test_expect_success ' create files' '
144- create_file_in_repo false "" &&
145- create_file_in_repo true "" &&
146- create_file_in_repo input "" &&
147168
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+ '
151201
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+ '
155207
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' '
159209 rm -f *.txt &&
160210 git reset --hard
161211'
0 commit comments