@@ -55,14 +55,34 @@ create_gitattributes () {
5555 esac
5656}
5757
58+ create_NNO_files () {
59+ lfname=$1
60+ crlfname=$2
61+ lfmixcrlf=$3
62+ lfmixcr=$4
63+ crlfnul=$5
64+ for crlf in false true input
65+ do
66+ for attr in " " auto text -text lf crlf
67+ do
68+ 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
74+ done
75+ done
76+ }
77+
5878check_warning () {
5979 case " $1 " in
6080 LF_CRLF) echo " warning: LF will be replaced by CRLF" > " $2 " .expect ;;
6181 CRLF_LF) echo " warning: CRLF will be replaced by LF" > " $2 " .expect ;;
6282 ' ' ) > " $2 " .expect ;;
6383 * ) echo >&2 " Illegal 1" : " $1 " ; return false ;;
6484 esac
65- grep " will be replaced by" " $2 " | sed -e " s/\(.*\) in [^ ]*$/\1/" > " $2 " .actual
85+ grep " will be replaced by" " $2 " | sed -e " s/\(.*\) in [^ ]*$/\1/" | uniq > " $2 " .actual
6686 test_cmp " $2 " .expect " $2 " .actual
6787}
6888
@@ -71,19 +91,10 @@ commit_check_warn () {
7191 attr=$2
7292 lfname=$3
7393 crlfname=$4
74- repoMIX=$5
75- lfmixcrlf=$6
76- lfmixcr=$7
77- crlfnul=$8
94+ lfmixcrlf=$5
95+ lfmixcr=$6
96+ crlfnul=$7
7897 pfx=crlf_${crlf} _attr_${attr}
79- # Special handling for repoMIX: It should already be in the repo
80- # with CRLF
81- f=repoMIX
82- fname=${pfx} _$f .txt
83- echo > .gitattributes &&
84- cp $f $fname &&
85- git -c core.autocrlf=false add $fname 2> " ${pfx} _$f .err" &&
86- git commit -m " repoMIX" &&
8798 create_gitattributes " $attr " &&
8899 for f in LF CRLF repoMIX LF_mix_CR CRLF_mix_LF LF_nul CRLF_nul
89100 do
@@ -99,6 +110,45 @@ commit_check_warn () {
99110 check_warning " $crlfnul " ${pfx} _CRLF_nul.err
100111}
101112
113+ commit_chk_wrnNNO () {
114+ crlf=$1
115+ attr=$2
116+ lfwarn=$3
117+ crlfwarn=$4
118+ lfmixcrlf=$5
119+ lfmixcr=$6
120+ crlfnul=$7
121+ pfx=NNO_${crlf} _attr_${attr}
122+ # Commit files on top of existing file
123+ create_gitattributes " $attr " &&
124+ for f in LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
125+ do
126+ fname=${pfx} _$f .txt &&
127+ cp $f $fname &&
128+ git -c core.autocrlf=$crlf add $fname 2> /dev/null &&
129+ git -c core.autocrlf=$crlf commit -m " commit_$fname " $fname > " ${pfx} _$f .err" 2>&1
130+ done
131+
132+ test_expect_success " commit NNO files crlf=$crlf attr=$attr LF" '
133+ check_warning "$lfwarn" ${pfx}_LF.err
134+ '
135+ test_expect_success " commit NNO files crlf=$crlf attr=$attr CRLF" '
136+ check_warning "$crlfwarn" ${pfx}_CRLF.err
137+ '
138+
139+ test_expect_success " commit NNO files crlf=$crlf attr=$attr CRLF_mix_LF" '
140+ check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err
141+ '
142+
143+ test_expect_success " commit NNO files crlf=$crlf attr=$attr LF_mix_cr" '
144+ check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err
145+ '
146+
147+ test_expect_success " commit NNO files crlf=$crlf attr=$attr CRLF_nul" '
148+ check_warning "$crlfnul" ${pfx}_CRLF_nul.err
149+ '
150+ }
151+
102152check_files_in_repo () {
103153 crlf=$1
104154 attr=$2
@@ -115,6 +165,31 @@ check_files_in_repo () {
115165 compare_files $crlfnul ${pfx} CRLF_nul.txt
116166}
117167
168+ check_in_repo_NNO () {
169+ crlf=$1
170+ attr=$2
171+ lfname=$3
172+ crlfname=$4
173+ lfmixcrlf=$5
174+ lfmixcr=$6
175+ crlfnul=$7
176+ pfx=NNO_${crlf} _attr_${attr} _
177+ test_expect_success " compare_files $lfname ${pfx} LF.txt" '
178+ compare_files $lfname ${pfx}LF.txt
179+ '
180+ test_expect_success " compare_files $crlfname ${pfx} CRLF.txt" '
181+ compare_files $crlfname ${pfx}CRLF.txt
182+ '
183+ test_expect_success " compare_files $lfmixcrlf ${pfx} CRLF_mix_LF.txt" '
184+ compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt
185+ '
186+ test_expect_success " compare_files $lfmixcr ${pfx} LF_mix_CR.txt" '
187+ compare_files $lfmixcr ${pfx}LF_mix_CR.txt
188+ '
189+ test_expect_success " compare_files $crlfnul ${pfx} CRLF_nul.txt" '
190+ compare_files $crlfnul ${pfx}CRLF_nul.txt
191+ '
192+ }
118193
119194checkout_files () {
120195 eol=$1
@@ -169,7 +244,11 @@ test_expect_success 'setup master' '
169244 printf "line1\nline2\rline3" >LF_mix_CR &&
170245 printf "line1\r\nline2\rline3" >CRLF_mix_CR &&
171246 printf "line1Q\r\nline2\r\nline3" | q_to_nul >CRLF_nul &&
172- printf "line1Q\nline2\nline3" | q_to_nul >LF_nul
247+ printf "line1Q\nline2\nline3" | q_to_nul >LF_nul &&
248+ create_NNO_files CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF CRLF_mix_LF &&
249+ git -c core.autocrlf=false add NNO_*.txt &&
250+ git commit -m "mixed line endings" &&
251+ test_tick
173252'
174253
175254
@@ -191,46 +270,72 @@ else
191270 WAMIX=CRLF_LF
192271fi
193272
194- # attr LF CRLF repoMIX CRLFmixLF LFmixCR CRLFNUL
273+ # attr LF CRLF CRLFmixLF LFmixCR CRLFNUL
195274test_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" " " ""
275+ commit_check_warn false "" "" "" "" "" "" &&
276+ commit_check_warn true "" "LF_CRLF" "" "LF_CRLF" "" "" &&
277+ commit_check_warn input "" "" "CRLF_LF" "CRLF_LF" "" ""
199278'
200279
201280test_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" " " ""
281+ commit_check_warn false "auto" "$WILC" "$WICL" "$WAMIX" "" "" &&
282+ commit_check_warn true "auto" "LF_CRLF" "" "LF_CRLF" "" "" &&
283+ commit_check_warn input "auto" "" "CRLF_LF" "CRLF_LF" "" ""
205284'
206285
207286test_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"
287+ commit_check_warn false "text" "$WILC" "$WICL" "$WAMIX" "$WILC" "$WICL" &&
288+ commit_check_warn true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
289+ commit_check_warn input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
211290'
212291
213292test_expect_success ' commit files attr=-text' '
214- commit_check_warn false "-text" "" "" "" "" "" "" &&
215- commit_check_warn true "-text" "" "" "" "" "" "" &&
216- commit_check_warn input "-text" "" "" "" "" "" ""
293+ commit_check_warn false "-text" "" "" "" "" "" &&
294+ commit_check_warn true "-text" "" "" "" "" "" &&
295+ commit_check_warn input "-text" "" "" "" "" ""
217296'
218297
219298test_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"
299+ commit_check_warn false "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
300+ commit_check_warn true "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" &&
301+ commit_check_warn input "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF"
223302'
224303
225304test_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" " "
305+ commit_check_warn false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
306+ commit_check_warn true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" &&
307+ commit_check_warn input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" ""
229308'
230309
310+ # attr LF CRLF CRLFmixLF LF_mix_CR CRLFNUL
311+ commit_chk_wrnNNO false " " " " " " " " " " " "
312+ commit_chk_wrnNNO true " " " LF_CRLF" " " " " " " " "
313+ commit_chk_wrnNNO input " " " " " " " " " " " "
314+
315+
316+ commit_chk_wrnNNO false " auto" " $WILC " " $WICL " " $WAMIX " " " " "
317+ commit_chk_wrnNNO true " auto" " LF_CRLF" " " " LF_CRLF" " " " "
318+ commit_chk_wrnNNO input " auto" " " " CRLF_LF" " CRLF_LF" " " " "
319+
320+ commit_chk_wrnNNO false " text" " $WILC " " $WICL " " $WAMIX " " $WILC " " $WICL "
321+ commit_chk_wrnNNO true " text" " LF_CRLF" " " " LF_CRLF" " LF_CRLF" " "
322+ commit_chk_wrnNNO input " text" " " " CRLF_LF" " CRLF_LF" " " " CRLF_LF"
323+
324+ commit_chk_wrnNNO false " -text" " " " " " " " " " "
325+ commit_chk_wrnNNO true " -text" " " " " " " " " " "
326+ commit_chk_wrnNNO input " -text" " " " " " " " " " "
327+
328+ commit_chk_wrnNNO false " lf" " " " CRLF_LF" " CRLF_LF" " " " CRLF_LF"
329+ commit_chk_wrnNNO true " lf" " " " CRLF_LF" " CRLF_LF" " " " CRLF_LF"
330+ commit_chk_wrnNNO input " lf" " " " CRLF_LF" " CRLF_LF" " " " CRLF_LF"
331+
332+ commit_chk_wrnNNO false " crlf" " LF_CRLF" " " " LF_CRLF" " LF_CRLF" " "
333+ commit_chk_wrnNNO true " crlf" " LF_CRLF" " " " LF_CRLF" " LF_CRLF" " "
334+ commit_chk_wrnNNO input " crlf" " LF_CRLF" " " " LF_CRLF" " LF_CRLF" " "
335+
231336test_expect_success ' create files cleanup' '
232337 rm -f *.txt &&
233- git reset --hard
338+ git -c core.autocrlf=false reset --hard
234339'
235340
236341test_expect_success ' commit empty gitattribues' '
@@ -257,6 +362,24 @@ test_expect_success 'commit -text' '
257362 check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
258363'
259364
365+ # attr LF CRLF CRLF_mix_LF LF_mix_CR CRLFNUL
366+ check_in_repo_NNO false " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
367+ check_in_repo_NNO true " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
368+ check_in_repo_NNO input " " LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
369+
370+ check_in_repo_NNO false " auto" LF LF LF LF_mix_CR CRLF_nul
371+ check_in_repo_NNO true " auto" LF LF LF LF_mix_CR CRLF_nul
372+ check_in_repo_NNO input " auto" LF LF LF LF_mix_CR CRLF_nul
373+
374+ check_in_repo_NNO false " text" LF LF LF LF_mix_CR LF_nul
375+ check_in_repo_NNO true " text" LF LF LF LF_mix_CR LF_nul
376+ check_in_repo_NNO input " text" LF LF LF LF_mix_CR LF_nul
377+
378+ check_in_repo_NNO false " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
379+ check_in_repo_NNO true " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
380+ check_in_repo_NNO input " -text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul
381+
382+
260383# ###############################################################################
261384# Check how files in the repo are changed when they are checked out
262385# How to read the table below:
0 commit comments