cocci: apply "pending" index-compatibility to "t/helper/*.c"
[git/debian.git] / t / t0026-eol-config.sh
blobf426a185bb9b32e732c0404d65237f8278435f0e
1 #!/bin/sh
3 test_description='CRLF conversion'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 has_cr() {
9 tr '\015' Q <"$1" | grep Q >/dev/null
12 test_expect_success setup '
14 git config core.autocrlf false &&
16 echo "one text" > .gitattributes &&
18 test_write_lines Hello world how are you >one &&
19 test_write_lines I am very very fine thank you >two &&
20 git add . &&
22 git commit -m initial &&
24 one=$(git rev-parse HEAD:one) &&
25 two=$(git rev-parse HEAD:two) &&
27 echo happy.
30 test_expect_success 'eol=lf puts LFs in normalized file' '
32 rm -f .gitattributes tmp one two &&
33 git config core.eol lf &&
34 git read-tree --reset -u HEAD &&
36 ! has_cr one &&
37 ! has_cr two &&
38 onediff=$(git diff one) &&
39 twodiff=$(git diff two) &&
40 test -z "$onediff" && test -z "$twodiff"
43 test_expect_success 'eol=crlf puts CRLFs in normalized file' '
45 rm -f .gitattributes tmp one two &&
46 git config core.eol crlf &&
47 git read-tree --reset -u HEAD &&
49 has_cr one &&
50 ! has_cr two &&
51 onediff=$(git diff one) &&
52 twodiff=$(git diff two) &&
53 test -z "$onediff" && test -z "$twodiff"
56 test_expect_success 'autocrlf=true overrides eol=lf' '
58 rm -f .gitattributes tmp one two &&
59 git config core.eol lf &&
60 git config core.autocrlf true &&
61 git read-tree --reset -u HEAD &&
63 has_cr one &&
64 has_cr two &&
65 onediff=$(git diff one) &&
66 twodiff=$(git diff two) &&
67 test -z "$onediff" && test -z "$twodiff"
70 test_expect_success 'autocrlf=true overrides unset eol' '
72 rm -f .gitattributes tmp one two &&
73 git config --unset-all core.eol &&
74 git config core.autocrlf true &&
75 git read-tree --reset -u HEAD &&
77 has_cr one &&
78 has_cr two &&
79 onediff=$(git diff one) &&
80 twodiff=$(git diff two) &&
81 test -z "$onediff" && test -z "$twodiff"
84 test_expect_success NATIVE_CRLF 'eol native is crlf' '
86 rm -rf native_eol && mkdir native_eol &&
88 cd native_eol &&
89 printf "*.txt text\n" >.gitattributes &&
90 printf "one\r\ntwo\r\nthree\r\n" >filedos.txt &&
91 printf "one\ntwo\nthree\n" >fileunix.txt &&
92 git init &&
93 git config core.autocrlf false &&
94 git config core.eol native &&
95 git add filedos.txt fileunix.txt &&
96 git commit -m "first" &&
97 rm file*.txt &&
98 git reset --hard HEAD &&
99 has_cr filedos.txt &&
100 has_cr fileunix.txt
104 test_done