l10n: sv.po: Update Swedish translation (3195t0f0u)
[alt-git.git] / t / t0020-crlf.sh
blob71350e0657986d7b3e38801d82058c53f9fd23d0
1 #!/bin/sh
3 test_description='CRLF conversion'
5 . ./test-lib.sh
7 has_cr() {
8 tr '\015' Q <"$1" | grep Q >/dev/null
11 # add or remove CRs to disk file in-place
12 # usage: munge_cr <append|remove> <file>
13 munge_cr () {
14 "${1}_cr" <"$2" >tmp &&
15 mv tmp "$2"
18 test_expect_success setup '
20 git config core.autocrlf false &&
22 for w in Hello world how are you; do echo $w; done >one &&
23 mkdir dir &&
24 for w in I am very very fine thank you; do echo $w; done >dir/two &&
25 for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three &&
26 git add . &&
28 git commit -m initial &&
30 one=$(git rev-parse HEAD:one) &&
31 dir=$(git rev-parse HEAD:dir) &&
32 two=$(git rev-parse HEAD:dir/two) &&
33 three=$(git rev-parse HEAD:three) &&
35 for w in Some extra lines here; do echo $w; done >>one &&
36 git diff >patch.file &&
37 patched=$(git hash-object --stdin <one) &&
38 git read-tree --reset -u HEAD
41 test_expect_success 'safecrlf: autocrlf=input, all CRLF' '
43 git config core.autocrlf input &&
44 git config core.safecrlf true &&
46 for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
47 test_must_fail git add allcrlf
50 test_expect_success 'safecrlf: autocrlf=input, mixed LF/CRLF' '
52 git config core.autocrlf input &&
53 git config core.safecrlf true &&
55 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
56 test_must_fail git add mixed
59 test_expect_success 'safecrlf: autocrlf=true, all LF' '
61 git config core.autocrlf true &&
62 git config core.safecrlf true &&
64 for w in I am all LF; do echo $w; done >alllf &&
65 test_must_fail git add alllf
68 test_expect_success 'safecrlf: autocrlf=true mixed LF/CRLF' '
70 git config core.autocrlf true &&
71 git config core.safecrlf true &&
73 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
74 test_must_fail git add mixed
77 test_expect_success 'safecrlf: print warning only once' '
79 git config core.autocrlf input &&
80 git config core.safecrlf warn &&
82 for w in I am all LF; do echo $w; done >doublewarn &&
83 git add doublewarn &&
84 git commit -m "nowarn" &&
85 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >doublewarn &&
86 git add doublewarn 2>err &&
87 if test_have_prereq C_LOCALE_OUTPUT
88 then
89 test $(grep "CRLF will be replaced by LF" err | wc -l) = 1
94 test_expect_success 'safecrlf: git diff demotes safecrlf=true to warn' '
95 git config core.autocrlf input &&
96 git config core.safecrlf true &&
97 git diff HEAD
101 test_expect_success 'switch off autocrlf, safecrlf, reset HEAD' '
102 git config core.autocrlf false &&
103 git config core.safecrlf false &&
104 git reset --hard HEAD^
107 test_expect_success 'update with autocrlf=input' '
109 rm -f tmp one dir/two three &&
110 git read-tree --reset -u HEAD &&
111 git config core.autocrlf input &&
112 munge_cr append one &&
113 munge_cr append dir/two &&
114 git update-index -- one dir/two &&
115 differs=$(git diff-index --cached HEAD) &&
116 verbose test -z "$differs"
120 test_expect_success 'update with autocrlf=true' '
122 rm -f tmp one dir/two three &&
123 git read-tree --reset -u HEAD &&
124 git config core.autocrlf true &&
125 munge_cr append one &&
126 munge_cr append dir/two &&
127 git update-index -- one dir/two &&
128 differs=$(git diff-index --cached HEAD) &&
129 verbose test -z "$differs"
133 test_expect_success 'checkout with autocrlf=true' '
135 rm -f tmp one dir/two three &&
136 git config core.autocrlf true &&
137 git read-tree --reset -u HEAD &&
138 munge_cr remove one &&
139 munge_cr remove dir/two &&
140 git update-index -- one dir/two &&
141 test "$one" = $(git hash-object --stdin <one) &&
142 test "$two" = $(git hash-object --stdin <dir/two) &&
143 differs=$(git diff-index --cached HEAD) &&
144 verbose test -z "$differs"
147 test_expect_success 'checkout with autocrlf=input' '
149 rm -f tmp one dir/two three &&
150 git config core.autocrlf input &&
151 git read-tree --reset -u HEAD &&
152 test_must_fail has_cr one &&
153 test_must_fail has_cr two &&
154 git update-index -- one dir/two &&
155 test "$one" = $(git hash-object --stdin <one) &&
156 test "$two" = $(git hash-object --stdin <dir/two) &&
157 differs=$(git diff-index --cached HEAD) &&
158 verbose test -z "$differs"
161 test_expect_success 'apply patch (autocrlf=input)' '
163 rm -f tmp one dir/two three &&
164 git config core.autocrlf input &&
165 git read-tree --reset -u HEAD &&
167 git apply patch.file &&
168 verbose test "$patched" = "$(git hash-object --stdin <one)"
171 test_expect_success 'apply patch --cached (autocrlf=input)' '
173 rm -f tmp one dir/two three &&
174 git config core.autocrlf input &&
175 git read-tree --reset -u HEAD &&
177 git apply --cached patch.file &&
178 verbose test "$patched" = $(git rev-parse :one)
181 test_expect_success 'apply patch --index (autocrlf=input)' '
183 rm -f tmp one dir/two three &&
184 git config core.autocrlf input &&
185 git read-tree --reset -u HEAD &&
187 git apply --index patch.file &&
188 verbose test "$patched" = $(git rev-parse :one) &&
189 verbose test "$patched" = $(git hash-object --stdin <one)
192 test_expect_success 'apply patch (autocrlf=true)' '
194 rm -f tmp one dir/two three &&
195 git config core.autocrlf true &&
196 git read-tree --reset -u HEAD &&
198 git apply patch.file &&
199 verbose test "$patched" = "$(remove_cr <one | git hash-object --stdin)"
202 test_expect_success 'apply patch --cached (autocrlf=true)' '
204 rm -f tmp one dir/two three &&
205 git config core.autocrlf true &&
206 git read-tree --reset -u HEAD &&
208 git apply --cached patch.file &&
209 verbose test "$patched" = $(git rev-parse :one)
212 test_expect_success 'apply patch --index (autocrlf=true)' '
214 rm -f tmp one dir/two three &&
215 git config core.autocrlf true &&
216 git read-tree --reset -u HEAD &&
218 git apply --index patch.file &&
219 verbose test "$patched" = $(git rev-parse :one) &&
220 verbose test "$patched" = "$(remove_cr <one | git hash-object --stdin)"
223 test_expect_success '.gitattributes says two is binary' '
225 rm -f tmp one dir/two three &&
226 echo "two -crlf" >.gitattributes &&
227 git config core.autocrlf true &&
228 git read-tree --reset -u HEAD &&
230 test_must_fail has_cr dir/two &&
231 verbose has_cr one &&
232 test_must_fail has_cr three
235 test_expect_success '.gitattributes says two is input' '
237 rm -f tmp one dir/two three &&
238 echo "two crlf=input" >.gitattributes &&
239 git read-tree --reset -u HEAD &&
241 test_must_fail has_cr dir/two
244 test_expect_success '.gitattributes says two and three are text' '
246 rm -f tmp one dir/two three &&
247 echo "t* crlf" >.gitattributes &&
248 git read-tree --reset -u HEAD &&
250 verbose has_cr dir/two &&
251 verbose has_cr three
254 test_expect_success 'in-tree .gitattributes (1)' '
256 echo "one -crlf" >>.gitattributes &&
257 git add .gitattributes &&
258 git commit -m "Add .gitattributes" &&
260 rm -rf tmp one dir .gitattributes patch.file three &&
261 git read-tree --reset -u HEAD &&
263 test_must_fail has_cr one &&
264 verbose has_cr three
267 test_expect_success 'in-tree .gitattributes (2)' '
269 rm -rf tmp one dir .gitattributes patch.file three &&
270 git read-tree --reset HEAD &&
271 git checkout-index -f -q -u -a &&
273 test_must_fail has_cr one &&
274 verbose has_cr three
277 test_expect_success 'in-tree .gitattributes (3)' '
279 rm -rf tmp one dir .gitattributes patch.file three &&
280 git read-tree --reset HEAD &&
281 git checkout-index -u .gitattributes &&
282 git checkout-index -u one dir/two three &&
284 test_must_fail has_cr one &&
285 verbose has_cr three
288 test_expect_success 'in-tree .gitattributes (4)' '
290 rm -rf tmp one dir .gitattributes patch.file three &&
291 git read-tree --reset HEAD &&
292 git checkout-index -u one dir/two three &&
293 git checkout-index -u .gitattributes &&
295 test_must_fail has_cr one &&
296 verbose has_cr three
299 test_expect_success 'checkout with existing .gitattributes' '
301 git config core.autocrlf true &&
302 git config --unset core.safecrlf &&
303 echo ".file2 -crlfQ" | q_to_cr >> .gitattributes &&
304 git add .gitattributes &&
305 git commit -m initial &&
306 echo ".file -crlfQ" | q_to_cr >> .gitattributes &&
307 echo "contents" > .file &&
308 git add .gitattributes .file &&
309 git commit -m second &&
311 git checkout master~1 &&
312 git checkout master &&
313 test "$(git diff-files --raw)" = ""
317 test_expect_success 'checkout when deleting .gitattributes' '
319 git rm .gitattributes &&
320 echo "contentsQ" | q_to_cr > .file2 &&
321 git add .file2 &&
322 git commit -m third &&
324 git checkout master~1 &&
325 git checkout master &&
326 has_cr .file2
330 test_expect_success 'invalid .gitattributes (must not crash)' '
332 echo "three +crlf" >>.gitattributes &&
333 git diff
336 # Some more tests here to add new autocrlf functionality.
337 # We want to have a known state here, so start a bit from scratch
339 test_expect_success 'setting up for new autocrlf tests' '
340 git config core.autocrlf false &&
341 git config core.safecrlf false &&
342 rm -rf .????* * &&
343 for w in I am all LF; do echo $w; done >alllf &&
344 for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
345 for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
346 git add -A . &&
347 git commit -m "alllf, allcrlf and mixed only" &&
348 git tag -a -m "message" autocrlf-checkpoint
351 test_expect_success 'report no change after setting autocrlf' '
352 git config core.autocrlf true &&
353 touch * &&
354 git diff --exit-code
357 test_expect_success 'files are clean after checkout' '
358 rm * &&
359 git checkout -f &&
360 git diff --exit-code
363 cr_to_Q_no_NL () {
364 tr '\015' Q | tr -d '\012'
367 test_expect_success 'LF only file gets CRLF with autocrlf' '
368 test "$(cr_to_Q_no_NL < alllf)" = "IQamQallQLFQ"
371 test_expect_success 'Mixed file is still mixed with autocrlf' '
372 test "$(cr_to_Q_no_NL < mixed)" = "OhhereisCRLFQintext"
375 test_expect_success 'CRLF only file has CRLF with autocrlf' '
376 test "$(cr_to_Q_no_NL < allcrlf)" = "IQamQallQCRLFQ"
379 test_expect_success 'New CRLF file gets LF in repo' '
380 tr -d "\015" < alllf | append_cr > alllf2 &&
381 git add alllf2 &&
382 git commit -m "alllf2 added" &&
383 git config core.autocrlf false &&
384 rm * &&
385 git checkout -f &&
386 test_cmp alllf alllf2
389 test_done