Teach git-commit about commit message templates.
[git/jnareb-git.git] / t / t0020-crlf.sh
blobfe1dfd08a02e7a8c9c26542e934ccd6fc4f16f5c
1 #!/bin/sh
3 test_description='CRLF conversion'
5 . ./test-lib.sh
7 q_to_nul () {
8 tr Q '\0'
11 append_cr () {
12 sed -e 's/$/Q/' | tr Q '\015'
15 remove_cr () {
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 &&
25 mkdir dir &&
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 &&
28 git add . &&
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 &&
42 echo happy.
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 &&
51 for f in one dir/two
53 append_cr <$f >tmp && mv -f tmp $f &&
54 git update-index -- $f || {
55 echo Oops
56 false
57 break
59 done &&
61 differs=`git diff-index --cached HEAD` &&
62 test -z "$differs" || {
63 echo Oops "$differs"
64 false
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 &&
75 for f in one dir/two
77 append_cr <$f >tmp && mv -f tmp $f &&
78 git update-index -- $f || {
79 echo "Oops $f"
80 false
81 break
83 done &&
85 differs=`git diff-index --cached HEAD` &&
86 test -z "$differs" || {
87 echo Oops "$differs"
88 false
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 &&
99 for f in one dir/two
101 remove_cr "$f" >tmp && mv -f tmp $f &&
102 git update-index -- $f || {
103 echo "Eh? $f"
104 false
105 break
107 done &&
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" || {
112 echo Oops "$differs"
113 false
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 &&
123 for f in one dir/two
125 if remove_cr "$f" >/dev/null
126 then
127 echo "Eh? $f"
128 false
129 break
130 else
131 git update-index -- $f
133 done &&
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" || {
138 echo Oops "$differs"
139 false
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"
152 false
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"
165 false
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"
179 false
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"
192 false
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"
205 false
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"
219 false
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
231 then
232 echo "Huh?"
233 false
234 else
235 : happy
236 fi &&
238 if remove_cr one >/dev/null
239 then
240 : happy
241 else
242 echo "Huh?"
243 false
244 fi &&
246 if remove_cr three >/dev/null
247 then
248 echo "Huh?"
249 false
250 else
251 : happy
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
262 then
263 echo "Huh?"
264 false
265 else
266 : happy
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
277 then
278 : happy
279 else
280 echo "Huh?"
281 false
282 fi &&
284 if remove_cr three >/dev/null
285 then
286 : happy
287 else
288 echo "Huh?"
289 false
293 test_done