Merge pull request #285 from dscho/readme
[git/mingw/4msysgit.git] / t / t0026-eol-config.sh
blob43a580a2fbe17f9543ace4617171e0769b3e4a0d
1 #!/bin/sh
3 test_description='CRLF conversion'
5 . ./test-lib.sh
7 has_cr() {
8 tr '\015' Q <"$1" | grep Q >/dev/null
11 test_expect_success setup '
13 git config core.autocrlf false &&
15 echo "one text" > .gitattributes &&
17 for w in Hello world how are you; do echo $w; done >one &&
18 for w in I am very very fine thank you; do echo $w; done >two &&
19 git add . &&
21 git commit -m initial &&
23 one=$(git rev-parse HEAD:one) &&
24 two=$(git rev-parse HEAD:two) &&
26 echo happy.
29 test_expect_success 'eol=lf puts LFs in normalized file' '
31 rm -f .gitattributes tmp one two &&
32 git config core.eol lf &&
33 git read-tree --reset -u HEAD &&
35 ! has_cr one &&
36 ! has_cr two &&
37 onediff=$(git diff one) &&
38 twodiff=$(git diff two) &&
39 test -z "$onediff" && test -z "$twodiff"
42 test_expect_success 'eol=crlf puts CRLFs in normalized file' '
44 rm -f .gitattributes tmp one two &&
45 git config core.eol crlf &&
46 git read-tree --reset -u HEAD &&
48 has_cr one &&
49 ! has_cr two &&
50 onediff=$(git diff one) &&
51 twodiff=$(git diff two) &&
52 test -z "$onediff" && test -z "$twodiff"
55 test_expect_success 'autocrlf=true overrides eol=lf' '
57 rm -f .gitattributes tmp one two &&
58 git config core.eol lf &&
59 git config core.autocrlf true &&
60 git read-tree --reset -u HEAD &&
62 has_cr one &&
63 has_cr two &&
64 onediff=$(git diff one) &&
65 twodiff=$(git diff two) &&
66 test -z "$onediff" && test -z "$twodiff"
69 test_expect_success 'autocrlf=true overrides unset eol' '
71 rm -f .gitattributes tmp one two &&
72 git config --unset-all core.eol &&
73 git config core.autocrlf true &&
74 git read-tree --reset -u HEAD &&
76 has_cr one &&
77 has_cr two &&
78 onediff=$(git diff one) &&
79 twodiff=$(git diff two) &&
80 test -z "$onediff" && test -z "$twodiff"
83 test_expect_success NATIVE_CRLF 'eol native is crlf' '
85 rm -rf native_eol && mkdir native_eol &&
86 ( cd native_eol &&
87 printf "*.txt text\n" > .gitattributes
88 printf "one\r\ntwo\r\nthree\r\n" > filedos.txt
89 printf "one\ntwo\nthree\n" > fileunix.txt
90 git init &&
91 git config core.autocrlf false &&
92 git config core.eol native &&
93 git add filedos.txt fileunix.txt &&
94 git commit -m "first" &&
95 rm file*.txt &&
96 git reset --hard HEAD &&
97 has_cr filedos.txt && has_cr fileunix.txt
101 test_done