3 test_description='CRLF conversion'
12 sed -e 's/$/Q/' | tr Q '\015'
16 tr '\015' Q <"$1" | grep Q >/dev/null &&
17 tr '\015' Q <"$1" | sed -ne 's/Q$//p'
20 test_expect_success setup '
22 git repo-config core.autocrlf false &&
24 for w in Hello world how are you; do echo $w; done >one &&
26 for w in I am very very fine thank you; do echo $w; done >dir/two &&
27 for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three &&
30 git commit -m initial &&
32 one=`git rev-parse HEAD:one` &&
33 dir=`git rev-parse HEAD:dir` &&
34 two=`git rev-parse HEAD:dir/two` &&
35 three=`git rev-parse HEAD:three` &&
37 for w in Some extra lines here; do echo $w; done >>one &&
38 git diff >patch.file &&
39 patched=`git hash-object --stdin <one` &&
40 git read-tree --reset -u HEAD &&
45 test_expect_success 'update with autocrlf=input' '
47 rm -f tmp one dir/two three &&
48 git read-tree --reset -u HEAD &&
49 git repo-config core.autocrlf input &&
53 append_cr <$f >tmp && mv -f tmp $f &&
54 git update-index -- $f || {
61 differs=`git diff-index --cached HEAD` &&
62 test -z "$differs" || {
69 test_expect_success 'update with autocrlf=true' '
71 rm -f tmp one dir/two three &&
72 git read-tree --reset -u HEAD &&
73 git repo-config core.autocrlf true &&
77 append_cr <$f >tmp && mv -f tmp $f &&
78 git update-index -- $f || {
85 differs=`git diff-index --cached HEAD` &&
86 test -z "$differs" || {
93 test_expect_success 'checkout with autocrlf=true' '
95 rm -f tmp one dir/two three &&
96 git repo-config core.autocrlf true &&
97 git read-tree --reset -u HEAD &&
101 remove_cr "$f" >tmp && mv -f tmp $f &&
102 git update-index -- $f || {
108 test "$one" = `git hash-object --stdin <one` &&
109 test "$two" = `git hash-object --stdin <dir/two` &&
110 differs=`git diff-index --cached HEAD` &&
111 test -z "$differs" || {
117 test_expect_success 'checkout with autocrlf=input' '
119 rm -f tmp one dir/two three &&
120 git repo-config core.autocrlf input &&
121 git read-tree --reset -u HEAD &&
125 if remove_cr "$f" >/dev/null
131 git update-index -- $f
134 test "$one" = `git hash-object --stdin <one` &&
135 test "$two" = `git hash-object --stdin <dir/two` &&
136 differs=`git diff-index --cached HEAD` &&
137 test -z "$differs" || {
143 test_expect_success 'apply patch (autocrlf=input)' '
145 rm -f tmp one dir/two three &&
146 git repo-config core.autocrlf input &&
147 git read-tree --reset -u HEAD &&
149 git apply patch.file &&
150 test "$patched" = "`git hash-object --stdin <one`" || {
151 echo "Eh? apply without index"
156 test_expect_success 'apply patch --cached (autocrlf=input)' '
158 rm -f tmp one dir/two three &&
159 git repo-config core.autocrlf input &&
160 git read-tree --reset -u HEAD &&
162 git apply --cached patch.file &&
163 test "$patched" = `git rev-parse :one` || {
164 echo "Eh? apply with --cached"
169 test_expect_success 'apply patch --index (autocrlf=input)' '
171 rm -f tmp one dir/two three &&
172 git repo-config core.autocrlf input &&
173 git read-tree --reset -u HEAD &&
175 git apply --index patch.file &&
176 test "$patched" = `git rev-parse :one` &&
177 test "$patched" = `git hash-object --stdin <one` || {
178 echo "Eh? apply with --index"
183 test_expect_success 'apply patch (autocrlf=true)' '
185 rm -f tmp one dir/two three &&
186 git repo-config core.autocrlf true &&
187 git read-tree --reset -u HEAD &&
189 git apply patch.file &&
190 test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
191 echo "Eh? apply without index"
196 test_expect_success 'apply patch --cached (autocrlf=true)' '
198 rm -f tmp one dir/two three &&
199 git repo-config core.autocrlf true &&
200 git read-tree --reset -u HEAD &&
202 git apply --cached patch.file &&
203 test "$patched" = `git rev-parse :one` || {
204 echo "Eh? apply without index"
209 test_expect_success 'apply patch --index (autocrlf=true)' '
211 rm -f tmp one dir/two three &&
212 git repo-config core.autocrlf true &&
213 git read-tree --reset -u HEAD &&
215 git apply --index patch.file &&
216 test "$patched" = `git rev-parse :one` &&
217 test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
218 echo "Eh? apply with --index"
223 test_expect_success '.gitattributes says two is binary' '
225 rm -f tmp one dir/two three &&
226 echo "two -crlf" >.gitattributes &&
227 git repo-config core.autocrlf true &&
228 git read-tree --reset -u HEAD &&
230 if remove_cr dir/two >/dev/null
238 if remove_cr one >/dev/null
246 if remove_cr three >/dev/null
255 test_expect_success '.gitattributes says two is input' '
257 rm -f tmp one dir/two three &&
258 echo "two crlf=input" >.gitattributes &&
259 git read-tree --reset -u HEAD &&
261 if remove_cr dir/two >/dev/null
270 test_expect_success '.gitattributes says two and three are text' '
272 rm -f tmp one dir/two three &&
273 echo "t* crlf" >.gitattributes &&
274 git read-tree --reset -u HEAD &&
276 if remove_cr dir/two >/dev/null
284 if remove_cr three >/dev/null
293 test_expect_success 'in-tree .gitattributes (1)' '
295 echo "one -crlf" >>.gitattributes &&
296 git add .gitattributes &&
297 git commit -m "Add .gitattributes" &&
299 rm -rf tmp one dir .gitattributes patch.file three &&
300 git read-tree --reset -u HEAD &&
302 if remove_cr one >/dev/null
304 echo "Eh? one should not have CRLF"
309 remove_cr three >/dev/null || {
310 echo "Eh? three should still have CRLF"
315 test_expect_success 'in-tree .gitattributes (2)' '
317 rm -rf tmp one dir .gitattributes patch.file three &&
318 git read-tree --reset HEAD &&
319 git checkout-index -f -q -u -a &&
321 if remove_cr one >/dev/null
323 echo "Eh? one should not have CRLF"
328 remove_cr three >/dev/null || {
329 echo "Eh? three should still have CRLF"
334 test_expect_success 'in-tree .gitattributes (3)' '
336 rm -rf tmp one dir .gitattributes patch.file three &&
337 git read-tree --reset HEAD &&
338 git checkout-index -u .gitattributes &&
339 git checkout-index -u one dir/two three &&
341 if remove_cr one >/dev/null
343 echo "Eh? one should not have CRLF"
348 remove_cr three >/dev/null || {
349 echo "Eh? three should still have CRLF"
354 test_expect_success 'in-tree .gitattributes (4)' '
356 rm -rf tmp one dir .gitattributes patch.file three &&
357 git read-tree --reset HEAD &&
358 git checkout-index -u one dir/two three &&
359 git checkout-index -u .gitattributes &&
361 if remove_cr one >/dev/null
363 echo "Eh? one should not have CRLF"
368 remove_cr three >/dev/null || {
369 echo "Eh? three should still have CRLF"