]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0021-conversion.sh
Merge branch 'jk/index-pack-hotfixes'
[thirdparty/git.git] / t / t0021-conversion.sh
CommitLineData
3fed15f5
JH
1#!/bin/sh
2
3test_description='blob conversion via gitattributes'
4
5. ./test-lib.sh
6
71dd5047 7TEST_ROOT="$PWD"
30030a36 8PATH=$TEST_ROOT:$PATH
edcc8581 9
cbb6707b 10write_script <<\EOF "$TEST_ROOT/rot13.sh"
7339eb08
JK
11tr \
12 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
13 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
aa4ed402 14EOF
edcc8581 15
f272696a
JK
16write_script rot13-filter.pl "$PERL_PATH" \
17 <"$TEST_DIRECTORY"/t0021/rot13-filter.pl
edcc8581
LS
18
19generate_random_characters () {
20 LEN=$1
21 NAME=$2
c680668d 22 test-tool genrandom some-seed $LEN |
edcc8581
LS
23 perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME"
24}
25
26file_size () {
5868bd86 27 test-tool path-utils file-size "$1"
edcc8581
LS
28}
29
30filter_git () {
e1ec4721 31 rm -f *.log &&
a0d8b60d 32 git "$@"
edcc8581
LS
33}
34
35# Compare two files and ensure that `clean` and `smudge` respectively are
36# called at least once if specified in the `expect` file. The actual
37# invocation count is not relevant because their number can vary.
3eae30e4 38# c.f. http://lore.kernel.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
edcc8581
LS
39test_cmp_count () {
40 expect=$1
41 actual=$2
42 for FILE in "$expect" "$actual"
43 do
038212c4 44 sort "$FILE" | uniq -c |
58ec9cb3 45 sed -e "s/^ *[0-9][0-9]*[ ]*IN: /x IN: /" >"$FILE.tmp"
edcc8581 46 done &&
58ec9cb3
LS
47 test_cmp "$expect.tmp" "$actual.tmp" &&
48 rm "$expect.tmp" "$actual.tmp"
edcc8581
LS
49}
50
51# Compare two files but exclude all `clean` invocations because Git can
52# call `clean` zero or more times.
3eae30e4 53# c.f. http://lore.kernel.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
edcc8581
LS
54test_cmp_exclude_clean () {
55 expect=$1
56 actual=$2
57 for FILE in "$expect" "$actual"
58 do
58ec9cb3 59 grep -v "IN: clean" "$FILE" >"$FILE.tmp"
edcc8581 60 done &&
58ec9cb3
LS
61 test_cmp "$expect.tmp" "$actual.tmp" &&
62 rm "$expect.tmp" "$actual.tmp"
edcc8581
LS
63}
64
65# Check that the contents of two files are equal and that their rot13 version
66# is equal to the committed content.
67test_cmp_committed_rot13 () {
68 test_cmp "$1" "$2" &&
30030a36 69 rot13.sh <"$1" >expected &&
edcc8581
LS
70 git cat-file blob :"$2" >actual &&
71 test_cmp expected actual
72}
aa4ed402 73
3fed15f5 74test_expect_success setup '
aa4ed402
JH
75 git config filter.rot13.smudge ./rot13.sh &&
76 git config filter.rot13.clean ./rot13.sh &&
77
3fed15f5 78 {
aa4ed402 79 echo "*.t filter=rot13"
3fed15f5
JH
80 echo "*.i ident"
81 } >.gitattributes &&
82
83 {
84 echo a b c d e f g h i j k l m
85 echo n o p q r s t u v w x y z
af9b54bb 86 echo '\''$Id$'\''
3fed15f5
JH
87 } >test &&
88 cat test >test.t &&
89 cat test >test.o &&
90 cat test >test.i &&
91 git add test test.t test.i &&
92 rm -f test test.t test.i &&
edcc8581
LS
93 git checkout -- test test.t test.i &&
94
95 echo "content-test2" >test2.o &&
c6b0831c 96 echo "content-test3 - filename with special characters" >"test3 '\''sq'\'',\$x=.o"
3fed15f5
JH
97'
98
af9b54bb 99script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
3fed15f5
JH
100
101test_expect_success check '
102
ed549703
LS
103 test_cmp test.o test &&
104 test_cmp test.o test.t &&
3fed15f5
JH
105
106 # ident should be stripped in the repository
107 git diff --raw --exit-code :test :test.i &&
108 id=$(git rev-parse --verify :test) &&
109 embedded=$(sed -ne "$script" test.i) &&
a0ae35ae
JS
110 test "z$id" = "z$embedded" &&
111
ed549703 112 git cat-file blob :test.t >test.r &&
a0ae35ae 113
ed549703
LS
114 ./rot13.sh <test.o >test.t &&
115 test_cmp test.r test.t
3fed15f5
JH
116'
117
dfab71cb
AP
118# If an expanded ident ever gets into the repository, we want to make sure that
119# it is collapsed before being expanded again on checkout
120test_expect_success expanded_in_repo '
121 {
122 echo "File with expanded keywords"
123 echo "\$Id\$"
124 echo "\$Id:\$"
125 echo "\$Id: 0000000000000000000000000000000000000000 \$"
126 echo "\$Id: NoSpaceAtEnd\$"
127 echo "\$Id:NoSpaceAtFront \$"
128 echo "\$Id:NoSpaceAtEitherEnd\$"
129 echo "\$Id: NoTerminatingSymbol"
a9f3049f 130 echo "\$Id: Foreign Commit With Spaces \$"
6b6cab3f 131 } >expanded-keywords.0 &&
dfab71cb 132
6b6cab3f
JH
133 {
134 cat expanded-keywords.0 &&
135 printf "\$Id: NoTerminatingSymbolAtEOF"
136 } >expanded-keywords &&
137 cat expanded-keywords >expanded-keywords-crlf &&
138 git add expanded-keywords expanded-keywords-crlf &&
dd555d8b
RS
139 git commit -m "File with keywords expanded" &&
140 id=$(git rev-parse --verify :expanded-keywords) &&
141
dfab71cb
AP
142 {
143 echo "File with expanded keywords"
dd555d8b
RS
144 echo "\$Id: $id \$"
145 echo "\$Id: $id \$"
146 echo "\$Id: $id \$"
147 echo "\$Id: $id \$"
148 echo "\$Id: $id \$"
149 echo "\$Id: $id \$"
dfab71cb 150 echo "\$Id: NoTerminatingSymbol"
07814d90 151 echo "\$Id: Foreign Commit With Spaces \$"
6b6cab3f
JH
152 } >expected-output.0 &&
153 {
154 cat expected-output.0 &&
dd555d8b 155 printf "\$Id: NoTerminatingSymbolAtEOF"
6b6cab3f
JH
156 } >expected-output &&
157 {
158 append_cr <expected-output.0 &&
159 printf "\$Id: NoTerminatingSymbolAtEOF"
160 } >expected-output-crlf &&
161 {
162 echo "expanded-keywords ident"
163 echo "expanded-keywords-crlf ident text eol=crlf"
164 } >>.gitattributes &&
dfab71cb 165
6b6cab3f 166 rm -f expanded-keywords expanded-keywords-crlf &&
dfab71cb 167
dfab71cb 168 git checkout -- expanded-keywords &&
dcbaa0b3 169 test_cmp expected-output expanded-keywords &&
6b6cab3f
JH
170
171 git checkout -- expanded-keywords-crlf &&
dcbaa0b3 172 test_cmp expected-output-crlf expanded-keywords-crlf
dfab71cb
AP
173'
174
a2b665de
PW
175# The use of %f in a filter definition is expanded to the path to
176# the filename being smudged or cleaned. It must be shell escaped.
177# First, set up some interesting file names and pet them in
178# .gitattributes.
179test_expect_success 'filter shell-escaped filenames' '
180 cat >argc.sh <<-EOF &&
181 #!$SHELL_PATH
4290f690 182 cat >/dev/null
a2b665de
PW
183 echo argc: \$# "\$@"
184 EOF
185 normal=name-no-magic &&
186 special="name with '\''sq'\'' and \$x" &&
187 echo some test text >"$normal" &&
188 echo some test text >"$special" &&
189 git add "$normal" "$special" &&
190 git commit -q -m "add files" &&
191 echo "name* filter=argc" >.gitattributes &&
192
193 # delete the files and check them out again, using a smudge filter
194 # that will count the args and echo the command-line back to us
ed549703 195 test_config filter.argc.smudge "sh ./argc.sh %f" &&
a2b665de
PW
196 rm "$normal" "$special" &&
197 git checkout -- "$normal" "$special" &&
198
199 # make sure argc.sh counted the right number of args
200 echo "argc: 1 $normal" >expect &&
201 test_cmp expect "$normal" &&
202 echo "argc: 1 $special" >expect &&
203 test_cmp expect "$special" &&
204
205 # do the same thing, but with more args in the filter expression
ed549703 206 test_config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
a2b665de
PW
207 rm "$normal" "$special" &&
208 git checkout -- "$normal" "$special" &&
209
210 # make sure argc.sh counted the right number of args
211 echo "argc: 2 $normal --my-extra-arg" >expect &&
212 test_cmp expect "$normal" &&
213 echo "argc: 2 $special --my-extra-arg" >expect &&
214 test_cmp expect "$special" &&
215 :
216'
217
9035d75a 218test_expect_success 'required filter should filter data' '
ed549703
LS
219 test_config filter.required.smudge ./rot13.sh &&
220 test_config filter.required.clean ./rot13.sh &&
221 test_config filter.required.required true &&
36daaaca
JB
222
223 echo "*.r filter=required" >.gitattributes &&
224
9035d75a 225 cat test.o >test.r &&
36daaaca 226 git add test.r &&
9035d75a 227
36daaaca 228 rm -f test.r &&
9035d75a 229 git checkout -- test.r &&
ed549703 230 test_cmp test.o test.r &&
9035d75a
SP
231
232 ./rot13.sh <test.o >expected &&
233 git cat-file blob :test.r >actual &&
ed549703 234 test_cmp expected actual
36daaaca
JB
235'
236
237test_expect_success 'required filter smudge failure' '
ed549703
LS
238 test_config filter.failsmudge.smudge false &&
239 test_config filter.failsmudge.clean cat &&
240 test_config filter.failsmudge.required true &&
36daaaca
JB
241
242 echo "*.fs filter=failsmudge" >.gitattributes &&
243
244 echo test >test.fs &&
245 git add test.fs &&
246 rm -f test.fs &&
247 test_must_fail git checkout -- test.fs
248'
249
250test_expect_success 'required filter clean failure' '
ed549703
LS
251 test_config filter.failclean.smudge cat &&
252 test_config filter.failclean.clean false &&
253 test_config filter.failclean.required true &&
36daaaca
JB
254
255 echo "*.fc filter=failclean" >.gitattributes &&
256
257 echo test >test.fc &&
258 test_must_fail git add test.fc
259'
260
9035d75a 261test_expect_success 'filtering large input to small output should use little memory' '
ed549703
LS
262 test_config filter.devnull.clean "cat >/dev/null" &&
263 test_config filter.devnull.required true &&
9035d75a
SP
264 for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB &&
265 echo "30MB filter=devnull" >.gitattributes &&
266 GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
267'
268
0c4dd67a 269test_expect_success 'filter that does not read is fine' '
c680668d 270 test-tool genrandom foo $((128 * 1024 + 1)) >big &&
0c4dd67a 271 echo "big filter=epipe" >.gitattributes &&
ed549703 272 test_config filter.epipe.clean "echo xyzzy" &&
0c4dd67a
JH
273 git add big &&
274 git cat-file blob :big >actual &&
275 echo xyzzy >expect &&
276 test_cmp expect actual
277'
278
0b6806b9 279test_expect_success EXPENSIVE 'filter large file' '
ed549703
LS
280 test_config filter.largefile.smudge cat &&
281 test_config filter.largefile.clean cat &&
0b6806b9
SP
282 for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
283 echo "2GB filter=largefile" >.gitattributes &&
284 git add 2GB 2>err &&
ed549703 285 test_must_be_empty err &&
0b6806b9
SP
286 rm -f 2GB &&
287 git checkout -- 2GB 2>err &&
ed549703 288 test_must_be_empty err
0b6806b9
SP
289'
290
f6a1e1e2 291test_expect_success "filter: clean empty file" '
ed549703
LS
292 test_config filter.in-repo-header.clean "echo cleaned && cat" &&
293 test_config filter.in-repo-header.smudge "sed 1d" &&
f6a1e1e2
JH
294
295 echo "empty-in-worktree filter=in-repo-header" >>.gitattributes &&
296 >empty-in-worktree &&
297
298 echo cleaned >expected &&
299 git add empty-in-worktree &&
300 git show :empty-in-worktree >actual &&
301 test_cmp expected actual
302'
303
304test_expect_success "filter: smudge empty file" '
ed549703
LS
305 test_config filter.empty-in-repo.clean "cat >/dev/null" &&
306 test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
f6a1e1e2
JH
307
308 echo "empty-in-repo filter=empty-in-repo" >>.gitattributes &&
309 echo dead data walking >empty-in-repo &&
310 git add empty-in-repo &&
311
312 echo smudged >expected &&
313 git checkout-index --prefix=filtered- empty-in-repo &&
314 test_cmp expected filtered-empty-in-repo
315'
316
1a8630dc
LS
317test_expect_success 'disable filter with empty override' '
318 test_config_global filter.disable.smudge false &&
319 test_config_global filter.disable.clean false &&
320 test_config filter.disable.smudge false &&
321 test_config filter.disable.clean false &&
322
323 echo "*.disable filter=disable" >.gitattributes &&
324
325 echo test >test.disable &&
326 git -c filter.disable.clean= add test.disable 2>err &&
327 test_must_be_empty err &&
328 rm -f test.disable &&
329 git -c filter.disable.smudge= checkout -- test.disable 2>err &&
330 test_must_be_empty err
331'
332
06dec439
JK
333test_expect_success 'diff does not reuse worktree files that need cleaning' '
334 test_config filter.counter.clean "echo . >>count; sed s/^/clean:/" &&
335 echo "file filter=counter" >.gitattributes &&
336 test_commit one file &&
337 test_commit two file &&
338
339 >count &&
340 git diff-tree -p HEAD &&
341 test_line_count = 0 count
342'
343
edcc8581 344test_expect_success PERL 'required process filter should filter data' '
e1ec4721 345 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
edcc8581
LS
346 test_config_global filter.protocol.required true &&
347 rm -rf repo &&
348 mkdir repo &&
349 (
350 cd repo &&
351 git init &&
352
edcc8581
LS
353 echo "*.r filter=protocol" >.gitattributes &&
354 git add . &&
9c48b4fb 355 git commit -m "test commit 1" &&
edcc8581
LS
356 git branch empty-branch &&
357
358 cp "$TEST_ROOT/test.o" test.r &&
359 cp "$TEST_ROOT/test2.o" test2.r &&
360 mkdir testsubdir &&
c6b0831c 361 cp "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" &&
edcc8581
LS
362 >test4-empty.r &&
363
364 S=$(file_size test.r) &&
365 S2=$(file_size test2.r) &&
c6b0831c 366 S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
13e7ed6a 367 M=$(git hash-object test.r) &&
368 M2=$(git hash-object test2.r) &&
369 M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") &&
370 EMPTY=$(git hash-object /dev/null) &&
edcc8581
LS
371
372 filter_git add . &&
373 cat >expected.log <<-EOF &&
374 START
375 init handshake complete
376 IN: clean test.r $S [OK] -- OUT: $S . [OK]
377 IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
378 IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK]
c6b0831c 379 IN: clean testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
edcc8581
LS
380 STOP
381 EOF
e1ec4721 382 test_cmp_count expected.log debug.log &&
edcc8581 383
7eeda8b8 384 git commit -m "test commit 2" &&
3f267856 385 MASTER=$(git rev-parse --verify master) &&
386 META="ref=refs/heads/master treeish=$MASTER" &&
c6b0831c 387 rm -f test2.r "testsubdir/test3 '\''sq'\'',\$x=.r" &&
edcc8581
LS
388
389 filter_git checkout --quiet --no-progress . &&
390 cat >expected.log <<-EOF &&
391 START
392 init handshake complete
13e7ed6a 393 IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
394 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
edcc8581
LS
395 STOP
396 EOF
e1ec4721 397 test_cmp_exclude_clean expected.log debug.log &&
edcc8581 398
58166c2e
TG
399 # Make sure that the file appears dirty, so checkout below has to
400 # run the configured filter.
401 touch test.r &&
edcc8581
LS
402 filter_git checkout --quiet --no-progress empty-branch &&
403 cat >expected.log <<-EOF &&
404 START
405 init handshake complete
406 IN: clean test.r $S [OK] -- OUT: $S . [OK]
407 STOP
408 EOF
e1ec4721 409 test_cmp_exclude_clean expected.log debug.log &&
edcc8581
LS
410
411 filter_git checkout --quiet --no-progress master &&
412 cat >expected.log <<-EOF &&
413 START
414 init handshake complete
13e7ed6a 415 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
416 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
417 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
418 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
edcc8581
LS
419 STOP
420 EOF
e1ec4721 421 test_cmp_exclude_clean expected.log debug.log &&
edcc8581
LS
422
423 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
424 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
c6b0831c 425 test_cmp_committed_rot13 "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r"
edcc8581
LS
426 )
427'
428
3f267856 429test_expect_success PERL 'required process filter should filter data for various subcommands' '
430 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
431 test_config_global filter.protocol.required true &&
432 (
433 cd repo &&
434
435 S=$(file_size test.r) &&
436 S2=$(file_size test2.r) &&
437 S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
438 M=$(git hash-object test.r) &&
439 M2=$(git hash-object test2.r) &&
440 M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") &&
441 EMPTY=$(git hash-object /dev/null) &&
442
443 MASTER=$(git rev-parse --verify master) &&
444
445 cp "$TEST_ROOT/test.o" test5.r &&
446 git add test5.r &&
447 git commit -m "test commit 3" &&
448 git checkout empty-branch &&
449 filter_git rebase --onto empty-branch master^^ master &&
4cf76f6b 450 MASTER2=$(git rev-parse --verify master) &&
451 META="ref=refs/heads/master treeish=$MASTER2" &&
3f267856 452 cat >expected.log <<-EOF &&
453 START
454 init handshake complete
455 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
456 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
457 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
458 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
459 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
460 STOP
461 EOF
4cf76f6b 462 test_cmp_exclude_clean expected.log debug.log &&
463
464 git reset --hard empty-branch &&
465 filter_git reset --hard $MASTER &&
466 META="treeish=$MASTER" &&
467 cat >expected.log <<-EOF &&
468 START
469 init handshake complete
470 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
471 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
472 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
473 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
474 STOP
475 EOF
476 test_cmp_exclude_clean expected.log debug.log &&
477
478 git branch old-master $MASTER &&
479 git reset --hard empty-branch &&
480 filter_git reset --hard old-master &&
481 META="ref=refs/heads/old-master treeish=$MASTER" &&
482 cat >expected.log <<-EOF &&
483 START
484 init handshake complete
485 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
486 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
487 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
488 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
489 STOP
490 EOF
0c0f8a7f 491 test_cmp_exclude_clean expected.log debug.log &&
492
493 git checkout -b merge empty-branch &&
494 git branch -f master $MASTER2 &&
495 filter_git merge master &&
496 META="treeish=$MASTER2" &&
497 cat >expected.log <<-EOF &&
498 START
499 init handshake complete
500 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
501 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
502 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
503 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
504 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
505 STOP
506 EOF
507 test_cmp_exclude_clean expected.log debug.log &&
508
509 filter_git archive master >/dev/null &&
510 META="ref=refs/heads/master treeish=$MASTER2" &&
511 cat >expected.log <<-EOF &&
512 START
513 init handshake complete
514 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
515 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
516 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
517 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
518 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
519 STOP
520 EOF
521 test_cmp_exclude_clean expected.log debug.log &&
522
523 TREE="$(git rev-parse $MASTER2^{tree})" &&
524 filter_git archive $TREE >/dev/null &&
525 META="treeish=$TREE" &&
526 cat >expected.log <<-EOF &&
527 START
528 init handshake complete
529 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
530 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
531 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
532 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
533 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
534 STOP
535 EOF
3f267856 536 test_cmp_exclude_clean expected.log debug.log
537 )
538'
539
edcc8581
LS
540test_expect_success PERL 'required process filter takes precedence' '
541 test_config_global filter.protocol.clean false &&
e1ec4721 542 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean" &&
edcc8581
LS
543 test_config_global filter.protocol.required true &&
544 rm -rf repo &&
545 mkdir repo &&
546 (
547 cd repo &&
548 git init &&
549
550 echo "*.r filter=protocol" >.gitattributes &&
551 cp "$TEST_ROOT/test.o" test.r &&
552 S=$(file_size test.r) &&
553
554 # Check that the process filter is invoked here
555 filter_git add . &&
556 cat >expected.log <<-EOF &&
557 START
558 init handshake complete
559 IN: clean test.r $S [OK] -- OUT: $S . [OK]
560 STOP
561 EOF
e1ec4721 562 test_cmp_count expected.log debug.log
edcc8581
LS
563 )
564'
565
566test_expect_success PERL 'required process filter should be used only for "clean" operation only' '
e1ec4721 567 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean" &&
edcc8581
LS
568 rm -rf repo &&
569 mkdir repo &&
570 (
571 cd repo &&
572 git init &&
573
574 echo "*.r filter=protocol" >.gitattributes &&
575 cp "$TEST_ROOT/test.o" test.r &&
576 S=$(file_size test.r) &&
577
578 filter_git add . &&
579 cat >expected.log <<-EOF &&
580 START
581 init handshake complete
582 IN: clean test.r $S [OK] -- OUT: $S . [OK]
583 STOP
584 EOF
e1ec4721 585 test_cmp_count expected.log debug.log &&
edcc8581
LS
586
587 rm test.r &&
588
589 filter_git checkout --quiet --no-progress . &&
590 # If the filter would be used for "smudge", too, we would see
591 # "IN: smudge test.r 57 [OK] -- OUT: 57 . [OK]" here
592 cat >expected.log <<-EOF &&
593 START
594 init handshake complete
595 STOP
596 EOF
e1ec4721 597 test_cmp_exclude_clean expected.log debug.log
edcc8581
LS
598 )
599'
600
601test_expect_success PERL 'required process filter should process multiple packets' '
e1ec4721 602 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
edcc8581
LS
603 test_config_global filter.protocol.required true &&
604
605 rm -rf repo &&
606 mkdir repo &&
607 (
608 cd repo &&
609 git init &&
610
611 # Generate data requiring 1, 2, 3 packets
612 S=65516 && # PKTLINE_DATA_MAXLEN -> Maximal size of a packet
613 generate_random_characters $(($S )) 1pkt_1__.file &&
614 generate_random_characters $(($S +1)) 2pkt_1+1.file &&
615 generate_random_characters $(($S*2-1)) 2pkt_2-1.file &&
616 generate_random_characters $(($S*2 )) 2pkt_2__.file &&
617 generate_random_characters $(($S*2+1)) 3pkt_2+1.file &&
618
619 for FILE in "$TEST_ROOT"/*.file
620 do
621 cp "$FILE" . &&
30030a36 622 rot13.sh <"$FILE" >"$FILE.rot13"
edcc8581
LS
623 done &&
624
625 echo "*.file filter=protocol" >.gitattributes &&
626 filter_git add *.file .gitattributes &&
627 cat >expected.log <<-EOF &&
628 START
629 init handshake complete
630 IN: clean 1pkt_1__.file $(($S )) [OK] -- OUT: $(($S )) . [OK]
631 IN: clean 2pkt_1+1.file $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
632 IN: clean 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
633 IN: clean 2pkt_2__.file $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
634 IN: clean 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
635 STOP
636 EOF
e1ec4721 637 test_cmp_count expected.log debug.log &&
edcc8581 638
13e7ed6a 639 M1="blob=$(git hash-object 1pkt_1__.file)" &&
640 M2="blob=$(git hash-object 2pkt_1+1.file)" &&
641 M3="blob=$(git hash-object 2pkt_2-1.file)" &&
642 M4="blob=$(git hash-object 2pkt_2__.file)" &&
643 M5="blob=$(git hash-object 3pkt_2+1.file)" &&
644 rm -f *.file debug.log &&
edcc8581
LS
645
646 filter_git checkout --quiet --no-progress -- *.file &&
647 cat >expected.log <<-EOF &&
648 START
649 init handshake complete
13e7ed6a 650 IN: smudge 1pkt_1__.file $M1 $(($S )) [OK] -- OUT: $(($S )) . [OK]
651 IN: smudge 2pkt_1+1.file $M2 $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
652 IN: smudge 2pkt_2-1.file $M3 $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
653 IN: smudge 2pkt_2__.file $M4 $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
654 IN: smudge 3pkt_2+1.file $M5 $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
edcc8581
LS
655 STOP
656 EOF
e1ec4721 657 test_cmp_exclude_clean expected.log debug.log &&
edcc8581
LS
658
659 for FILE in *.file
660 do
661 test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE
662 done
663 )
664'
665
666test_expect_success PERL 'required process filter with clean error should fail' '
e1ec4721 667 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
edcc8581
LS
668 test_config_global filter.protocol.required true &&
669 rm -rf repo &&
670 mkdir repo &&
671 (
672 cd repo &&
673 git init &&
674
675 echo "*.r filter=protocol" >.gitattributes &&
676
677 cp "$TEST_ROOT/test.o" test.r &&
678 echo "this is going to fail" >clean-write-fail.r &&
679 echo "content-test3-subdir" >test3.r &&
680
681 test_must_fail git add .
682 )
683'
684
685test_expect_success PERL 'process filter should restart after unexpected write failure' '
e1ec4721 686 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
edcc8581
LS
687 rm -rf repo &&
688 mkdir repo &&
689 (
690 cd repo &&
691 git init &&
692
693 echo "*.r filter=protocol" >.gitattributes &&
694
695 cp "$TEST_ROOT/test.o" test.r &&
696 cp "$TEST_ROOT/test2.o" test2.r &&
697 echo "this is going to fail" >smudge-write-fail.o &&
698 cp smudge-write-fail.o smudge-write-fail.r &&
699
700 S=$(file_size test.r) &&
701 S2=$(file_size test2.r) &&
702 SF=$(file_size smudge-write-fail.r) &&
13e7ed6a 703 M=$(git hash-object test.r) &&
704 M2=$(git hash-object test2.r) &&
705 MF=$(git hash-object smudge-write-fail.r) &&
706 rm -f debug.log &&
edcc8581
LS
707
708 git add . &&
709 rm -f *.r &&
710
e1ec4721 711 rm -f debug.log &&
edcc8581
LS
712 git checkout --quiet --no-progress . 2>git-stderr.log &&
713
714 grep "smudge write error at" git-stderr.log &&
d26a328e 715 test_i18ngrep "error: external filter" git-stderr.log &&
edcc8581
LS
716
717 cat >expected.log <<-EOF &&
718 START
719 init handshake complete
13e7ed6a 720 IN: smudge smudge-write-fail.r blob=$MF $SF [OK] -- [WRITE FAIL]
edcc8581
LS
721 START
722 init handshake complete
13e7ed6a 723 IN: smudge test.r blob=$M $S [OK] -- OUT: $S . [OK]
724 IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
edcc8581
LS
725 STOP
726 EOF
e1ec4721 727 test_cmp_exclude_clean expected.log debug.log &&
edcc8581
LS
728
729 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
730 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
731
732 # Smudge failed
733 ! test_cmp smudge-write-fail.o smudge-write-fail.r &&
30030a36 734 rot13.sh <smudge-write-fail.o >expected &&
edcc8581
LS
735 git cat-file blob :smudge-write-fail.r >actual &&
736 test_cmp expected actual
737 )
738'
739
740test_expect_success PERL 'process filter should not be restarted if it signals an error' '
e1ec4721 741 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
edcc8581
LS
742 rm -rf repo &&
743 mkdir repo &&
744 (
745 cd repo &&
746 git init &&
747
748 echo "*.r filter=protocol" >.gitattributes &&
749
750 cp "$TEST_ROOT/test.o" test.r &&
751 cp "$TEST_ROOT/test2.o" test2.r &&
752 echo "this will cause an error" >error.o &&
753 cp error.o error.r &&
754
755 S=$(file_size test.r) &&
756 S2=$(file_size test2.r) &&
757 SE=$(file_size error.r) &&
13e7ed6a 758 M=$(git hash-object test.r) &&
759 M2=$(git hash-object test2.r) &&
760 ME=$(git hash-object error.r) &&
761 rm -f debug.log &&
edcc8581
LS
762
763 git add . &&
764 rm -f *.r &&
765
766 filter_git checkout --quiet --no-progress . &&
767 cat >expected.log <<-EOF &&
768 START
769 init handshake complete
13e7ed6a 770 IN: smudge error.r blob=$ME $SE [OK] -- [ERROR]
771 IN: smudge test.r blob=$M $S [OK] -- OUT: $S . [OK]
772 IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
edcc8581
LS
773 STOP
774 EOF
e1ec4721 775 test_cmp_exclude_clean expected.log debug.log &&
edcc8581
LS
776
777 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
778 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
779 test_cmp error.o error.r
780 )
781'
782
783test_expect_success PERL 'process filter abort stops processing of all further files' '
e1ec4721 784 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
edcc8581
LS
785 rm -rf repo &&
786 mkdir repo &&
787 (
788 cd repo &&
789 git init &&
790
791 echo "*.r filter=protocol" >.gitattributes &&
792
793 cp "$TEST_ROOT/test.o" test.r &&
794 cp "$TEST_ROOT/test2.o" test2.r &&
795 echo "error this blob and all future blobs" >abort.o &&
796 cp abort.o abort.r &&
797
13e7ed6a 798 M="blob=$(git hash-object abort.r)" &&
799 rm -f debug.log &&
edcc8581
LS
800 SA=$(file_size abort.r) &&
801
802 git add . &&
803 rm -f *.r &&
804
13e7ed6a 805
edcc8581
LS
806 # Note: This test assumes that Git filters files in alphabetical
807 # order ("abort.r" before "test.r").
808 filter_git checkout --quiet --no-progress . &&
809 cat >expected.log <<-EOF &&
810 START
811 init handshake complete
13e7ed6a 812 IN: smudge abort.r $M $SA [OK] -- [ABORT]
edcc8581
LS
813 STOP
814 EOF
e1ec4721 815 test_cmp_exclude_clean expected.log debug.log &&
edcc8581
LS
816
817 test_cmp "$TEST_ROOT/test.o" test.r &&
818 test_cmp "$TEST_ROOT/test2.o" test2.r &&
819 test_cmp abort.o abort.r
820 )
821'
822
823test_expect_success PERL 'invalid process filter must fail (and not hang!)' '
824 test_config_global filter.protocol.process cat &&
825 test_config_global filter.protocol.required true &&
826 rm -rf repo &&
827 mkdir repo &&
828 (
829 cd repo &&
830 git init &&
831
832 echo "*.r filter=protocol" >.gitattributes &&
833
834 cp "$TEST_ROOT/test.o" test.r &&
835 test_must_fail git add . 2>git-stderr.log &&
fa64a2fd 836 grep "expected git-filter-server" git-stderr.log
edcc8581
LS
837 )
838'
839
2841e8f8
LS
840test_expect_success PERL 'delayed checkout in process filter' '
841 test_config_global filter.a.process "rot13-filter.pl a.log clean smudge delay" &&
842 test_config_global filter.a.required true &&
843 test_config_global filter.b.process "rot13-filter.pl b.log clean smudge delay" &&
844 test_config_global filter.b.required true &&
845
846 rm -rf repo &&
847 mkdir repo &&
848 (
849 cd repo &&
850 git init &&
851 echo "*.a filter=a" >.gitattributes &&
852 echo "*.b filter=b" >>.gitattributes &&
853 cp "$TEST_ROOT/test.o" test.a &&
854 cp "$TEST_ROOT/test.o" test-delay10.a &&
855 cp "$TEST_ROOT/test.o" test-delay11.a &&
856 cp "$TEST_ROOT/test.o" test-delay20.a &&
857 cp "$TEST_ROOT/test.o" test-delay10.b &&
858 git add . &&
859 git commit -m "test commit"
860 ) &&
861
862 S=$(file_size "$TEST_ROOT/test.o") &&
dfc8cdc6 863 PM="ref=refs/heads/master treeish=$(git -C repo rev-parse --verify master) " &&
864 M="${PM}blob=$(git -C repo rev-parse --verify master:test.a)" &&
2841e8f8
LS
865 cat >a.exp <<-EOF &&
866 START
867 init handshake complete
13e7ed6a 868 IN: smudge test.a $M $S [OK] -- OUT: $S . [OK]
869 IN: smudge test-delay10.a $M $S [OK] -- [DELAYED]
870 IN: smudge test-delay11.a $M $S [OK] -- [DELAYED]
871 IN: smudge test-delay20.a $M $S [OK] -- [DELAYED]
2841e8f8 872 IN: list_available_blobs test-delay10.a test-delay11.a [OK]
13e7ed6a 873 IN: smudge test-delay10.a $M 0 [OK] -- OUT: $S . [OK]
874 IN: smudge test-delay11.a $M 0 [OK] -- OUT: $S . [OK]
2841e8f8 875 IN: list_available_blobs test-delay20.a [OK]
13e7ed6a 876 IN: smudge test-delay20.a $M 0 [OK] -- OUT: $S . [OK]
2841e8f8
LS
877 IN: list_available_blobs [OK]
878 STOP
879 EOF
880 cat >b.exp <<-EOF &&
881 START
882 init handshake complete
13e7ed6a 883 IN: smudge test-delay10.b $M $S [OK] -- [DELAYED]
2841e8f8 884 IN: list_available_blobs test-delay10.b [OK]
13e7ed6a 885 IN: smudge test-delay10.b $M 0 [OK] -- OUT: $S . [OK]
2841e8f8
LS
886 IN: list_available_blobs [OK]
887 STOP
888 EOF
889
890 rm -rf repo-cloned &&
891 filter_git clone repo repo-cloned &&
892 test_cmp_count a.exp repo-cloned/a.log &&
893 test_cmp_count b.exp repo-cloned/b.log &&
894
895 (
896 cd repo-cloned &&
897 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
898 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&
899 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a &&
900 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a &&
901 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b &&
902
903 rm *.a *.b &&
904 filter_git checkout . &&
dfc8cdc6 905 # We are not checking out a ref here, so filter out ref metadata.
906 sed -e "s!$PM!!" ../a.exp >a.exp.filtered &&
907 sed -e "s!$PM!!" ../b.exp >b.exp.filtered &&
908 test_cmp_count a.exp.filtered a.log &&
909 test_cmp_count b.exp.filtered b.log &&
2841e8f8
LS
910
911 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
912 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&
913 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a &&
914 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a &&
915 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b
916 )
917'
918
919test_expect_success PERL 'missing file in delayed checkout' '
920 test_config_global filter.bug.process "rot13-filter.pl bug.log clean smudge delay" &&
921 test_config_global filter.bug.required true &&
922
923 rm -rf repo &&
924 mkdir repo &&
925 (
926 cd repo &&
927 git init &&
928 echo "*.a filter=bug" >.gitattributes &&
75651fd7 929 cp "$TEST_ROOT/test.o" missing-delay.a &&
2841e8f8
LS
930 git add . &&
931 git commit -m "test commit"
932 ) &&
933
934 rm -rf repo-cloned &&
935 test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
2841e8f8
LS
936 grep "error: .missing-delay\.a. was not filtered properly" git-stderr.log
937'
938
939test_expect_success PERL 'invalid file in delayed checkout' '
940 test_config_global filter.bug.process "rot13-filter.pl bug.log clean smudge delay" &&
941 test_config_global filter.bug.required true &&
942
943 rm -rf repo &&
944 mkdir repo &&
945 (
946 cd repo &&
947 git init &&
948 echo "*.a filter=bug" >.gitattributes &&
949 cp "$TEST_ROOT/test.o" invalid-delay.a &&
75651fd7 950 cp "$TEST_ROOT/test.o" unfiltered &&
2841e8f8
LS
951 git add . &&
952 git commit -m "test commit"
953 ) &&
954
955 rm -rf repo-cloned &&
956 test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
957 grep "error: external filter .* signaled that .unfiltered. is now available although it has not been delayed earlier" git-stderr.log
958'
959
3fed15f5 960test_done