3 test_description
='blob conversion via gitattributes'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 .
"$TEST_DIRECTORY"/lib-terminal.sh
14 write_script
<<\EOF
"$TEST_ROOT/rot13.sh"
16 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
17 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
20 generate_random_characters
() {
23 test-tool genrandom some-seed
$LEN |
24 perl
-pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME"
32 # Compare two files and ensure that `clean` and `smudge` respectively are
33 # called at least once if specified in the `expect` file. The actual
34 # invocation count is not relevant because their number can vary.
35 # c.f. https://lore.kernel.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
39 for FILE
in "$expect" "$actual"
41 sort "$FILE" |
uniq -c |
42 sed -e "s/^ *[0-9][0-9]*[ ]*IN: /x IN: /" >"$FILE.tmp"
44 test_cmp
"$expect.tmp" "$actual.tmp" &&
45 rm "$expect.tmp" "$actual.tmp"
48 # Compare two files but exclude all `clean` invocations because Git can
49 # call `clean` zero or more times.
50 # c.f. https://lore.kernel.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
51 test_cmp_exclude_clean
() {
54 for FILE
in "$expect" "$actual"
56 grep -v "IN: clean" "$FILE" >"$FILE.tmp"
58 test_cmp
"$expect.tmp" "$actual.tmp" &&
59 rm "$expect.tmp" "$actual.tmp"
62 # Check that the contents of two files are equal and that their rot13 version
63 # is equal to the committed content.
64 test_cmp_committed_rot13
() {
66 rot13.sh
<"$1" >expected
&&
67 git cat-file blob
:"$2" >actual
&&
68 test_cmp expected actual
71 test_expect_success setup
'
72 git config filter.rot13.smudge ./rot13.sh &&
73 git config filter.rot13.clean ./rot13.sh &&
76 echo "*.t filter=rot13" &&
81 echo a b c d e f g h i j k l m &&
82 echo n o p q r s t u v w x y z &&
88 git add test test.t test.i &&
89 rm -f test test.t test.i &&
90 git checkout -- test test.t test.i &&
92 echo "content-test2" >test2.o &&
93 echo "content-test3 - filename with special characters" >"test3 '\''sq'\'',\$x=.o"
96 script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
98 test_expect_success check
'
100 test_cmp test.o test &&
101 test_cmp test.o test.t &&
103 # ident should be stripped in the repository
104 git diff --raw --exit-code :test :test.i &&
105 id=$(git rev-parse --verify :test) &&
106 embedded=$(sed -ne "$script" test.i) &&
107 test "z$id" = "z$embedded" &&
109 git cat-file blob :test.t >test.r &&
111 ./rot13.sh <test.o >test.t &&
112 test_cmp test.r test.t
115 # If an expanded ident ever gets into the repository, we want to make sure that
116 # it is collapsed before being expanded again on checkout
117 test_expect_success expanded_in_repo
'
118 cat >expanded-keywords.0 <<-\EOF &&
119 File with expanded keywords
122 $Id: 0000000000000000000000000000000000000000 $
125 $Id:NoSpaceAtEitherEnd$
126 $Id: NoTerminatingSymbol
127 $Id: Foreign Commit With Spaces $
131 cat expanded-keywords.0 &&
132 printf "\$Id: NoTerminatingSymbolAtEOF"
133 } >expanded-keywords &&
134 cat expanded-keywords >expanded-keywords-crlf &&
135 git add expanded-keywords expanded-keywords-crlf &&
136 git commit -m "File with keywords expanded" &&
137 id=$(git rev-parse --verify :expanded-keywords) &&
139 cat >expected-output.0 <<-EOF &&
140 File with expanded keywords
147 \$Id: NoTerminatingSymbol
148 \$Id: Foreign Commit With Spaces \$
151 cat expected-output.0 &&
152 printf "\$Id: NoTerminatingSymbolAtEOF"
153 } >expected-output &&
155 append_cr <expected-output.0 &&
156 printf "\$Id: NoTerminatingSymbolAtEOF"
157 } >expected-output-crlf &&
159 echo "expanded-keywords ident" &&
160 echo "expanded-keywords-crlf ident text eol=crlf"
161 } >>.gitattributes &&
163 rm -f expanded-keywords expanded-keywords-crlf &&
165 git checkout -- expanded-keywords &&
166 test_cmp expected-output expanded-keywords &&
168 git checkout -- expanded-keywords-crlf &&
169 test_cmp expected-output-crlf expanded-keywords-crlf
172 # The use of %f in a filter definition is expanded to the path to
173 # the filename being smudged or cleaned. It must be shell escaped.
174 # First, set up some interesting file names and pet them in
176 test_expect_success
'filter shell-escaped filenames' '
177 cat >argc.sh <<-EOF &&
182 normal=name-no-magic &&
183 special="name with '\''sq'\'' and \$x" &&
184 echo some test text >"$normal" &&
185 echo some test text >"$special" &&
186 git add "$normal" "$special" &&
187 git commit -q -m "add files" &&
188 echo "name* filter=argc" >.gitattributes &&
190 # delete the files and check them out again, using a smudge filter
191 # that will count the args and echo the command-line back to us
192 test_config filter.argc.smudge "sh ./argc.sh %f" &&
193 rm "$normal" "$special" &&
194 git checkout -- "$normal" "$special" &&
196 # make sure argc.sh counted the right number of args
197 echo "argc: 1 $normal" >expect &&
198 test_cmp expect "$normal" &&
199 echo "argc: 1 $special" >expect &&
200 test_cmp expect "$special" &&
202 # do the same thing, but with more args in the filter expression
203 test_config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
204 rm "$normal" "$special" &&
205 git checkout -- "$normal" "$special" &&
207 # make sure argc.sh counted the right number of args
208 echo "argc: 2 $normal --my-extra-arg" >expect &&
209 test_cmp expect "$normal" &&
210 echo "argc: 2 $special --my-extra-arg" >expect &&
211 test_cmp expect "$special" &&
215 test_expect_success
'required filter should filter data' '
216 test_config filter.required.smudge ./rot13.sh &&
217 test_config filter.required.clean ./rot13.sh &&
218 test_config filter.required.required true &&
220 echo "*.r filter=required" >.gitattributes &&
222 cat test.o >test.r &&
226 git checkout -- test.r &&
227 test_cmp test.o test.r &&
229 ./rot13.sh <test.o >expected &&
230 git cat-file blob :test.r >actual &&
231 test_cmp expected actual
234 test_expect_success
'required filter smudge failure' '
235 test_config filter.failsmudge.smudge false &&
236 test_config filter.failsmudge.clean cat &&
237 test_config filter.failsmudge.required true &&
239 echo "*.fs filter=failsmudge" >.gitattributes &&
241 echo test >test.fs &&
244 test_must_fail git checkout -- test.fs
247 test_expect_success
'required filter clean failure' '
248 test_config filter.failclean.smudge cat &&
249 test_config filter.failclean.clean false &&
250 test_config filter.failclean.required true &&
252 echo "*.fc filter=failclean" >.gitattributes &&
254 echo test >test.fc &&
255 test_must_fail git add test.fc
258 test_expect_success
'required filter with absent clean field' '
259 test_config filter.absentclean.smudge cat &&
260 test_config filter.absentclean.required true &&
262 echo "*.ac filter=absentclean" >.gitattributes &&
264 echo test >test.ac &&
265 test_must_fail git add test.ac 2>stderr &&
266 test_i18ngrep "fatal: test.ac: clean filter .absentclean. failed" stderr
269 test_expect_success
'required filter with absent smudge field' '
270 test_config filter.absentsmudge.clean cat &&
271 test_config filter.absentsmudge.required true &&
273 echo "*.as filter=absentsmudge" >.gitattributes &&
275 echo test >test.as &&
278 test_must_fail git checkout -- test.as 2>stderr &&
279 test_i18ngrep "fatal: test.as: smudge filter absentsmudge failed" stderr
282 test_expect_success
'filtering large input to small output should use little memory' '
283 test_config filter.devnull.clean "cat >/dev/null" &&
284 test_config filter.devnull.required true &&
285 for i in $(test_seq 1 30); do printf "%1048576d" 1 || return 1; done >30MB &&
286 echo "30MB filter=devnull" >.gitattributes &&
287 GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
290 test_expect_success
'filter that does not read is fine' '
291 test-tool genrandom foo $((128 * 1024 + 1)) >big &&
292 echo "big filter=epipe" >.gitattributes &&
293 test_config filter.epipe.clean "echo xyzzy" &&
295 git cat-file blob :big >actual &&
296 echo xyzzy >expect &&
297 test_cmp expect actual
300 test_expect_success EXPENSIVE
'filter large file' '
301 test_config filter.largefile.smudge cat &&
302 test_config filter.largefile.clean cat &&
303 for i in $(test_seq 1 2048); do printf "%1048576d" 1 || return 1; done >2GB &&
304 echo "2GB filter=largefile" >.gitattributes &&
306 test_must_be_empty err &&
308 git checkout -- 2GB 2>err &&
309 test_must_be_empty err
312 test_expect_success
"filter: clean empty file" '
313 test_config filter.in-repo-header.clean "echo cleaned && cat" &&
314 test_config filter.in-repo-header.smudge "sed 1d" &&
316 echo "empty-in-worktree filter=in-repo-header" >>.gitattributes &&
317 >empty-in-worktree &&
319 echo cleaned >expected &&
320 git add empty-in-worktree &&
321 git show :empty-in-worktree >actual &&
322 test_cmp expected actual
325 test_expect_success
"filter: smudge empty file" '
326 test_config filter.empty-in-repo.clean "cat >/dev/null" &&
327 test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
329 echo "empty-in-repo filter=empty-in-repo" >>.gitattributes &&
330 echo dead data walking >empty-in-repo &&
331 git add empty-in-repo &&
333 echo smudged >expected &&
334 git checkout-index --prefix=filtered- empty-in-repo &&
335 test_cmp expected filtered-empty-in-repo
338 test_expect_success
'disable filter with empty override' '
339 test_config_global filter.disable.smudge false &&
340 test_config_global filter.disable.clean false &&
341 test_config filter.disable.smudge false &&
342 test_config filter.disable.clean false &&
344 echo "*.disable filter=disable" >.gitattributes &&
346 echo test >test.disable &&
347 git -c filter.disable.clean= add test.disable 2>err &&
348 test_must_be_empty err &&
349 rm -f test.disable &&
350 git -c filter.disable.smudge= checkout -- test.disable 2>err &&
351 test_must_be_empty err
354 test_expect_success
'diff does not reuse worktree files that need cleaning' '
355 test_config filter.counter.clean "echo . >>count; sed s/^/clean:/" &&
356 echo "file filter=counter" >.gitattributes &&
357 test_commit one file &&
358 test_commit two file &&
361 git diff-tree -p HEAD &&
362 test_line_count = 0 count
365 test_expect_success
'required process filter should filter data' '
366 test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
367 test_config_global filter.protocol.required true &&
374 echo "*.r filter=protocol" >.gitattributes &&
376 git commit -m "test commit 1" &&
377 git branch empty-branch &&
379 cp "$TEST_ROOT/test.o" test.r &&
380 cp "$TEST_ROOT/test2.o" test2.r &&
382 cp "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" &&
385 S=$(test_file_size test.r) &&
386 S2=$(test_file_size test2.r) &&
387 S3=$(test_file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
388 M=$(git hash-object test.r) &&
389 M2=$(git hash-object test2.r) &&
390 M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") &&
391 EMPTY=$(git hash-object /dev/null) &&
394 cat >expected.log <<-EOF &&
396 init handshake complete
397 IN: clean test.r $S [OK] -- OUT: $S . [OK]
398 IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
399 IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK]
400 IN: clean testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
403 test_cmp_count expected.log debug.log &&
405 git commit -m "test commit 2" &&
406 MAIN=$(git rev-parse --verify main) &&
407 META="ref=refs/heads/main treeish=$MAIN" &&
408 rm -f test2.r "testsubdir/test3 '\''sq'\'',\$x=.r" &&
410 filter_git checkout --quiet --no-progress . &&
411 cat >expected.log <<-EOF &&
413 init handshake complete
414 IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
415 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
418 test_cmp_exclude_clean expected.log debug.log &&
420 # Make sure that the file appears dirty, so checkout below has to
421 # run the configured filter.
423 filter_git checkout --quiet --no-progress empty-branch &&
424 cat >expected.log <<-EOF &&
426 init handshake complete
427 IN: clean test.r $S [OK] -- OUT: $S . [OK]
430 test_cmp_exclude_clean expected.log debug.log &&
432 filter_git checkout --quiet --no-progress main &&
433 cat >expected.log <<-EOF &&
435 init handshake complete
436 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
437 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
438 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
439 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
442 test_cmp_exclude_clean expected.log debug.log &&
444 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
445 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
446 test_cmp_committed_rot13 "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r"
450 test_expect_success
'required process filter should filter data for various subcommands' '
451 test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
452 test_config_global filter.protocol.required true &&
456 S=$(test_file_size test.r) &&
457 S2=$(test_file_size test2.r) &&
458 S3=$(test_file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
459 M=$(git hash-object test.r) &&
460 M2=$(git hash-object test2.r) &&
461 M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") &&
462 EMPTY=$(git hash-object /dev/null) &&
464 MAIN=$(git rev-parse --verify main) &&
466 cp "$TEST_ROOT/test.o" test5.r &&
468 git commit -m "test commit 3" &&
469 git checkout empty-branch &&
470 filter_git rebase --onto empty-branch main^^ main &&
471 MAIN2=$(git rev-parse --verify main) &&
472 META="ref=refs/heads/main treeish=$MAIN2" &&
473 cat >expected.log <<-EOF &&
475 init handshake complete
476 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
477 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
478 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
479 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
480 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
483 test_cmp_exclude_clean expected.log debug.log &&
485 git reset --hard empty-branch &&
486 filter_git reset --hard $MAIN &&
487 META="treeish=$MAIN" &&
488 cat >expected.log <<-EOF &&
490 init handshake complete
491 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
492 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
493 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
494 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
497 test_cmp_exclude_clean expected.log debug.log &&
499 git branch old-main $MAIN &&
500 git reset --hard empty-branch &&
501 filter_git reset --hard old-main &&
502 META="ref=refs/heads/old-main treeish=$MAIN" &&
503 cat >expected.log <<-EOF &&
505 init handshake complete
506 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
507 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
508 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
509 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
512 test_cmp_exclude_clean expected.log debug.log &&
514 git checkout -b merge empty-branch &&
515 git branch -f main $MAIN2 &&
516 filter_git merge main &&
517 META="treeish=$MAIN2" &&
518 cat >expected.log <<-EOF &&
520 init handshake complete
521 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
522 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
523 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
524 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
525 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
528 test_cmp_exclude_clean expected.log debug.log &&
530 filter_git archive main >/dev/null &&
531 META="ref=refs/heads/main treeish=$MAIN2" &&
532 cat >expected.log <<-EOF &&
534 init handshake complete
535 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
536 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
537 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
538 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
539 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
542 test_cmp_exclude_clean expected.log debug.log &&
544 TREE="$(git rev-parse $MAIN2^{tree})" &&
545 filter_git archive $TREE >/dev/null &&
546 META="treeish=$TREE" &&
547 cat >expected.log <<-EOF &&
549 init handshake complete
550 IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
551 IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
552 IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
553 IN: smudge test5.r $META blob=$M $S [OK] -- OUT: $S . [OK]
554 IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
557 test_cmp_exclude_clean expected.log debug.log
561 test_expect_success
'required process filter takes precedence' '
562 test_config_global filter.protocol.clean false &&
563 test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean" &&
564 test_config_global filter.protocol.required true &&
571 echo "*.r filter=protocol" >.gitattributes &&
572 cp "$TEST_ROOT/test.o" test.r &&
573 S=$(test_file_size test.r) &&
575 # Check that the process filter is invoked here
577 cat >expected.log <<-EOF &&
579 init handshake complete
580 IN: clean test.r $S [OK] -- OUT: $S . [OK]
583 test_cmp_count expected.log debug.log
587 test_expect_success
'required process filter should be used only for "clean" operation only' '
588 test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean" &&
595 echo "*.r filter=protocol" >.gitattributes &&
596 cp "$TEST_ROOT/test.o" test.r &&
597 S=$(test_file_size test.r) &&
600 cat >expected.log <<-EOF &&
602 init handshake complete
603 IN: clean test.r $S [OK] -- OUT: $S . [OK]
606 test_cmp_count expected.log debug.log &&
610 filter_git checkout --quiet --no-progress . &&
611 # If the filter would be used for "smudge", too, we would see
612 # "IN: smudge test.r 57 [OK] -- OUT: 57 . [OK]" here
613 cat >expected.log <<-EOF &&
615 init handshake complete
618 test_cmp_exclude_clean expected.log debug.log
622 test_expect_success
'required process filter should process multiple packets' '
623 test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
624 test_config_global filter.protocol.required true &&
632 # Generate data requiring 1, 2, 3 packets
633 S=65516 && # PKTLINE_DATA_MAXLEN -> Maximal size of a packet
634 generate_random_characters $(($S )) 1pkt_1__.file &&
635 generate_random_characters $(($S +1)) 2pkt_1+1.file &&
636 generate_random_characters $(($S*2-1)) 2pkt_2-1.file &&
637 generate_random_characters $(($S*2 )) 2pkt_2__.file &&
638 generate_random_characters $(($S*2+1)) 3pkt_2+1.file &&
640 for FILE in "$TEST_ROOT"/*.file
643 rot13.sh <"$FILE" >"$FILE.rot13" || return 1
646 echo "*.file filter=protocol" >.gitattributes &&
647 filter_git add *.file .gitattributes &&
648 cat >expected.log <<-EOF &&
650 init handshake complete
651 IN: clean 1pkt_1__.file $(($S )) [OK] -- OUT: $(($S )) . [OK]
652 IN: clean 2pkt_1+1.file $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
653 IN: clean 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
654 IN: clean 2pkt_2__.file $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
655 IN: clean 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
658 test_cmp_count expected.log debug.log &&
660 M1="blob=$(git hash-object 1pkt_1__.file)" &&
661 M2="blob=$(git hash-object 2pkt_1+1.file)" &&
662 M3="blob=$(git hash-object 2pkt_2-1.file)" &&
663 M4="blob=$(git hash-object 2pkt_2__.file)" &&
664 M5="blob=$(git hash-object 3pkt_2+1.file)" &&
665 rm -f *.file debug.log &&
667 filter_git checkout --quiet --no-progress -- *.file &&
668 cat >expected.log <<-EOF &&
670 init handshake complete
671 IN: smudge 1pkt_1__.file $M1 $(($S )) [OK] -- OUT: $(($S )) . [OK]
672 IN: smudge 2pkt_1+1.file $M2 $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
673 IN: smudge 2pkt_2-1.file $M3 $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
674 IN: smudge 2pkt_2__.file $M4 $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
675 IN: smudge 3pkt_2+1.file $M5 $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
678 test_cmp_exclude_clean expected.log debug.log &&
682 test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE || return 1
687 test_expect_success
'required process filter with clean error should fail' '
688 test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
689 test_config_global filter.protocol.required true &&
696 echo "*.r filter=protocol" >.gitattributes &&
698 cp "$TEST_ROOT/test.o" test.r &&
699 echo "this is going to fail" >clean-write-fail.r &&
700 echo "content-test3-subdir" >test3.r &&
702 test_must_fail git add .
706 test_expect_success
'process filter should restart after unexpected write failure' '
707 test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
714 echo "*.r filter=protocol" >.gitattributes &&
716 cp "$TEST_ROOT/test.o" test.r &&
717 cp "$TEST_ROOT/test2.o" test2.r &&
718 echo "this is going to fail" >smudge-write-fail.o &&
719 cp smudge-write-fail.o smudge-write-fail.r &&
721 S=$(test_file_size test.r) &&
722 S2=$(test_file_size test2.r) &&
723 SF=$(test_file_size smudge-write-fail.r) &&
724 M=$(git hash-object test.r) &&
725 M2=$(git hash-object test2.r) &&
726 MF=$(git hash-object smudge-write-fail.r) &&
733 git checkout --quiet --no-progress . 2>git-stderr.log &&
735 grep "smudge write error" git-stderr.log &&
736 test_i18ngrep "error: external filter" git-stderr.log &&
738 cat >expected.log <<-EOF &&
740 init handshake complete
741 IN: smudge smudge-write-fail.r blob=$MF $SF [OK] -- [WRITE FAIL]
743 init handshake complete
744 IN: smudge test.r blob=$M $S [OK] -- OUT: $S . [OK]
745 IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
748 test_cmp_exclude_clean expected.log debug.log &&
750 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
751 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
754 ! test_cmp smudge-write-fail.o smudge-write-fail.r &&
755 rot13.sh <smudge-write-fail.o >expected &&
756 git cat-file blob :smudge-write-fail.r >actual &&
757 test_cmp expected actual
761 test_expect_success
'process filter should not be restarted if it signals an error' '
762 test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
769 echo "*.r filter=protocol" >.gitattributes &&
771 cp "$TEST_ROOT/test.o" test.r &&
772 cp "$TEST_ROOT/test2.o" test2.r &&
773 echo "this will cause an error" >error.o &&
774 cp error.o error.r &&
776 S=$(test_file_size test.r) &&
777 S2=$(test_file_size test2.r) &&
778 SE=$(test_file_size error.r) &&
779 M=$(git hash-object test.r) &&
780 M2=$(git hash-object test2.r) &&
781 ME=$(git hash-object error.r) &&
787 filter_git checkout --quiet --no-progress . &&
788 cat >expected.log <<-EOF &&
790 init handshake complete
791 IN: smudge error.r blob=$ME $SE [OK] -- [ERROR]
792 IN: smudge test.r blob=$M $S [OK] -- OUT: $S . [OK]
793 IN: smudge test2.r blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
796 test_cmp_exclude_clean expected.log debug.log &&
798 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
799 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
800 test_cmp error.o error.r
804 test_expect_success
'process filter abort stops processing of all further files' '
805 test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
812 echo "*.r filter=protocol" >.gitattributes &&
814 cp "$TEST_ROOT/test.o" test.r &&
815 cp "$TEST_ROOT/test2.o" test2.r &&
816 echo "error this blob and all future blobs" >abort.o &&
817 cp abort.o abort.r &&
819 M="blob=$(git hash-object abort.r)" &&
821 SA=$(test_file_size abort.r) &&
827 # Note: This test assumes that Git filters files in alphabetical
828 # order ("abort.r" before "test.r").
829 filter_git checkout --quiet --no-progress . &&
830 cat >expected.log <<-EOF &&
832 init handshake complete
833 IN: smudge abort.r $M $SA [OK] -- [ABORT]
836 test_cmp_exclude_clean expected.log debug.log &&
838 test_cmp "$TEST_ROOT/test.o" test.r &&
839 test_cmp "$TEST_ROOT/test2.o" test2.r &&
840 test_cmp abort.o abort.r
844 test_expect_success PERL
'invalid process filter must fail (and not hang!)' '
845 test_config_global filter.protocol.process cat &&
846 test_config_global filter.protocol.required true &&
853 echo "*.r filter=protocol" >.gitattributes &&
855 cp "$TEST_ROOT/test.o" test.r &&
856 test_must_fail git add . 2>git-stderr.log &&
857 grep "expected git-filter-server" git-stderr.log
861 test_expect_success
'delayed checkout in process filter' '
862 test_config_global filter.a.process "test-tool rot13-filter --log=a.log clean smudge delay" &&
863 test_config_global filter.a.required true &&
864 test_config_global filter.b.process "test-tool rot13-filter --log=b.log clean smudge delay" &&
865 test_config_global filter.b.required true &&
872 echo "*.a filter=a" >.gitattributes &&
873 echo "*.b filter=b" >>.gitattributes &&
874 cp "$TEST_ROOT/test.o" test.a &&
875 cp "$TEST_ROOT/test.o" test-delay10.a &&
876 cp "$TEST_ROOT/test.o" test-delay11.a &&
877 cp "$TEST_ROOT/test.o" test-delay20.a &&
878 cp "$TEST_ROOT/test.o" test-delay10.b &&
880 git commit -m "test commit"
883 S=$(test_file_size "$TEST_ROOT/test.o") &&
884 PM="ref=refs/heads/main treeish=$(git -C repo rev-parse --verify main) " &&
885 M="${PM}blob=$(git -C repo rev-parse --verify main:test.a)" &&
888 init handshake complete
889 IN: smudge test.a $M $S [OK] -- OUT: $S . [OK]
890 IN: smudge test-delay10.a $M $S [OK] -- [DELAYED]
891 IN: smudge test-delay11.a $M $S [OK] -- [DELAYED]
892 IN: smudge test-delay20.a $M $S [OK] -- [DELAYED]
893 IN: list_available_blobs test-delay10.a test-delay11.a [OK]
894 IN: smudge test-delay10.a $M 0 [OK] -- OUT: $S . [OK]
895 IN: smudge test-delay11.a $M 0 [OK] -- OUT: $S . [OK]
896 IN: list_available_blobs test-delay20.a [OK]
897 IN: smudge test-delay20.a $M 0 [OK] -- OUT: $S . [OK]
898 IN: list_available_blobs [OK]
903 init handshake complete
904 IN: smudge test-delay10.b $M $S [OK] -- [DELAYED]
905 IN: list_available_blobs test-delay10.b [OK]
906 IN: smudge test-delay10.b $M 0 [OK] -- OUT: $S . [OK]
907 IN: list_available_blobs [OK]
911 rm -rf repo-cloned &&
912 filter_git clone repo repo-cloned &&
913 test_cmp_count a.exp repo-cloned/a.log &&
914 test_cmp_count b.exp repo-cloned/b.log &&
918 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
919 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&
920 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a &&
921 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a &&
922 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b &&
925 filter_git checkout . &&
926 # We are not checking out a ref here, so filter out ref metadata.
927 sed -e "s!$PM!!" ../a.exp >a.exp.filtered &&
928 sed -e "s!$PM!!" ../b.exp >b.exp.filtered &&
929 test_cmp_count a.exp.filtered a.log &&
930 test_cmp_count b.exp.filtered b.log &&
932 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
933 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&
934 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a &&
935 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a &&
936 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b
940 test_expect_success
'missing file in delayed checkout' '
941 test_config_global filter.bug.process "test-tool rot13-filter --log=bug.log clean smudge delay" &&
942 test_config_global filter.bug.required true &&
949 echo "*.a filter=bug" >.gitattributes &&
950 cp "$TEST_ROOT/test.o" missing-delay.a &&
952 git commit -m "test commit"
955 rm -rf repo-cloned &&
956 test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
957 grep "error: .missing-delay\.a. was not filtered properly" git-stderr.log
960 test_expect_success
'invalid file in delayed checkout' '
961 test_config_global filter.bug.process "test-tool rot13-filter --log=bug.log clean smudge delay" &&
962 test_config_global filter.bug.required true &&
969 echo "*.a filter=bug" >.gitattributes &&
970 cp "$TEST_ROOT/test.o" invalid-delay.a &&
971 cp "$TEST_ROOT/test.o" unfiltered &&
973 git commit -m "test commit"
976 rm -rf repo-cloned &&
977 test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
978 grep "error: external filter .* signaled that .unfiltered. is now available although it has not been delayed earlier" git-stderr.log
981 for mode
in 'case' 'utf-8'
984 case) dir
='A' symlink
='a' mode_prereq
='CASE_INSENSITIVE_FS' ;;
986 dir
=$
(printf "\141\314\210") symlink
=$
(printf "\303\244")
987 mode_prereq
='UTF8_NFD_TO_NFC' ;;
990 test_expect_success SYMLINKS
,$mode_prereq \
991 "delayed checkout with $mode-collision don't write to the wrong place" '
992 test_config_global filter.delay.process \
993 "test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay" &&
994 test_config_global filter.delay.required true &&
996 git init $mode-collision &&
998 cd $mode-collision &&
1001 empty_oid=$(printf "" | git hash-object -w --stdin) &&
1002 symlink_oid=$(printf "%s" "$PWD/target-dir" | git hash-object -w --stdin) &&
1003 attr_oid=$(echo "$dir/z filter=delay" | git hash-object -w --stdin) &&
1006 100644 blob $empty_oid $dir/x
1007 100644 blob $empty_oid $dir/y
1008 100644 blob $empty_oid $dir/z
1009 120000 blob $symlink_oid $symlink
1010 100644 blob $attr_oid .gitattributes
1013 git update-index --index-info <objs &&
1014 git commit -m "test commit"
1017 git clone $mode-collision $mode-collision-cloned &&
1018 # Make sure z was really delayed
1019 grep "IN: smudge $dir/z .* \\[DELAYED\\]" $mode-collision-cloned/delayed.log &&
1021 # Should not create $dir/z at $symlink/z
1022 test_path_is_missing $mode-collision/target-dir/z
1026 test_expect_success SYMLINKS
,CASE_INSENSITIVE_FS \
1027 "delayed checkout with submodule collision don't write to the wrong place" '
1028 git init collision-with-submodule &&
1030 cd collision-with-submodule &&
1031 git config filter.delay.process "test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay" &&
1032 git config filter.delay.required true &&
1034 # We need Git to treat the submodule "a" and the
1035 # leading dir "A" as different paths in the index.
1036 git config --local core.ignoreCase false &&
1038 empty_oid=$(printf "" | git hash-object -w --stdin) &&
1039 attr_oid=$(echo "A/B/y filter=delay" | git hash-object -w --stdin) &&
1041 100644 blob $empty_oid A/B/x
1042 100644 blob $empty_oid A/B/y
1043 100644 blob $attr_oid .gitattributes
1045 git update-index --index-info <objs &&
1049 symlink_oid=$(printf "%s" "$PWD/target-dir" | git -C a hash-object -w --stdin) &&
1050 echo "120000 blob $symlink_oid b" >objs &&
1051 git -C a update-index --index-info <objs &&
1052 git -C a commit -m sub &&
1053 git submodule add ./a &&
1054 git commit -m super &&
1056 git checkout --recurse-submodules . &&
1057 grep "IN: smudge A/B/y .* \\[DELAYED\\]" delayed.log &&
1058 test_path_is_missing target-dir/y
1062 test_expect_success
'setup for progress tests' '
1063 git init progress &&
1066 git config filter.delay.process "test-tool rot13-filter --log=delay-progress.log clean smudge delay" &&
1067 git config filter.delay.required true &&
1069 echo "*.a filter=delay" >.gitattributes &&
1070 touch test-delay10.a &&
1076 test_delayed_checkout_progress
() {
1079 local expect_progress
=N
&&
1082 local expect_progress
=
1087 BUG
"no command given to test_delayed_checkout_progress"
1092 GIT_PROGRESS_DELAY
=0 &&
1093 export GIT_PROGRESS_DELAY
&&
1094 rm -f *.a delay-progress.log
&&
1097 grep "IN: smudge test-delay10.a .* \\[DELAYED\\]" delay-progress.log
&&
1098 if test "$expect_progress" = N
1100 ! grep "Filtering content" err
1102 grep "Filtering content" err
1107 for mode
in pathspec branch
1110 pathspec
) opt
='.' ;;
1111 branch
) opt
='-f HEAD' ;;
1114 test_expect_success PERL
,TTY
"delayed checkout shows progress by default on tty ($mode checkout)" '
1115 test_delayed_checkout_progress test_terminal git checkout $opt
1118 test_expect_success PERL
"delayed checkout ommits progress on non-tty ($mode checkout)" '
1119 test_delayed_checkout_progress ! git checkout $opt
1122 test_expect_success PERL
,TTY
"delayed checkout ommits progress with --quiet ($mode checkout)" '
1123 test_delayed_checkout_progress ! test_terminal git checkout --quiet $opt
1126 test_expect_success PERL
,TTY
"delayed checkout honors --[no]-progress ($mode checkout)" '
1127 test_delayed_checkout_progress ! test_terminal git checkout --no-progress $opt &&
1128 test_delayed_checkout_progress test_terminal git checkout --quiet --progress $opt
1132 test_expect_success
'delayed checkout correctly reports the number of updated entries' '
1137 git config filter.delay.process "test-tool rot13-filter --log=delayed.log clean smudge delay" &&
1138 git config filter.delay.required true &&
1140 echo "*.a filter=delay" >.gitattributes &&
1141 echo a >test-delay10.a &&
1142 echo a >test-delay11.a &&
1144 git commit -m files &&
1147 git checkout . 2>err &&
1148 grep "IN: smudge test-delay10.a .* \\[DELAYED\\]" delayed.log &&
1149 grep "IN: smudge test-delay11.a .* \\[DELAYED\\]" delayed.log &&
1150 grep "Updated 2 paths from the index" err