1 #!/bin/sh
3 test_description='CRLF conversion'
5 . ./test-lib.sh
7 has_cr() {
8 tr '\015' Q <"$1" | grep Q >/dev/null
9 }
11 test_expect_success setup '
13 git config core.autocrlf false &&
15 for w in Hello world how are you; do echo $w; done >one &&
16 for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >two &&
17 for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >three &&
18 git add . &&
20 git commit -m initial &&
22 one=`git rev-parse HEAD:one` &&
23 two=`git rev-parse HEAD:two` &&
24 three=`git rev-parse HEAD:three` &&
26 echo happy.
27 '
29 test_expect_success 'default settings cause no changes' '
31 rm -f .gitattributes tmp one two three &&
32 git read-tree --reset -u HEAD &&
34 ! has_cr one &&
35 has_cr two &&
36 onediff=`git diff one` &&
37 twodiff=`git diff two` &&
38 threediff=`git diff three` &&
39 test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
40 '
42 test_expect_failure 'crlf=true causes a CRLF file to be normalized' '
44 rm -f .gitattributes tmp one two three &&
45 echo "two crlf" > .gitattributes &&
46 git read-tree --reset -u HEAD &&
48 # Note, "normalized" means that git will normalize it if added
49 has_cr two &&
50 twodiff=`git diff two` &&
51 test -n "$twodiff"
52 '
54 test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
56 rm -f .gitattributes tmp one two three &&
57 git config core.autocrlf false &&
58 echo "one eol=crlf" > .gitattributes &&
59 git read-tree --reset -u HEAD &&
61 has_cr one &&
62 onediff=`git diff one` &&
63 test -z "$onediff"
64 '
66 test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
68 rm -f .gitattributes tmp one two three &&
69 git config core.autocrlf input &&
70 echo "one eol=crlf" > .gitattributes &&
71 git read-tree --reset -u HEAD &&
73 has_cr one &&
74 onediff=`git diff one` &&
75 test -z "$onediff"
76 '
78 test_expect_failure 'eol=lf gives a normalized file LFs with autocrlf=true' '
80 rm -f .gitattributes tmp one two three &&
81 git config core.autocrlf true &&
82 echo "one eol=lf" > .gitattributes &&
83 git read-tree --reset -u HEAD &&
85 ! has_cr one &&
86 onediff=`git diff one` &&
87 test -z "$onediff"
88 '
90 test_expect_success 'autocrlf=true does not normalize CRLF files' '
92 rm -f .gitattributes tmp one two three &&
93 git config core.autocrlf true &&
94 git read-tree --reset -u HEAD &&
96 has_cr one &&
97 has_cr two &&
98 onediff=`git diff one` &&
99 twodiff=`git diff two` &&
100 threediff=`git diff three` &&
101 test -z "$onediff" -a -z "$twodiff" -a -z "$threediff"
102 '
104 test_expect_failure 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '
106 rm -f .gitattributes tmp one two three &&
107 git config core.autocrlf true &&
108 echo "* crlf=auto" > .gitattributes &&
109 git read-tree --reset -u HEAD &&
111 has_cr one &&
112 has_cr two &&
113 onediff=`git diff one` &&
114 twodiff=`git diff two` &&
115 threediff=`git diff three` &&
116 test -z "$onediff" -a -n "$twodiff" -a -z "$threediff"
117 '
119 test_expect_success 'crlf=auto, autocrlf=true does not normalize binary files' '
121 rm -f .gitattributes tmp one two three &&
122 git config core.autocrlf true &&
123 echo "* crlf=auto" > .gitattributes &&
124 git read-tree --reset -u HEAD &&
126 ! has_cr three &&
127 threediff=`git diff three` &&
128 test -z "$threediff"
129 '
131 test_expect_failure 'eol=crlf _does_ normalize binary files' '
133 rm -f .gitattributes tmp one two three &&
134 echo "three eol=crlf" > .gitattributes &&
135 git read-tree --reset -u HEAD &&
137 has_cr three &&
138 threediff=`git diff three` &&
139 test -z "$threediff"
140 '
142 test_done