1#!/bin/sh
2
3test_description='CRLF conversion'
4
5. ./test-lib.sh
6
7has_cr() {
8 tr '\015' Q <"$1" | grep Q >/dev/null
9}
10
11test_expect_success setup '
12
13 git config core.autocrlf false &&
14
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 . &&
19
20 git commit -m initial &&
21
22 one=`git rev-parse HEAD:one` &&
23 two=`git rev-parse HEAD:two` &&
24 three=`git rev-parse HEAD:three` &&
25
26 echo happy.
27'
28
29test_expect_success 'default settings cause no changes' '
30
31 rm -f .gitattributes tmp one two three &&
32 git read-tree --reset -u HEAD &&
33
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'
41
42test_expect_failure 'crlf=true causes a CRLF file to be normalized' '
43
44 rm -f .gitattributes tmp one two three &&
45 echo "two crlf" > .gitattributes &&
46 git read-tree --reset -u HEAD &&
47
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'
53
54test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
55
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 &&
60
61 has_cr one &&
62 onediff=`git diff one` &&
63 test -z "$onediff"
64'
65
66test_expect_failure 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
67
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 &&
72
73 has_cr one &&
74 onediff=`git diff one` &&
75 test -z "$onediff"
76'
77
78test_expect_failure 'eol=lf gives a normalized file LFs with autocrlf=true' '
79
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 &&
84
85 ! has_cr one &&
86 onediff=`git diff one` &&
87 test -z "$onediff"
88'
89
90test_expect_success 'autocrlf=true does not normalize CRLF files' '
91
92 rm -f .gitattributes tmp one two three &&
93 git config core.autocrlf true &&
94 git read-tree --reset -u HEAD &&
95
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'
103
104test_expect_failure 'crlf=auto, autocrlf=true _does_ normalize CRLF files' '
105
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 &&
110
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'
118
119test_expect_success 'crlf=auto, autocrlf=true does not normalize binary files' '
120
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 &&
125
126 ! has_cr three &&
127 threediff=`git diff three` &&
128 test -z "$threediff"
129'
130
131test_expect_failure 'eol=crlf _does_ normalize binary files' '
132
133 rm -f .gitattributes tmp one two three &&
134 echo "three eol=crlf" > .gitattributes &&
135 git read-tree --reset -u HEAD &&
136
137 has_cr three &&
138 threediff=`git diff three` &&
139 test -z "$threediff"
140'
141
142test_done