3 test_description='blob conversion via gitattributes'
10 write_script <<\EOF "$TEST_ROOT/rot13.sh"
12 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
13 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
16 write_script rot13-filter.pl "$PERL_PATH" \
17 <"$TEST_DIRECTORY"/t0021/rot13-filter.pl
19 generate_random_characters () {
22 test-tool genrandom some-seed $LEN |
23 perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME"
31 # Compare two files and ensure that `clean` and `smudge` respectively are
32 # called at least once if specified in the `expect` file. The actual
33 # invocation count is not relevant because their number can vary.
34 # c.f. http://lore.kernel.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
38 for FILE in "$expect" "$actual"
40 sort "$FILE" | uniq -c |
41 sed -e "s/^ *[0-9][0-9]*[ ]*IN: /x IN: /" >"$FILE.tmp"
43 test_cmp "$expect.tmp" "$actual.tmp" &&
44 rm "$expect.tmp" "$actual.tmp"
47 # Compare two files but exclude all `clean` invocations because Git can
48 # call `clean` zero or more times.
49 # c.f. http://lore.kernel.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
50 test_cmp_exclude_clean () {
53 for FILE in "$expect" "$actual"
55 grep -v "IN: clean" "$FILE" >"$FILE.tmp"
57 test_cmp "$expect.tmp" "$actual.tmp" &&
58 rm "$expect.tmp" "$actual.tmp"
61 # Check that the contents of two files are equal and that their rot13 version
62 # is equal to the committed content.
63 test_cmp_committed_rot13 () {
65 rot13.sh <"$1" >expected &&
66 git cat-file blob :"$2" >actual &&
67 test_cmp expected actual
70 test_expect_success setup '
71 git config filter.rot13.smudge ./rot13.sh &&
72 git config filter.rot13.clean ./rot13.sh &&
75 echo "*.t filter=rot13"
80 echo a b c d e f g h i j k l m
81 echo n o p q r s t u v w x y z
87 git add test test.t test.i &&
88 rm -f test test.t test.i &&
89 git checkout -- test test.t test.i &&
91 echo "content-test2" >test2.o &&
92 echo "content-test3 - filename with special characters" >"test3 '\''sq'\'',\$x=.o"
95 script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
97 test_expect_success check '
99 test_cmp test.o test &&
100 test_cmp test.o test.t &&
102 # ident should be stripped in the repository
103 git diff --raw --exit-code :test :test.i &&
104 id=$(git rev-parse --verify :test) &&
105 embedded=$(sed -ne "$script" test.i) &&
106 test "z$id" = "z$embedded" &&
108 git cat-file blob :test.t >test.r &&
110 ./rot13.sh <test.o >test.t &&
111 test_cmp test.r test.t
114 # If an expanded ident ever gets into the repository, we want to make sure that
115 # it is collapsed before being expanded again on checkout
116 test_expect_success expanded_in_repo '
118 echo "File with expanded keywords"
121 echo "\$Id: 0000000000000000000000000000000000000000 \$"
122 echo "\$Id: NoSpaceAtEnd\$"
123 echo "\$Id:NoSpaceAtFront \$"
124 echo "\$Id:NoSpaceAtEitherEnd\$"
125 echo "\$Id: NoTerminatingSymbol"
126 echo "\$Id: Foreign Commit With Spaces \$"
127 } >expanded-keywords.0 &&
130 cat expanded-keywords.0 &&
131 printf "\$Id: NoTerminatingSymbolAtEOF"
132 } >expanded-keywords &&
133 cat expanded-keywords >expanded-keywords-crlf &&
134 git add expanded-keywords expanded-keywords-crlf &&
135 git commit -m "File with keywords expanded" &&
136 id=$(git rev-parse --verify :expanded-keywords) &&
139 echo "File with expanded keywords"
146 echo "\$Id: NoTerminatingSymbol"
147 echo "\$Id: Foreign Commit With Spaces \$"
148 } >expected-output.0 &&
150 cat expected-output.0 &&
151 printf "\$Id: NoTerminatingSymbolAtEOF"
152 } >expected-output &&
154 append_cr <expected-output.0 &&
155 printf "\$Id: NoTerminatingSymbolAtEOF"
156 } >expected-output-crlf &&
158 echo "expanded-keywords ident"
159 echo "expanded-keywords-crlf ident text eol=crlf"
160 } >>.gitattributes &&
162 rm -f expanded-keywords expanded-keywords-crlf &&
164 git checkout -- expanded-keywords &&
165 test_cmp expected-output expanded-keywords &&
167 git checkout -- expanded-keywords-crlf &&
168 test_cmp expected-output-crlf expanded-keywords-crlf
171 # The use of %f in a filter definition is expanded to the path to
172 # the filename being smudged or cleaned. It must be shell escaped.
173 # First, set up some interesting file names and pet them in
175 test_expect_success 'filter shell-escaped filenames' '
176 cat >argc.sh <<-EOF &&
181 normal=name-no-magic &&
182 special="name with '\''sq'\'' and \$x" &&
183 echo some test text >"$normal" &&
184 echo some test text >"$special" &&
185 git add "$normal" "$special" &&
186 git commit -q -m "add files" &&
187 echo "name* filter=argc" >.gitattributes &&
189 # delete the files and check them out again, using a smudge filter
190 # that will count the args and echo the command-line back to us
191 test_config filter.argc.smudge "sh ./argc.sh %f" &&
192 rm "$normal" "$special" &&
193 git checkout -- "$normal" "$special" &&
195 # make sure argc.sh counted the right number of args
196 echo "argc: 1 $normal" >expect &&
197 test_cmp expect "$normal" &&
198 echo "argc: 1 $special" >expect &&
199 test_cmp expect "$special" &&
201 # do the same thing, but with more args in the filter expression
202 test_config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
203 rm "$normal" "$special" &&
204 git checkout -- "$normal" "$special" &&
206 # make sure argc.sh counted the right number of args
207 echo "argc: 2 $normal --my-extra-arg" >expect &&
208 test_cmp expect "$normal" &&
209 echo "argc: 2 $special --my-extra-arg" >expect &&
210 test_cmp expect "$special" &&
214 test_expect_success 'required filter should filter data' '
215 test_config filter.required.smudge ./rot13.sh &&
216 test_config filter.required.clean ./rot13.sh &&
217 test_config filter.required.required true &&
219 echo "*.r filter=required" >.gitattributes &&
221 cat test.o >test.r &&
225 git checkout -- test.r &&
226 test_cmp test.o test.r &&
228 ./rot13.sh <test.o >expected &&
229 git cat-file blob :test.r >actual &&
230 test_cmp expected actual
233 test_expect_success 'required filter smudge failure' '
234 test_config filter.failsmudge.smudge false &&
235 test_config filter.failsmudge.clean cat &&
236 test_config filter.failsmudge.required true &&
238 echo "*.fs filter=failsmudge" >.gitattributes &&
240 echo test >test.fs &&
243 test_must_fail git checkout -- test.fs
246 test_expect_success 'required filter clean failure' '
247 test_config filter.failclean.smudge cat &&
248 test_config filter.failclean.clean false &&
249 test_config filter.failclean.required true &&
251 echo "*.fc filter=failclean" >.gitattributes &&
253 echo test >test.fc &&
254 test_must_fail git add test.fc
257 test_expect_success 'filtering large input to small output should use little memory' '
258 test_config filter.devnull.clean "cat >/dev/null" &&
259 test_config filter.devnull.required true &&
260 for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB &&
261 echo "30MB filter=devnull" >.gitattributes &&
262 GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
265 test_expect_success 'filter that does not read is fine' '
266 test-tool genrandom foo $((128 * 1024 + 1)) >big &&
267 echo "big filter=epipe" >.gitattributes &&
268 test_config filter.epipe.clean "echo xyzzy" &&
270 git cat-file blob :big >actual &&
271 echo xyzzy >expect &&
272 test_cmp expect actual
275 test_expect_success EXPENSIVE 'filter large file' '
276 test_config filter.largefile.smudge cat &&
277 test_config filter.largefile.clean cat &&
278 for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
279 echo "2GB filter=largefile" >.gitattributes &&
281 test_must_be_empty err &&
283 git checkout -- 2GB 2>err &&
284 test_must_be_empty err
287 test_expect_success "filter: clean empty file" '
288 test_config filter.in-repo-header.clean "echo cleaned && cat" &&
289 test_config filter.in-repo-header.smudge "sed 1d" &&
291 echo "empty-in-worktree filter=in-repo-header" >>.gitattributes &&
292 >empty-in-worktree &&
294 echo cleaned >expected &&
295 git add empty-in-worktree &&
296 git show :empty-in-worktree >actual &&
297 test_cmp expected actual
300 test_expect_success "filter: smudge empty file" '
301 test_config filter.empty-in-repo.clean "cat >/dev/null" &&
302 test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
304 echo "empty-in-repo filter=empty-in-repo" >>.gitattributes &&
305 echo dead data walking >empty-in-repo &&
306 git add empty-in-repo &&
308 echo smudged >expected &&
309 git checkout-index --prefix=filtered- empty-in-repo &&
310 test_cmp expected filtered-empty-in-repo
313 test_expect_success 'disable filter with empty override' '
314 test_config_global filter.disable.smudge false &&
315 test_config_global filter.disable.clean false &&
316 test_config filter.disable.smudge false &&
317 test_config filter.disable.clean false &&
319 echo "*.disable filter=disable" >.gitattributes &&
321 echo test >test.disable &&
322 git -c filter.disable.clean= add test.disable 2>err &&
323 test_must_be_empty err &&
324 rm -f test.disable &&
325 git -c filter.disable.smudge= checkout -- test.disable 2>err &&
326 test_must_be_empty err
329 test_expect_success 'diff does not reuse worktree files that need cleaning' '
330 test_config filter.counter.clean "echo . >>count; sed s/^/clean:/" &&
331 echo "file filter=counter" >.gitattributes &&
332 test_commit one file &&
333 test_commit two file &&
336 git diff-tree -p HEAD &&
337 test_line_count = 0 count
340 test_expect_success PERL 'required process filter should filter data' '
341 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
342 test_config_global filter.protocol.required true &&
349 echo "*.r filter=protocol" >.gitattributes &&
351 git commit -m "test commit 1" &&
352 git branch empty-branch &&
354 cp "$TEST_ROOT/test.o" test.r &&
355 cp "$TEST_ROOT/test2.o" test2.r &&
357 cp "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" &&
360 S=$(test_file_size test.r) &&
361 S2=$(test_file_size test2.r) &&
362 S3=$(test_file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
363 M=$(git hash-object test.r) &&
364 M2=$(git hash-object test2.r) &&
365 M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") &&
366 EMPTY=$(git hash-object /dev/null) &&
369 cat >expected.log <<-EOF &&
371 init handshake complete
372 IN: clean test.r $S [OK] -- OUT: $S . [OK]
373 IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
374 IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK]
375 IN: clean testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
378 test_cmp_count expected.log debug.log &&
380 git commit -m "test commit 2" &&
381 MASTER=$(git rev-parse --verify master) &&
382 META="ref=refs/heads/master treeish=$MASTER" &&
383 rm -f test2.r "testsubdir/test3 '\''sq'\'',\$x=.r" &&
385 filter_git checkout --quiet --no-progress . &&
386 cat >expected.log <<-EOF &&
388 init handshake complete
389 IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
390 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
393 test_cmp_exclude_clean expected.log debug.log &&
395 # Make sure that the file appears dirty, so checkout below has to
396 # run the configured filter.
398 filter_git checkout --quiet --no-progress empty-branch &&
399 cat >expected.log <<-EOF &&
401 init handshake complete
402 IN: clean test.r $S [OK] -- OUT: $S . [OK]
405 test_cmp_exclude_clean expected.log debug.log &&
407 filter_git checkout --quiet --no-progress master &&
408 cat >expected.log <<-EOF &&
410 init handshake complete
411 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
412 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
413 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
414 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
417 test_cmp_exclude_clean expected.log debug.log &&
419 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
420 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
421 test_cmp_committed_rot13 "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r"
425 test_expect_success PERL 'required process filter should filter data for various subcommands' '
426 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
427 test_config_global filter.protocol.required true &&
431 S=$(test_file_size test.r) &&
432 S2=$(test_file_size test2.r) &&
433 S3=$(test_file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
434 M=$(git hash-object test.r) &&
435 M2=$(git hash-object test2.r) &&
436 M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") &&
437 EMPTY=$(git hash-object /dev/null) &&
439 MASTER=$(git rev-parse --verify master) &&
441 cp "$TEST_ROOT/test.o" test5.r &&
443 git commit -m "test commit 3" &&
444 git checkout empty-branch &&
445 filter_git rebase --onto empty-branch master^^ master &&
446 MASTER2=$(git rev-parse --verify master) &&
447 META="ref=refs/heads/master treeish=$MASTER2" &&
448 cat >expected.log <<-EOF &&
450 init handshake complete
451 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
452 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
453 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
454 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
455 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
458 test_cmp_exclude_clean expected.log debug.log &&
460 git reset --hard empty-branch &&
461 filter_git reset --hard $MASTER &&
462 META="treeish=$MASTER" &&
463 cat >expected.log <<-EOF &&
465 init handshake complete
466 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
467 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
468 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
469 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
472 test_cmp_exclude_clean expected.log debug.log &&
474 git branch old-master $MASTER &&
475 git reset --hard empty-branch &&
476 filter_git reset --hard old-master &&
477 META="ref=refs/heads/old-master treeish=$MASTER" &&
478 cat >expected.log <<-EOF &&
480 init handshake complete
481 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
482 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
483 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
484 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
487 test_cmp_exclude_clean expected.log debug.log &&
489 git checkout -b merge empty-branch &&
490 git branch -f master $MASTER2 &&
491 filter_git merge master &&
492 META="treeish=$MASTER2" &&
493 cat >expected.log <<-EOF &&
495 init handshake complete
496 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
497 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
498 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
499 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
500 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
503 test_cmp_exclude_clean expected.log debug.log &&
505 filter_git archive master >/dev/null &&
506 META="ref=refs/heads/master treeish=$MASTER2" &&
507 cat >expected.log <<-EOF &&
509 init handshake complete
510 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
511 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
512 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
513 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
514 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
517 test_cmp_exclude_clean expected.log debug.log &&
519 TREE="$(git rev-parse $MASTER2^{tree})" &&
520 filter_git archive $TREE >/dev/null &&
521 META="treeish=$TREE" &&
522 cat >expected.log <<-EOF &&
524 init handshake complete
525 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
526 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
527 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
528 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
529 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
532 test_cmp_exclude_clean expected.log debug.log
536 test_expect_success PERL 'required process filter takes precedence' '
537 test_config_global filter.protocol.clean false &&
538 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean" &&
539 test_config_global filter.protocol.required true &&
546 echo "*.r filter=protocol" >.gitattributes &&
547 cp "$TEST_ROOT/test.o" test.r &&
548 S=$(test_file_size test.r) &&
550 # Check that the process filter is invoked here
552 cat >expected.log <<-EOF &&
554 init handshake complete
555 IN: clean test.r $S [OK] -- OUT: $S . [OK]
558 test_cmp_count expected.log debug.log
562 test_expect_success PERL 'required process filter should be used only for "clean" operation only' '
563 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean" &&
570 echo "*.r filter=protocol" >.gitattributes &&
571 cp "$TEST_ROOT/test.o" test.r &&
572 S=$(test_file_size test.r) &&
575 cat >expected.log <<-EOF &&
577 init handshake complete
578 IN: clean test.r $S [OK] -- OUT: $S . [OK]
581 test_cmp_count expected.log debug.log &&
585 filter_git checkout --quiet --no-progress . &&
586 # If the filter would be used for "smudge", too, we would see
587 # "IN: smudge test.r 57 [OK] -- OUT: 57 . [OK]" here
588 cat >expected.log <<-EOF &&
590 init handshake complete
593 test_cmp_exclude_clean expected.log debug.log
597 test_expect_success PERL 'required process filter should process multiple packets' '
598 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
599 test_config_global filter.protocol.required true &&
607 # Generate data requiring 1, 2, 3 packets
608 S=65516 && # PKTLINE_DATA_MAXLEN -> Maximal size of a packet
609 generate_random_characters $(($S )) 1pkt_1__.file &&
610 generate_random_characters $(($S +1)) 2pkt_1+1.file &&
611 generate_random_characters $(($S*2-1)) 2pkt_2-1.file &&
612 generate_random_characters $(($S*2 )) 2pkt_2__.file &&
613 generate_random_characters $(($S*2+1)) 3pkt_2+1.file &&
615 for FILE in "$TEST_ROOT"/*.file
618 rot13.sh <"$FILE" >"$FILE.rot13"
621 echo "*.file filter=protocol" >.gitattributes &&
622 filter_git add *.file .gitattributes &&
623 cat >expected.log <<-EOF &&
625 init handshake complete
626 IN: clean 1pkt_1__.file $(($S )) [OK] -- OUT: $(($S )) . [OK]
627 IN: clean 2pkt_1+1.file $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
628 IN: clean 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
629 IN: clean 2pkt_2__.file $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
630 IN: clean 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
633 test_cmp_count expected.log debug.log &&
635 M1="blob=$(git hash-object 1pkt_1__.file)" &&
636 M2="blob=$(git hash-object 2pkt_1+1.file)" &&
637 M3="blob=$(git hash-object 2pkt_2-1.file)" &&
638 M4="blob=$(git hash-object 2pkt_2__.file)" &&
639 M5="blob=$(git hash-object 3pkt_2+1.file)" &&
640 rm -f *.file debug.log &&
642 filter_git checkout --quiet --no-progress -- *.file &&
643 cat >expected.log <<-EOF &&
645 init handshake complete
646 IN: smudge 1pkt_1__.file $M1 $(($S )) [OK] -- OUT: $(($S )) . [OK]
647 IN: smudge 2pkt_1+1.file $M2 $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
648 IN: smudge 2pkt_2-1.file $M3 $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
649 IN: smudge 2pkt_2__.file $M4 $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
650 IN: smudge 3pkt_2+1.file $M5 $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
653 test_cmp_exclude_clean expected.log debug.log &&
657 test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE
662 test_expect_success PERL 'required process filter with clean error should fail' '
663 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
664 test_config_global filter.protocol.required true &&
671 echo "*.r filter=protocol" >.gitattributes &&
673 cp "$TEST_ROOT/test.o" test.r &&
674 echo "this is going to fail" >clean-write-fail.r &&
675 echo "content-test3-subdir" >test3.r &&
677 test_must_fail git add .
681 test_expect_success PERL 'process filter should restart after unexpected write failure' '
682 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
689 echo "*.r filter=protocol" >.gitattributes &&
691 cp "$TEST_ROOT/test.o" test.r &&
692 cp "$TEST_ROOT/test2.o" test2.r &&
693 echo "this is going to fail" >smudge-write-fail.o &&
694 cp smudge-write-fail.o smudge-write-fail.r &&
696 S=$(test_file_size test.r) &&
697 S2=$(test_file_size test2.r) &&
698 SF=$(test_file_size smudge-write-fail.r) &&
699 M=$(git hash-object test.r) &&
700 M2=$(git hash-object test2.r) &&
701 MF=$(git hash-object smudge-write-fail.r) &&
708 git checkout --quiet --no-progress . 2>git-stderr.log &&
710 grep "smudge write error at" git-stderr.log &&
711 test_i18ngrep "error: external filter" git-stderr.log &&
713 cat >expected.log <<-EOF &&
715 init handshake complete
716 IN: smudge smudge-write-fail.r blob=$MF $SF [OK] -- [WRITE FAIL]
718 init handshake complete
719 IN: smudge test.r blob=$M $S [OK] -- OUT: $S . [OK]
720 IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
723 test_cmp_exclude_clean expected.log debug.log &&
725 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
726 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
729 ! test_cmp smudge-write-fail.o smudge-write-fail.r &&
730 rot13.sh <smudge-write-fail.o >expected &&
731 git cat-file blob :smudge-write-fail.r >actual &&
732 test_cmp expected actual
736 test_expect_success PERL 'process filter should not be restarted if it signals an error' '
737 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
744 echo "*.r filter=protocol" >.gitattributes &&
746 cp "$TEST_ROOT/test.o" test.r &&
747 cp "$TEST_ROOT/test2.o" test2.r &&
748 echo "this will cause an error" >error.o &&
749 cp error.o error.r &&
751 S=$(test_file_size test.r) &&
752 S2=$(test_file_size test2.r) &&
753 SE=$(test_file_size error.r) &&
754 M=$(git hash-object test.r) &&
755 M2=$(git hash-object test2.r) &&
756 ME=$(git hash-object error.r) &&
762 filter_git checkout --quiet --no-progress . &&
763 cat >expected.log <<-EOF &&
765 init handshake complete
766 IN: smudge error.r blob=$ME $SE [OK] -- [ERROR]
767 IN: smudge test.r blob=$M $S [OK] -- OUT: $S . [OK]
768 IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
771 test_cmp_exclude_clean expected.log debug.log &&
773 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
774 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
775 test_cmp error.o error.r
779 test_expect_success PERL 'process filter abort stops processing of all further files' '
780 test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
787 echo "*.r filter=protocol" >.gitattributes &&
789 cp "$TEST_ROOT/test.o" test.r &&
790 cp "$TEST_ROOT/test2.o" test2.r &&
791 echo "error this blob and all future blobs" >abort.o &&
792 cp abort.o abort.r &&
794 M="blob=$(git hash-object abort.r)" &&
796 SA=$(test_file_size abort.r) &&
802 # Note: This test assumes that Git filters files in alphabetical
803 # order ("abort.r" before "test.r").
804 filter_git checkout --quiet --no-progress . &&
805 cat >expected.log <<-EOF &&
807 init handshake complete
808 IN: smudge abort.r $M $SA [OK] -- [ABORT]
811 test_cmp_exclude_clean expected.log debug.log &&
813 test_cmp "$TEST_ROOT/test.o" test.r &&
814 test_cmp "$TEST_ROOT/test2.o" test2.r &&
815 test_cmp abort.o abort.r
819 test_expect_success PERL 'invalid process filter must fail (and not hang!)' '
820 test_config_global filter.protocol.process cat &&
821 test_config_global filter.protocol.required true &&
828 echo "*.r filter=protocol" >.gitattributes &&
830 cp "$TEST_ROOT/test.o" test.r &&
831 test_must_fail git add . 2>git-stderr.log &&
832 grep "expected git-filter-server" git-stderr.log
836 test_expect_success PERL 'delayed checkout in process filter' '
837 test_config_global filter.a.process "rot13-filter.pl a.log clean smudge delay" &&
838 test_config_global filter.a.required true &&
839 test_config_global filter.b.process "rot13-filter.pl b.log clean smudge delay" &&
840 test_config_global filter.b.required true &&
847 echo "*.a filter=a" >.gitattributes &&
848 echo "*.b filter=b" >>.gitattributes &&
849 cp "$TEST_ROOT/test.o" test.a &&
850 cp "$TEST_ROOT/test.o" test-delay10.a &&
851 cp "$TEST_ROOT/test.o" test-delay11.a &&
852 cp "$TEST_ROOT/test.o" test-delay20.a &&
853 cp "$TEST_ROOT/test.o" test-delay10.b &&
855 git commit -m "test commit"
858 S=$(test_file_size "$TEST_ROOT/test.o") &&
859 PM="ref=refs/heads/master treeish=$(git -C repo rev-parse --verify master) " &&
860 M="${PM}blob=$(git -C repo rev-parse --verify master:test.a)" &&
863 init handshake complete
864 IN: smudge test.a $M $S [OK] -- OUT: $S . [OK]
865 IN: smudge test-delay10.a $M $S [OK] -- [DELAYED]
866 IN: smudge test-delay11.a $M $S [OK] -- [DELAYED]
867 IN: smudge test-delay20.a $M $S [OK] -- [DELAYED]
868 IN: list_available_blobs test-delay10.a test-delay11.a [OK]
869 IN: smudge test-delay10.a $M 0 [OK] -- OUT: $S . [OK]
870 IN: smudge test-delay11.a $M 0 [OK] -- OUT: $S . [OK]
871 IN: list_available_blobs test-delay20.a [OK]
872 IN: smudge test-delay20.a $M 0 [OK] -- OUT: $S . [OK]
873 IN: list_available_blobs [OK]
878 init handshake complete
879 IN: smudge test-delay10.b $M $S [OK] -- [DELAYED]
880 IN: list_available_blobs test-delay10.b [OK]
881 IN: smudge test-delay10.b $M 0 [OK] -- OUT: $S . [OK]
882 IN: list_available_blobs [OK]
886 rm -rf repo-cloned &&
887 filter_git clone repo repo-cloned &&
888 test_cmp_count a.exp repo-cloned/a.log &&
889 test_cmp_count b.exp repo-cloned/b.log &&
893 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
894 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&
895 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a &&
896 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a &&
897 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b &&
900 filter_git checkout . &&
901 # We are not checking out a ref here, so filter out ref metadata.
902 sed -e "s!$PM!!" ../a.exp >a.exp.filtered &&
903 sed -e "s!$PM!!" ../b.exp >b.exp.filtered &&
904 test_cmp_count a.exp.filtered a.log &&
905 test_cmp_count b.exp.filtered b.log &&
907 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
908 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&
909 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a &&
910 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a &&
911 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b
915 test_expect_success PERL 'missing file in delayed checkout' '
916 test_config_global filter.bug.process "rot13-filter.pl bug.log clean smudge delay" &&
917 test_config_global filter.bug.required true &&
924 echo "*.a filter=bug" >.gitattributes &&
925 cp "$TEST_ROOT/test.o" missing-delay.a &&
927 git commit -m "test commit"
930 rm -rf repo-cloned &&
931 test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
932 grep "error: .missing-delay\.a. was not filtered properly" git-stderr.log
935 test_expect_success PERL 'invalid file in delayed checkout' '
936 test_config_global filter.bug.process "rot13-filter.pl bug.log clean smudge delay" &&
937 test_config_global filter.bug.required true &&
944 echo "*.a filter=bug" >.gitattributes &&
945 cp "$TEST_ROOT/test.o" invalid-delay.a &&
946 cp "$TEST_ROOT/test.o" unfiltered &&
948 git commit -m "test commit"
951 rm -rf repo-cloned &&
952 test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
953 grep "error: external filter .* signaled that .unfiltered. is now available although it has not been delayed earlier" git-stderr.log