3 test_description
='CRLF conversion'
16 sed -e 's/$/Q/' |
tr Q
'\015'
20 tr '\015' Q
<"$1" |
grep Q
>/dev
/null
&&
21 tr '\015' Q
<"$1" |
sed -ne 's/Q$//p'
24 test_expect_success setup
'
26 git config core.autocrlf false &&
28 for w in Hello world how are you; do echo $w; done >one &&
30 for w in I am very very fine thank you; do echo $w; done >dir/two &&
31 for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three &&
34 git commit -m initial &&
36 one=`git rev-parse HEAD:one` &&
37 dir=`git rev-parse HEAD:dir` &&
38 two=`git rev-parse HEAD:dir/two` &&
39 three=`git rev-parse HEAD:three` &&
41 for w in Some extra lines here; do echo $w; done >>one &&
42 git diff >patch.file &&
43 patched=`git hash-object --stdin <one` &&
44 git read-tree --reset -u HEAD &&
49 test_expect_success
'safecrlf: autocrlf=input, all CRLF' '
51 git config core.autocrlf input &&
52 git config core.safecrlf true &&
54 for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
55 test_must_fail git add allcrlf
58 test_expect_success
'safecrlf: autocrlf=input, mixed LF/CRLF' '
60 git config core.autocrlf input &&
61 git config core.safecrlf true &&
63 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
64 test_must_fail git add mixed
67 test_expect_success
'safecrlf: autocrlf=true, all LF' '
69 git config core.autocrlf true &&
70 git config core.safecrlf true &&
72 for w in I am all LF; do echo $w; done >alllf &&
73 test_must_fail git add alllf
76 test_expect_success
'safecrlf: autocrlf=true mixed LF/CRLF' '
78 git config core.autocrlf true &&
79 git config core.safecrlf true &&
81 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
82 test_must_fail git add mixed
85 test_expect_success
'safecrlf: print warning only once' '
87 git config core.autocrlf input &&
88 git config core.safecrlf warn &&
90 for w in I am all LF; do echo $w; done >doublewarn &&
92 git commit -m "nowarn" &&
93 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >doublewarn &&
94 test $(git add doublewarn 2>&1 | grep "CRLF will be replaced by LF" | wc -l) = 1
97 test_expect_success
'switch off autocrlf, safecrlf, reset HEAD' '
98 git config core.autocrlf false &&
99 git config core.safecrlf false &&
100 git reset --hard HEAD^
103 test_expect_success
'update with autocrlf=input' '
105 rm -f tmp one dir/two three &&
106 git read-tree --reset -u HEAD &&
107 git config core.autocrlf input &&
111 append_cr <$f >tmp && mv -f tmp $f &&
112 git update-index -- $f || {
119 differs=`git diff-index --cached HEAD` &&
120 test -z "$differs" || {
127 test_expect_success
'update with autocrlf=true' '
129 rm -f tmp one dir/two three &&
130 git read-tree --reset -u HEAD &&
131 git config core.autocrlf true &&
135 append_cr <$f >tmp && mv -f tmp $f &&
136 git update-index -- $f || {
143 differs=`git diff-index --cached HEAD` &&
144 test -z "$differs" || {
151 test_expect_success
'checkout with autocrlf=true' '
153 rm -f tmp one dir/two three &&
154 git config core.autocrlf true &&
155 git read-tree --reset -u HEAD &&
159 remove_cr "$f" >tmp && mv -f tmp $f &&
160 git update-index -- $f || {
166 test "$one" = `git hash-object --stdin <one` &&
167 test "$two" = `git hash-object --stdin <dir/two` &&
168 differs=`git diff-index --cached HEAD` &&
169 test -z "$differs" || {
175 test_expect_success
'checkout with autocrlf=input' '
177 rm -f tmp one dir/two three &&
178 git config core.autocrlf input &&
179 git read-tree --reset -u HEAD &&
183 if remove_cr "$f" >/dev/null
189 git update-index -- $f
192 test "$one" = `git hash-object --stdin <one` &&
193 test "$two" = `git hash-object --stdin <dir/two` &&
194 differs=`git diff-index --cached HEAD` &&
195 test -z "$differs" || {
201 test_expect_success
'apply patch (autocrlf=input)' '
203 rm -f tmp one dir/two three &&
204 git config core.autocrlf input &&
205 git read-tree --reset -u HEAD &&
207 git apply patch.file &&
208 test "$patched" = "`git hash-object --stdin <one`" || {
209 echo "Eh? apply without index"
214 test_expect_success
'apply patch --cached (autocrlf=input)' '
216 rm -f tmp one dir/two three &&
217 git config core.autocrlf input &&
218 git read-tree --reset -u HEAD &&
220 git apply --cached patch.file &&
221 test "$patched" = `git rev-parse :one` || {
222 echo "Eh? apply with --cached"
227 test_expect_success
'apply patch --index (autocrlf=input)' '
229 rm -f tmp one dir/two three &&
230 git config core.autocrlf input &&
231 git read-tree --reset -u HEAD &&
233 git apply --index patch.file &&
234 test "$patched" = `git rev-parse :one` &&
235 test "$patched" = `git hash-object --stdin <one` || {
236 echo "Eh? apply with --index"
241 test_expect_success
'apply patch (autocrlf=true)' '
243 rm -f tmp one dir/two three &&
244 git config core.autocrlf true &&
245 git read-tree --reset -u HEAD &&
247 git apply patch.file &&
248 test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
249 echo "Eh? apply without index"
254 test_expect_success
'apply patch --cached (autocrlf=true)' '
256 rm -f tmp one dir/two three &&
257 git config core.autocrlf true &&
258 git read-tree --reset -u HEAD &&
260 git apply --cached patch.file &&
261 test "$patched" = `git rev-parse :one` || {
262 echo "Eh? apply without index"
267 test_expect_success
'apply patch --index (autocrlf=true)' '
269 rm -f tmp one dir/two three &&
270 git config core.autocrlf true &&
271 git read-tree --reset -u HEAD &&
273 git apply --index patch.file &&
274 test "$patched" = `git rev-parse :one` &&
275 test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
276 echo "Eh? apply with --index"
281 test_expect_success
'.gitattributes says two is binary' '
283 rm -f tmp one dir/two three &&
284 echo "two -crlf" >.gitattributes &&
285 git config core.autocrlf true &&
286 git read-tree --reset -u HEAD &&
288 if remove_cr dir/two >/dev/null
296 if remove_cr one >/dev/null
304 if remove_cr three >/dev/null
313 test_expect_success
'.gitattributes says two is input' '
315 rm -f tmp one dir/two three &&
316 echo "two crlf=input" >.gitattributes &&
317 git read-tree --reset -u HEAD &&
319 if remove_cr dir/two >/dev/null
328 test_expect_success
'.gitattributes says two and three are text' '
330 rm -f tmp one dir/two three &&
331 echo "t* crlf" >.gitattributes &&
332 git read-tree --reset -u HEAD &&
334 if remove_cr dir/two >/dev/null
342 if remove_cr three >/dev/null
351 test_expect_success
'in-tree .gitattributes (1)' '
353 echo "one -crlf" >>.gitattributes &&
354 git add .gitattributes &&
355 git commit -m "Add .gitattributes" &&
357 rm -rf tmp one dir .gitattributes patch.file three &&
358 git read-tree --reset -u HEAD &&
360 if remove_cr one >/dev/null
362 echo "Eh? one should not have CRLF"
367 remove_cr three >/dev/null || {
368 echo "Eh? three should still have CRLF"
373 test_expect_success
'in-tree .gitattributes (2)' '
375 rm -rf tmp one dir .gitattributes patch.file three &&
376 git read-tree --reset HEAD &&
377 git checkout-index -f -q -u -a &&
379 if remove_cr one >/dev/null
381 echo "Eh? one should not have CRLF"
386 remove_cr three >/dev/null || {
387 echo "Eh? three should still have CRLF"
392 test_expect_success
'in-tree .gitattributes (3)' '
394 rm -rf tmp one dir .gitattributes patch.file three &&
395 git read-tree --reset HEAD &&
396 git checkout-index -u .gitattributes &&
397 git checkout-index -u one dir/two three &&
399 if remove_cr one >/dev/null
401 echo "Eh? one should not have CRLF"
406 remove_cr three >/dev/null || {
407 echo "Eh? three should still have CRLF"
412 test_expect_success
'in-tree .gitattributes (4)' '
414 rm -rf tmp one dir .gitattributes patch.file three &&
415 git read-tree --reset HEAD &&
416 git checkout-index -u one dir/two three &&
417 git checkout-index -u .gitattributes &&
419 if remove_cr one >/dev/null
421 echo "Eh? one should not have CRLF"
426 remove_cr three >/dev/null || {
427 echo "Eh? three should still have CRLF"
432 test_expect_success
'invalid .gitattributes (must not crash)' '
434 echo "three +crlf" >>.gitattributes &&