Documentation/git-reset.txt: suggest git commit --amend in example.
[git/debian.git] / t / t0020-crlf.sh
blob723b29ad17f778f9f9a96682dee1793191b88667
1 #!/bin/sh
3 test_description='CRLF conversion'
5 . ./test-lib.sh
7 append_cr () {
8 sed -e 's/$/Q/' | tr Q '\015'
11 remove_cr () {
12 tr '\015' Q <"$1" | grep Q >/dev/null &&
13 tr '\015' Q <"$1" | sed -ne 's/Q$//p'
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.
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
47 append_cr <$f >tmp && mv -f tmp $f &&
48 git update-index -- $f || {
49 echo Oops
50 false
51 break
53 done &&
55 differs=`git diff-index --cached HEAD` &&
56 test -z "$differs" || {
57 echo Oops "$differs"
58 false
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
71 append_cr <$f >tmp && mv -f tmp $f &&
72 git update-index -- $f || {
73 echo "Oops $f"
74 false
75 break
77 done &&
79 differs=`git diff-index --cached HEAD` &&
80 test -z "$differs" || {
81 echo Oops "$differs"
82 false
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
95 remove_cr "$f" >tmp && mv -f tmp $f &&
96 git update-index -- $f || {
97 echo "Eh? $f"
98 false
99 break
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
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
119 if remove_cr "$f" >/dev/null
120 then
121 echo "Eh? $f"
122 false
123 break
124 else
125 git update-index -- $f
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
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
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
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
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
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
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
217 test_done