1#!/bin/sh
2
3test_description='blob conversion via gitattributes'
4
5. ./test-lib.sh
6
7TEST_ROOT="$(pwd)"
8PATH=$TEST_ROOT:$PATH
9
10write_script <<\EOF "$TEST_ROOT/rot13.sh"
11tr \
12 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
13 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
14EOF
15
16write_script rot13-filter.pl "$PERL_PATH" \
17 <"$TEST_DIRECTORY"/t0021/rot13-filter.pl
18
19generate_random_characters () {
20 LEN=$1
21 NAME=$2
22 test-genrandom some-seed $LEN |
23 perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME"
24}
25
26file_size () {
27 cat "$1" | wc -c | sed "s/^[ ]*//"
28}
29
30filter_git () {
31 rm -f rot13-filter.log &&
32 git "$@" 2>git-stderr.log &&
33 rm -f git-stderr.log
34}
35
36# Compare two files and ensure that `clean` and `smudge` respectively are
37# called at least once if specified in the `expect` file. The actual
38# invocation count is not relevant because their number can vary.
39# c.f. http://public-inbox.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
40test_cmp_count () {
41 expect=$1
42 actual=$2
43 for FILE in "$expect" "$actual"
44 do
45 sort "$FILE" | uniq -c | sed "s/^[ ]*//" |
46 sed "s/^\([0-9]\) IN: clean/x IN: clean/" |
47 sed "s/^\([0-9]\) IN: smudge/x IN: smudge/" >"$FILE.tmp" &&
48 mv "$FILE.tmp" "$FILE"
49 done &&
50 test_cmp "$expect" "$actual"
51}
52
53# Compare two files but exclude all `clean` invocations because Git can
54# call `clean` zero or more times.
55# c.f. http://public-inbox.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
56test_cmp_exclude_clean () {
57 expect=$1
58 actual=$2
59 for FILE in "$expect" "$actual"
60 do
61 grep -v "IN: clean" "$FILE" >"$FILE.tmp" &&
62 mv "$FILE.tmp" "$FILE"
63 done &&
64 test_cmp "$expect" "$actual"
65}
66
67# Check that the contents of two files are equal and that their rot13 version
68# is equal to the committed content.
69test_cmp_committed_rot13 () {
70 test_cmp "$1" "$2" &&
71 rot13.sh <"$1" >expected &&
72 git cat-file blob :"$2" >actual &&
73 test_cmp expected actual
74}
75
76test_expect_success setup '
77 git config filter.rot13.smudge ./rot13.sh &&
78 git config filter.rot13.clean ./rot13.sh &&
79
80 {
81 echo "*.t filter=rot13"
82 echo "*.i ident"
83 } >.gitattributes &&
84
85 {
86 echo a b c d e f g h i j k l m
87 echo n o p q r s t u v w x y z
88 echo '\''$Id$'\''
89 } >test &&
90 cat test >test.t &&
91 cat test >test.o &&
92 cat test >test.i &&
93 git add test test.t test.i &&
94 rm -f test test.t test.i &&
95 git checkout -- test test.t test.i &&
96
97 echo "content-test2" >test2.o &&
98 echo "content-test3 - filename with special characters" >"test3 '\''sq'\'',\$x.o"
99'
100
101script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
102
103test_expect_success check '
104
105 test_cmp test.o test &&
106 test_cmp test.o test.t &&
107
108 # ident should be stripped in the repository
109 git diff --raw --exit-code :test :test.i &&
110 id=$(git rev-parse --verify :test) &&
111 embedded=$(sed -ne "$script" test.i) &&
112 test "z$id" = "z$embedded" &&
113
114 git cat-file blob :test.t >test.r &&
115
116 ./rot13.sh <test.o >test.t &&
117 test_cmp test.r test.t
118'
119
120# If an expanded ident ever gets into the repository, we want to make sure that
121# it is collapsed before being expanded again on checkout
122test_expect_success expanded_in_repo '
123 {
124 echo "File with expanded keywords"
125 echo "\$Id\$"
126 echo "\$Id:\$"
127 echo "\$Id: 0000000000000000000000000000000000000000 \$"
128 echo "\$Id: NoSpaceAtEnd\$"
129 echo "\$Id:NoSpaceAtFront \$"
130 echo "\$Id:NoSpaceAtEitherEnd\$"
131 echo "\$Id: NoTerminatingSymbol"
132 echo "\$Id: Foreign Commit With Spaces \$"
133 } >expanded-keywords.0 &&
134
135 {
136 cat expanded-keywords.0 &&
137 printf "\$Id: NoTerminatingSymbolAtEOF"
138 } >expanded-keywords &&
139 cat expanded-keywords >expanded-keywords-crlf &&
140 git add expanded-keywords expanded-keywords-crlf &&
141 git commit -m "File with keywords expanded" &&
142 id=$(git rev-parse --verify :expanded-keywords) &&
143
144 {
145 echo "File with expanded keywords"
146 echo "\$Id: $id \$"
147 echo "\$Id: $id \$"
148 echo "\$Id: $id \$"
149 echo "\$Id: $id \$"
150 echo "\$Id: $id \$"
151 echo "\$Id: $id \$"
152 echo "\$Id: NoTerminatingSymbol"
153 echo "\$Id: Foreign Commit With Spaces \$"
154 } >expected-output.0 &&
155 {
156 cat expected-output.0 &&
157 printf "\$Id: NoTerminatingSymbolAtEOF"
158 } >expected-output &&
159 {
160 append_cr <expected-output.0 &&
161 printf "\$Id: NoTerminatingSymbolAtEOF"
162 } >expected-output-crlf &&
163 {
164 echo "expanded-keywords ident"
165 echo "expanded-keywords-crlf ident text eol=crlf"
166 } >>.gitattributes &&
167
168 rm -f expanded-keywords expanded-keywords-crlf &&
169
170 git checkout -- expanded-keywords &&
171 test_cmp expanded-keywords expected-output &&
172
173 git checkout -- expanded-keywords-crlf &&
174 test_cmp expanded-keywords-crlf expected-output-crlf
175'
176
177# The use of %f in a filter definition is expanded to the path to
178# the filename being smudged or cleaned. It must be shell escaped.
179# First, set up some interesting file names and pet them in
180# .gitattributes.
181test_expect_success 'filter shell-escaped filenames' '
182 cat >argc.sh <<-EOF &&
183 #!$SHELL_PATH
184 cat >/dev/null
185 echo argc: \$# "\$@"
186 EOF
187 normal=name-no-magic &&
188 special="name with '\''sq'\'' and \$x" &&
189 echo some test text >"$normal" &&
190 echo some test text >"$special" &&
191 git add "$normal" "$special" &&
192 git commit -q -m "add files" &&
193 echo "name* filter=argc" >.gitattributes &&
194
195 # delete the files and check them out again, using a smudge filter
196 # that will count the args and echo the command-line back to us
197 test_config filter.argc.smudge "sh ./argc.sh %f" &&
198 rm "$normal" "$special" &&
199 git checkout -- "$normal" "$special" &&
200
201 # make sure argc.sh counted the right number of args
202 echo "argc: 1 $normal" >expect &&
203 test_cmp expect "$normal" &&
204 echo "argc: 1 $special" >expect &&
205 test_cmp expect "$special" &&
206
207 # do the same thing, but with more args in the filter expression
208 test_config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
209 rm "$normal" "$special" &&
210 git checkout -- "$normal" "$special" &&
211
212 # make sure argc.sh counted the right number of args
213 echo "argc: 2 $normal --my-extra-arg" >expect &&
214 test_cmp expect "$normal" &&
215 echo "argc: 2 $special --my-extra-arg" >expect &&
216 test_cmp expect "$special" &&
217 :
218'
219
220test_expect_success 'required filter should filter data' '
221 test_config filter.required.smudge ./rot13.sh &&
222 test_config filter.required.clean ./rot13.sh &&
223 test_config filter.required.required true &&
224
225 echo "*.r filter=required" >.gitattributes &&
226
227 cat test.o >test.r &&
228 git add test.r &&
229
230 rm -f test.r &&
231 git checkout -- test.r &&
232 test_cmp test.o test.r &&
233
234 ./rot13.sh <test.o >expected &&
235 git cat-file blob :test.r >actual &&
236 test_cmp expected actual
237'
238
239test_expect_success 'required filter smudge failure' '
240 test_config filter.failsmudge.smudge false &&
241 test_config filter.failsmudge.clean cat &&
242 test_config filter.failsmudge.required true &&
243
244 echo "*.fs filter=failsmudge" >.gitattributes &&
245
246 echo test >test.fs &&
247 git add test.fs &&
248 rm -f test.fs &&
249 test_must_fail git checkout -- test.fs
250'
251
252test_expect_success 'required filter clean failure' '
253 test_config filter.failclean.smudge cat &&
254 test_config filter.failclean.clean false &&
255 test_config filter.failclean.required true &&
256
257 echo "*.fc filter=failclean" >.gitattributes &&
258
259 echo test >test.fc &&
260 test_must_fail git add test.fc
261'
262
263test_expect_success 'filtering large input to small output should use little memory' '
264 test_config filter.devnull.clean "cat >/dev/null" &&
265 test_config filter.devnull.required true &&
266 for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB &&
267 echo "30MB filter=devnull" >.gitattributes &&
268 GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
269'
270
271test_expect_success 'filter that does not read is fine' '
272 test-genrandom foo $((128 * 1024 + 1)) >big &&
273 echo "big filter=epipe" >.gitattributes &&
274 test_config filter.epipe.clean "echo xyzzy" &&
275 git add big &&
276 git cat-file blob :big >actual &&
277 echo xyzzy >expect &&
278 test_cmp expect actual
279'
280
281test_expect_success EXPENSIVE 'filter large file' '
282 test_config filter.largefile.smudge cat &&
283 test_config filter.largefile.clean cat &&
284 for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
285 echo "2GB filter=largefile" >.gitattributes &&
286 git add 2GB 2>err &&
287 test_must_be_empty err &&
288 rm -f 2GB &&
289 git checkout -- 2GB 2>err &&
290 test_must_be_empty err
291'
292
293test_expect_success "filter: clean empty file" '
294 test_config filter.in-repo-header.clean "echo cleaned && cat" &&
295 test_config filter.in-repo-header.smudge "sed 1d" &&
296
297 echo "empty-in-worktree filter=in-repo-header" >>.gitattributes &&
298 >empty-in-worktree &&
299
300 echo cleaned >expected &&
301 git add empty-in-worktree &&
302 git show :empty-in-worktree >actual &&
303 test_cmp expected actual
304'
305
306test_expect_success "filter: smudge empty file" '
307 test_config filter.empty-in-repo.clean "cat >/dev/null" &&
308 test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
309
310 echo "empty-in-repo filter=empty-in-repo" >>.gitattributes &&
311 echo dead data walking >empty-in-repo &&
312 git add empty-in-repo &&
313
314 echo smudged >expected &&
315 git checkout-index --prefix=filtered- empty-in-repo &&
316 test_cmp expected filtered-empty-in-repo
317'
318
319test_expect_success 'disable filter with empty override' '
320 test_config_global filter.disable.smudge false &&
321 test_config_global filter.disable.clean false &&
322 test_config filter.disable.smudge false &&
323 test_config filter.disable.clean false &&
324
325 echo "*.disable filter=disable" >.gitattributes &&
326
327 echo test >test.disable &&
328 git -c filter.disable.clean= add test.disable 2>err &&
329 test_must_be_empty err &&
330 rm -f test.disable &&
331 git -c filter.disable.smudge= checkout -- test.disable 2>err &&
332 test_must_be_empty err
333'
334
335test_expect_success 'diff does not reuse worktree files that need cleaning' '
336 test_config filter.counter.clean "echo . >>count; sed s/^/clean:/" &&
337 echo "file filter=counter" >.gitattributes &&
338 test_commit one file &&
339 test_commit two file &&
340
341 >count &&
342 git diff-tree -p HEAD &&
343 test_line_count = 0 count
344'
345
346test_expect_success PERL 'required process filter should filter data' '
347 test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
348 test_config_global filter.protocol.required true &&
349 rm -rf repo &&
350 mkdir repo &&
351 (
352 cd repo &&
353 git init &&
354
355 echo "git-stderr.log" >.gitignore &&
356 echo "*.r filter=protocol" >.gitattributes &&
357 git add . &&
358 git commit . -m "test commit 1" &&
359 git branch empty-branch &&
360
361 cp "$TEST_ROOT/test.o" test.r &&
362 cp "$TEST_ROOT/test2.o" test2.r &&
363 mkdir testsubdir &&
364 cp "$TEST_ROOT/test3 '\''sq'\'',\$x.o" "testsubdir/test3 '\''sq'\'',\$x.r" &&
365 >test4-empty.r &&
366
367 S=$(file_size test.r) &&
368 S2=$(file_size test2.r) &&
369 S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x.r") &&
370
371 filter_git add . &&
372 cat >expected.log <<-EOF &&
373 START
374 init handshake complete
375 IN: clean test.r $S [OK] -- OUT: $S . [OK]
376 IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
377 IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK]
378 IN: clean testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
379 STOP
380 EOF
381 test_cmp_count expected.log rot13-filter.log &&
382
383 filter_git commit . -m "test commit 2" &&
384 cat >expected.log <<-EOF &&
385 START
386 init handshake complete
387 IN: clean test.r $S [OK] -- OUT: $S . [OK]
388 IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
389 IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK]
390 IN: clean testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
391 IN: clean test.r $S [OK] -- OUT: $S . [OK]
392 IN: clean test2.r $S2 [OK] -- OUT: $S2 . [OK]
393 IN: clean test4-empty.r 0 [OK] -- OUT: 0 [OK]
394 IN: clean testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
395 STOP
396 EOF
397 test_cmp_count expected.log rot13-filter.log &&
398
399 rm -f test2.r "testsubdir/test3 '\''sq'\'',\$x.r" &&
400
401 filter_git checkout --quiet --no-progress . &&
402 cat >expected.log <<-EOF &&
403 START
404 init handshake complete
405 IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
406 IN: smudge testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
407 STOP
408 EOF
409 test_cmp_exclude_clean expected.log rot13-filter.log &&
410
411 filter_git checkout --quiet --no-progress empty-branch &&
412 cat >expected.log <<-EOF &&
413 START
414 init handshake complete
415 IN: clean test.r $S [OK] -- OUT: $S . [OK]
416 STOP
417 EOF
418 test_cmp_exclude_clean expected.log rot13-filter.log &&
419
420 filter_git checkout --quiet --no-progress master &&
421 cat >expected.log <<-EOF &&
422 START
423 init handshake complete
424 IN: smudge test.r $S [OK] -- OUT: $S . [OK]
425 IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
426 IN: smudge test4-empty.r 0 [OK] -- OUT: 0 [OK]
427 IN: smudge testsubdir/test3 '\''sq'\'',\$x.r $S3 [OK] -- OUT: $S3 . [OK]
428 STOP
429 EOF
430 test_cmp_exclude_clean expected.log rot13-filter.log &&
431
432 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
433 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
434 test_cmp_committed_rot13 "$TEST_ROOT/test3 '\''sq'\'',\$x.o" "testsubdir/test3 '\''sq'\'',\$x.r"
435 )
436'
437
438test_expect_success PERL 'required process filter takes precedence' '
439 test_config_global filter.protocol.clean false &&
440 test_config_global filter.protocol.process "rot13-filter.pl clean" &&
441 test_config_global filter.protocol.required true &&
442 rm -rf repo &&
443 mkdir repo &&
444 (
445 cd repo &&
446 git init &&
447
448 echo "*.r filter=protocol" >.gitattributes &&
449 cp "$TEST_ROOT/test.o" test.r &&
450 S=$(file_size test.r) &&
451
452 # Check that the process filter is invoked here
453 filter_git add . &&
454 cat >expected.log <<-EOF &&
455 START
456 init handshake complete
457 IN: clean test.r $S [OK] -- OUT: $S . [OK]
458 STOP
459 EOF
460 test_cmp_count expected.log rot13-filter.log
461 )
462'
463
464test_expect_success PERL 'required process filter should be used only for "clean" operation only' '
465 test_config_global filter.protocol.process "rot13-filter.pl clean" &&
466 rm -rf repo &&
467 mkdir repo &&
468 (
469 cd repo &&
470 git init &&
471
472 echo "*.r filter=protocol" >.gitattributes &&
473 cp "$TEST_ROOT/test.o" test.r &&
474 S=$(file_size test.r) &&
475
476 filter_git add . &&
477 cat >expected.log <<-EOF &&
478 START
479 init handshake complete
480 IN: clean test.r $S [OK] -- OUT: $S . [OK]
481 STOP
482 EOF
483 test_cmp_count expected.log rot13-filter.log &&
484
485 rm test.r &&
486
487 filter_git checkout --quiet --no-progress . &&
488 # If the filter would be used for "smudge", too, we would see
489 # "IN: smudge test.r 57 [OK] -- OUT: 57 . [OK]" here
490 cat >expected.log <<-EOF &&
491 START
492 init handshake complete
493 STOP
494 EOF
495 test_cmp_exclude_clean expected.log rot13-filter.log
496 )
497'
498
499test_expect_success PERL 'required process filter should process multiple packets' '
500 test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
501 test_config_global filter.protocol.required true &&
502
503 rm -rf repo &&
504 mkdir repo &&
505 (
506 cd repo &&
507 git init &&
508
509 # Generate data requiring 1, 2, 3 packets
510 S=65516 && # PKTLINE_DATA_MAXLEN -> Maximal size of a packet
511 generate_random_characters $(($S )) 1pkt_1__.file &&
512 generate_random_characters $(($S +1)) 2pkt_1+1.file &&
513 generate_random_characters $(($S*2-1)) 2pkt_2-1.file &&
514 generate_random_characters $(($S*2 )) 2pkt_2__.file &&
515 generate_random_characters $(($S*2+1)) 3pkt_2+1.file &&
516
517 for FILE in "$TEST_ROOT"/*.file
518 do
519 cp "$FILE" . &&
520 rot13.sh <"$FILE" >"$FILE.rot13"
521 done &&
522
523 echo "*.file filter=protocol" >.gitattributes &&
524 filter_git add *.file .gitattributes &&
525 cat >expected.log <<-EOF &&
526 START
527 init handshake complete
528 IN: clean 1pkt_1__.file $(($S )) [OK] -- OUT: $(($S )) . [OK]
529 IN: clean 2pkt_1+1.file $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
530 IN: clean 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
531 IN: clean 2pkt_2__.file $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
532 IN: clean 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
533 STOP
534 EOF
535 test_cmp_count expected.log rot13-filter.log &&
536
537 rm -f *.file &&
538
539 filter_git checkout --quiet --no-progress -- *.file &&
540 cat >expected.log <<-EOF &&
541 START
542 init handshake complete
543 IN: smudge 1pkt_1__.file $(($S )) [OK] -- OUT: $(($S )) . [OK]
544 IN: smudge 2pkt_1+1.file $(($S +1)) [OK] -- OUT: $(($S +1)) .. [OK]
545 IN: smudge 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
546 IN: smudge 2pkt_2__.file $(($S*2 )) [OK] -- OUT: $(($S*2 )) .. [OK]
547 IN: smudge 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
548 STOP
549 EOF
550 test_cmp_exclude_clean expected.log rot13-filter.log &&
551
552 for FILE in *.file
553 do
554 test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE
555 done
556 )
557'
558
559test_expect_success PERL 'required process filter with clean error should fail' '
560 test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
561 test_config_global filter.protocol.required true &&
562 rm -rf repo &&
563 mkdir repo &&
564 (
565 cd repo &&
566 git init &&
567
568 echo "*.r filter=protocol" >.gitattributes &&
569
570 cp "$TEST_ROOT/test.o" test.r &&
571 echo "this is going to fail" >clean-write-fail.r &&
572 echo "content-test3-subdir" >test3.r &&
573
574 test_must_fail git add .
575 )
576'
577
578test_expect_success PERL 'process filter should restart after unexpected write failure' '
579 test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
580 rm -rf repo &&
581 mkdir repo &&
582 (
583 cd repo &&
584 git init &&
585
586 echo "*.r filter=protocol" >.gitattributes &&
587
588 cp "$TEST_ROOT/test.o" test.r &&
589 cp "$TEST_ROOT/test2.o" test2.r &&
590 echo "this is going to fail" >smudge-write-fail.o &&
591 cp smudge-write-fail.o smudge-write-fail.r &&
592
593 S=$(file_size test.r) &&
594 S2=$(file_size test2.r) &&
595 SF=$(file_size smudge-write-fail.r) &&
596
597 git add . &&
598 rm -f *.r &&
599
600 rm -f rot13-filter.log &&
601 git checkout --quiet --no-progress . 2>git-stderr.log &&
602
603 grep "smudge write error at" git-stderr.log &&
604 grep "error: external filter" git-stderr.log &&
605
606 cat >expected.log <<-EOF &&
607 START
608 init handshake complete
609 IN: smudge smudge-write-fail.r $SF [OK] -- OUT: $SF [WRITE FAIL]
610 START
611 init handshake complete
612 IN: smudge test.r $S [OK] -- OUT: $S . [OK]
613 IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
614 STOP
615 EOF
616 test_cmp_exclude_clean expected.log rot13-filter.log &&
617
618 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
619 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
620
621 # Smudge failed
622 ! test_cmp smudge-write-fail.o smudge-write-fail.r &&
623 rot13.sh <smudge-write-fail.o >expected &&
624 git cat-file blob :smudge-write-fail.r >actual &&
625 test_cmp expected actual
626 )
627'
628
629test_expect_success PERL 'process filter should not be restarted if it signals an error' '
630 test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
631 rm -rf repo &&
632 mkdir repo &&
633 (
634 cd repo &&
635 git init &&
636
637 echo "*.r filter=protocol" >.gitattributes &&
638
639 cp "$TEST_ROOT/test.o" test.r &&
640 cp "$TEST_ROOT/test2.o" test2.r &&
641 echo "this will cause an error" >error.o &&
642 cp error.o error.r &&
643
644 S=$(file_size test.r) &&
645 S2=$(file_size test2.r) &&
646 SE=$(file_size error.r) &&
647
648 git add . &&
649 rm -f *.r &&
650
651 filter_git checkout --quiet --no-progress . &&
652 cat >expected.log <<-EOF &&
653 START
654 init handshake complete
655 IN: smudge error.r $SE [OK] -- OUT: 0 [ERROR]
656 IN: smudge test.r $S [OK] -- OUT: $S . [OK]
657 IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
658 STOP
659 EOF
660 test_cmp_exclude_clean expected.log rot13-filter.log &&
661
662 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
663 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
664 test_cmp error.o error.r
665 )
666'
667
668test_expect_success PERL 'process filter abort stops processing of all further files' '
669 test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
670 rm -rf repo &&
671 mkdir repo &&
672 (
673 cd repo &&
674 git init &&
675
676 echo "*.r filter=protocol" >.gitattributes &&
677
678 cp "$TEST_ROOT/test.o" test.r &&
679 cp "$TEST_ROOT/test2.o" test2.r &&
680 echo "error this blob and all future blobs" >abort.o &&
681 cp abort.o abort.r &&
682
683 SA=$(file_size abort.r) &&
684
685 git add . &&
686 rm -f *.r &&
687
688 # Note: This test assumes that Git filters files in alphabetical
689 # order ("abort.r" before "test.r").
690 filter_git checkout --quiet --no-progress . &&
691 cat >expected.log <<-EOF &&
692 START
693 init handshake complete
694 IN: smudge abort.r $SA [OK] -- OUT: 0 [ABORT]
695 STOP
696 EOF
697 test_cmp_exclude_clean expected.log rot13-filter.log &&
698
699 test_cmp "$TEST_ROOT/test.o" test.r &&
700 test_cmp "$TEST_ROOT/test2.o" test2.r &&
701 test_cmp abort.o abort.r
702 )
703'
704
705test_expect_success PERL 'invalid process filter must fail (and not hang!)' '
706 test_config_global filter.protocol.process cat &&
707 test_config_global filter.protocol.required true &&
708 rm -rf repo &&
709 mkdir repo &&
710 (
711 cd repo &&
712 git init &&
713
714 echo "*.r filter=protocol" >.gitattributes &&
715
716 cp "$TEST_ROOT/test.o" test.r &&
717 test_must_fail git add . 2>git-stderr.log &&
718 grep "does not support filter protocol version" git-stderr.log
719 )
720'
721
722test_done