Push the NATIVE_CRLF Makefile variable to C and added a test for native.
[git/mingw/4msysgit.git] / t / t0026-eol-config.sh
bloba524f046b914c95a54baa2f36c9db0274e4bdaff
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 # core.eol crlf and core.autocrlf input are not permitted.
12 # this lets us check for the core.eol native being crlf.
13 set_native_eol_prereq() {
14 rm -rf eol && mkdir eol &&
15 ( cd eol &&
16 git init --quiet &&
17 git config core.autocrlf input &&
18 git config core.eol native &&
19 git var core.eol 2> /dev/null
20 ) ||
21 test_set_prereq NATIVE_EOL_IS_CRLF
23 set_native_eol_prereq
25 test_expect_success setup '
27 git config core.autocrlf false &&
29 echo "one text" > .gitattributes &&
31 for w in Hello world how are you; do echo $w; done >one &&
32 for w in I am very very fine thank you; do echo $w; done >two &&
33 git add . &&
35 git commit -m initial &&
37 one=`git rev-parse HEAD:one` &&
38 two=`git rev-parse HEAD:two` &&
40 echo happy.
43 test_expect_success 'eol=lf puts LFs in normalized file' '
45 rm -f .gitattributes tmp one two &&
46 git config core.eol lf &&
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" -a -z "$twodiff"
56 test_expect_success 'eol=crlf puts CRLFs in normalized file' '
58 rm -f .gitattributes tmp one two &&
59 git config core.eol crlf &&
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" -a -z "$twodiff"
69 test_expect_success 'autocrlf=true overrides eol=lf' '
71 rm -f .gitattributes tmp one two &&
72 git config core.eol lf &&
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" -a -z "$twodiff"
83 test_expect_success 'autocrlf=true overrides unset eol' '
85 rm -f .gitattributes tmp one two &&
86 git config --unset-all core.eol &&
87 git config core.autocrlf true &&
88 git read-tree --reset -u HEAD &&
90 has_cr one &&
91 has_cr two &&
92 onediff=`git diff one` &&
93 twodiff=`git diff two` &&
94 test -z "$onediff" -a -z "$twodiff"
97 test_expect_success NATIVE_EOL_IS_CRLF 'eol native is crlf' '
99 rm -rf native_eol && mkdir native_eol &&
100 ( cd native_eol &&
101 printf "*.txt text\n" > .gitattributes
102 printf "one\r\ntwo\r\nthree\r\n" > filedos.txt
103 printf "one\ntwo\nthree\n" > fileunix.txt
104 git init &&
105 git config core.autocrlf false &&
106 git config core.eol native &&
107 git add filedos.txt fileunix.txt &&
108 git commit -m "first" &&
109 rm file*.txt &&
110 git reset --hard HEAD &&
111 has_cr filedos.txt && has_cr fileunix.txt
115 test_done