1
-#!/bin/sh
2
-
3
-test_description='CRLF conversion'
4
-
5
-. ./test-lib.sh
6
-
7
-has_cr() {
8
- tr '\015' Q <"$1" | grep Q >/dev/null
9
-}
10
-
11
-test_expect_success setup '
12
-
13
- git config core.autocrlf false &&
14
-
15
- for w in Hello world how are you; do echo $w; done >LFonly &&
16
- for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >CRLFonly &&
17
- for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >LFwithNUL &&
18
- git add . &&
19
-
20
- git commit -m initial &&
21
-
22
- LFonly=$(git rev-parse HEAD:LFonly) &&
23
- CRLFonly=$(git rev-parse HEAD:CRLFonly) &&
24
- LFwithNUL=$(git rev-parse HEAD:LFwithNUL) &&
25
-
26
- echo happy.
27
-'
28
-
29
-test_expect_success 'default settings cause no changes' '
30
-
31
- rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
32
- git read-tree --reset -u HEAD &&
33
-
34
- ! has_cr LFonly &&
35
- has_cr CRLFonly &&
36
- LFonlydiff=$(git diff LFonly) &&
37
- CRLFonlydiff=$(git diff CRLFonly) &&
38
- LFwithNULdiff=$(git diff LFwithNUL) &&
39
- test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
40
-'
41
-
42
-test_expect_success 'crlf=true causes a CRLF file to be normalized' '
43
-
44
- # Backwards compatibility check
45
- rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
46
- echo "CRLFonly crlf" > .gitattributes &&
47
- git read-tree --reset -u HEAD &&
48
-
49
- # Note, "normalized" means that git will normalize it if added
50
- has_cr CRLFonly &&
51
- CRLFonlydiff=$(git diff CRLFonly) &&
52
- test -n "$CRLFonlydiff"
53
-'
54
-
55
-test_expect_success 'text=true causes a CRLF file to be normalized' '
56
-
57
- rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
58
- echo "CRLFonly text" > .gitattributes &&
59
- git read-tree --reset -u HEAD &&
60
-
61
- # Note, "normalized" means that git will normalize it if added
62
- has_cr CRLFonly &&
63
- CRLFonlydiff=$(git diff CRLFonly) &&
64
- test -n "$CRLFonlydiff"
65
-'
66
-
67
-test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' '
68
-
69
- rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
70
- git config core.autocrlf false &&
71
- echo "LFonly eol=crlf" > .gitattributes &&
72
- git read-tree --reset -u HEAD &&
73
-
74
- has_cr LFonly &&
75
- LFonlydiff=$(git diff LFonly) &&
76
- test -z "$LFonlydiff"
77
-'
78
-
79
-test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' '
80
-
81
- rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
82
- git config core.autocrlf input &&
83
- echo "LFonly eol=crlf" > .gitattributes &&
84
- git read-tree --reset -u HEAD &&
85
-
86
- has_cr LFonly &&
87
- LFonlydiff=$(git diff LFonly) &&
88
- test -z "$LFonlydiff"
89
-'
90
-
91
-test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' '
92
-
93
- rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
94
- git config core.autocrlf true &&
95
- echo "LFonly eol=lf" > .gitattributes &&
96
- git read-tree --reset -u HEAD &&
97
-
98
- ! has_cr LFonly &&
99
- LFonlydiff=$(git diff LFonly) &&
100
- test -z "$LFonlydiff"
101
-'
102
-
103
-test_expect_success 'autocrlf=true does not normalize CRLF files' '
104
-
105
- rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
106
- git config core.autocrlf true &&
107
- git read-tree --reset -u HEAD &&
108
-
109
- has_cr LFonly &&
110
- has_cr CRLFonly &&
111
- LFonlydiff=$(git diff LFonly) &&
112
- CRLFonlydiff=$(git diff CRLFonly) &&
113
- LFwithNULdiff=$(git diff LFwithNUL) &&
114
- test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
115
-'
116
-
117
-test_expect_success 'text=auto, autocrlf=true does not normalize CRLF files' '
118
-
119
- rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
120
- git config core.autocrlf true &&
121
- echo "* text=auto" > .gitattributes &&
122
- git read-tree --reset -u HEAD &&
123
-
124
- has_cr LFonly &&
125
- has_cr CRLFonly &&
126
- LFonlydiff=$(git diff LFonly) &&
127
- CRLFonlydiff=$(git diff CRLFonly) &&
128
- LFwithNULdiff=$(git diff LFwithNUL) &&
129
- test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff"
130
-'
131
-
132
-test_expect_success 'text=auto, autocrlf=true does not normalize binary files' '
133
-
134
- rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
135
- git config core.autocrlf true &&
136
- echo "* text=auto" > .gitattributes &&
137
- git read-tree --reset -u HEAD &&
138
-
139
- ! has_cr LFwithNUL &&
140
- LFwithNULdiff=$(git diff LFwithNUL) &&
141
- test -z "$LFwithNULdiff"
142
-'
143
-
144
-test_expect_success 'eol=crlf _does_ normalize binary files' '
145
-
146
- rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL &&
147
- echo "LFwithNUL eol=crlf" > .gitattributes &&
148
- git read-tree --reset -u HEAD &&
149
-
150
- has_cr LFwithNUL &&
151
- LFwithNULdiff=$(git diff LFwithNUL) &&
152
- test -z "$LFwithNULdiff"
153
-'
154
-
155
-test_expect_success 'prepare unnormalized' '
156
- > .gitattributes &&
157
- git config core.autocrlf false &&
158
- printf "LINEONE\nLINETWO\r\n" >mixed &&
159
- git add mixed .gitattributes &&
160
- git commit -m "Add mixed" &&
161
- git ls-files --eol | egrep "i/crlf" &&
162
- git ls-files --eol | egrep "i/mixed"
163
-'
164
-
165
-test_expect_success 'normalize unnormalized' '
166
- echo "* text=auto" >.gitattributes &&
167
- rm .git/index &&
168
- git add . &&
169
- git commit -m "Introduce end-of-line normalization" &&
170
- git ls-files --eol | tr "\\t" " " | sort >act &&
171
-cat >exp <<EOF &&
172
-i/-text w/-text attr/text=auto LFwithNUL
173
-i/lf w/crlf attr/text=auto CRLFonly
174
-i/lf w/crlf attr/text=auto LFonly
175
-i/lf w/lf attr/text=auto .gitattributes
176
-i/lf w/mixed attr/text=auto mixed
177
-EOF
178
- test_cmp exp act
179
-'
180
-
181
-test_done