Code

Add a couple more test cases to the suite.
[git.git] / t / t0020-crlf.sh
1 #!/bin/sh
3 test_description='CRLF conversion'
5 . ./test-lib.sh
7 append_cr () {
8         sed -e 's/$/Q/' | tr Q '\015'
9 }
11 remove_cr () {
12         tr '\015' Q <"$1" | grep Q >/dev/null &&
13         tr '\015' Q <"$1" | sed -ne 's/Q$//p'
14 }
16 test_expect_success setup '
18         git repo-config core.autocrlf false &&
20         for w in Hello world how are you; do echo $w; done >one &&
21         mkdir dir &&
22         for w in I am very very fine thank you; do echo $w; done >dir/two &&
23         git add . &&
25         git commit -m initial &&
27         one=`git rev-parse HEAD:one` &&
28         dir=`git rev-parse HEAD:dir` &&
29         two=`git rev-parse HEAD:dir/two` &&
31         for w in Some extra lines here; do echo $w; done >>one &&
32         git diff >patch.file &&
33         patched=`git hash-object --stdin <one` &&
34         git read-tree --reset -u HEAD &&
36         echo happy.
37 '
39 test_expect_success 'update with autocrlf=input' '
41         rm -f tmp one dir/two &&
42         git read-tree --reset -u HEAD &&
43         git repo-config core.autocrlf input &&
45         for f in one dir/two
46         do
47                 append_cr <$f >tmp && mv -f tmp $f &&
48                 git update-index -- $f || {
49                         echo Oops
50                         false
51                         break
52                 }
53         done &&
55         differs=`git diff-index --cached HEAD` &&
56         test -z "$differs" || {
57                 echo Oops "$differs"
58                 false
59         }
61 '
63 test_expect_success 'update with autocrlf=true' '
65         rm -f tmp one dir/two &&
66         git read-tree --reset -u HEAD &&
67         git repo-config core.autocrlf true &&
69         for f in one dir/two
70         do
71                 append_cr <$f >tmp && mv -f tmp $f &&
72                 git update-index -- $f || {
73                         echo "Oops $f"
74                         false
75                         break
76                 }
77         done &&
79         differs=`git diff-index --cached HEAD` &&
80         test -z "$differs" || {
81                 echo Oops "$differs"
82                 false
83         }
85 '
87 test_expect_success 'checkout with autocrlf=true' '
89         rm -f tmp one dir/two &&
90         git repo-config core.autocrlf true &&
91         git read-tree --reset -u HEAD &&
93         for f in one dir/two
94         do
95                 remove_cr "$f" >tmp && mv -f tmp $f &&
96                 git update-index -- $f || {
97                         echo "Eh? $f"
98                         false
99                         break
100                 }
101         done &&
102         test "$one" = `git hash-object --stdin <one` &&
103         test "$two" = `git hash-object --stdin <dir/two` &&
104         differs=`git diff-index --cached HEAD` &&
105         test -z "$differs" || {
106                 echo Oops "$differs"
107                 false
108         }
111 test_expect_success 'checkout with autocrlf=input' '
113         rm -f tmp one dir/two &&
114         git repo-config core.autocrlf input &&
115         git read-tree --reset -u HEAD &&
117         for f in one dir/two
118         do
119                 if remove_cr "$f" >/dev/null
120                 then
121                         echo "Eh? $f"
122                         false
123                         break
124                 else
125                         git update-index -- $f
126                 fi
127         done &&
128         test "$one" = `git hash-object --stdin <one` &&
129         test "$two" = `git hash-object --stdin <dir/two` &&
130         differs=`git diff-index --cached HEAD` &&
131         test -z "$differs" || {
132                 echo Oops "$differs"
133                 false
134         }
137 test_expect_success 'apply patch (autocrlf=input)' '
139         rm -f tmp one dir/two &&
140         git repo-config core.autocrlf input &&
141         git read-tree --reset -u HEAD &&
143         git apply patch.file &&
144         test "$patched" = "`git hash-object --stdin <one`" || {
145                 echo "Eh?  apply without index"
146                 false
147         }
150 test_expect_success 'apply patch --cached (autocrlf=input)' '
152         rm -f tmp one dir/two &&
153         git repo-config core.autocrlf input &&
154         git read-tree --reset -u HEAD &&
156         git apply --cached patch.file &&
157         test "$patched" = `git rev-parse :one` || {
158                 echo "Eh?  apply with --cached"
159                 false
160         }
163 test_expect_success 'apply patch --index (autocrlf=input)' '
165         rm -f tmp one dir/two &&
166         git repo-config core.autocrlf input &&
167         git read-tree --reset -u HEAD &&
169         git apply --index patch.file &&
170         test "$patched" = `git rev-parse :one` &&
171         test "$patched" = `git hash-object --stdin <one` || {
172                 echo "Eh?  apply with --index"
173                 false
174         }
177 test_expect_success 'apply patch (autocrlf=true)' '
179         rm -f tmp one dir/two &&
180         git repo-config core.autocrlf true &&
181         git read-tree --reset -u HEAD &&
183         git apply patch.file &&
184         test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
185                 echo "Eh?  apply without index"
186                 false
187         }
190 test_expect_success 'apply patch --cached (autocrlf=true)' '
192         rm -f tmp one dir/two &&
193         git repo-config core.autocrlf true &&
194         git read-tree --reset -u HEAD &&
196         git apply --cached patch.file &&
197         test "$patched" = `git rev-parse :one` || {
198                 echo "Eh?  apply without index"
199                 false
200         }
203 test_expect_success 'apply patch --index (autocrlf=true)' '
205         rm -f tmp one dir/two &&
206         git repo-config core.autocrlf true &&
207         git read-tree --reset -u HEAD &&
209         git apply --index patch.file &&
210         test "$patched" = `git rev-parse :one` &&
211         test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
212                 echo "Eh?  apply with --index"
213                 false
214         }
217 test_done