doc-diff: use single-colon rule in rendering Makefile
[git] / t / t0021-conversion.sh
1 #!/bin/sh
2
3 test_description='blob conversion via gitattributes'
4
5 . ./test-lib.sh
6
7 TEST_ROOT="$PWD"
8 PATH=$TEST_ROOT:$PATH
9
10 write_script <<\EOF "$TEST_ROOT/rot13.sh"
11 tr \
12   'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
13   'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
14 EOF
15
16 write_script rot13-filter.pl "$PERL_PATH" \
17         <"$TEST_DIRECTORY"/t0021/rot13-filter.pl
18
19 generate_random_characters () {
20         LEN=$1
21         NAME=$2
22         test-tool genrandom some-seed $LEN |
23                 perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME"
24 }
25
26 file_size () {
27         test-tool path-utils file-size "$1"
28 }
29
30 filter_git () {
31         rm -f *.log &&
32         git "$@"
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.
38 # c.f. http://public-inbox.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
39 test_cmp_count () {
40         expect=$1
41         actual=$2
42         for FILE in "$expect" "$actual"
43         do
44                 sort "$FILE" | uniq -c |
45                 sed -e "s/^ *[0-9][0-9]*[       ]*IN: /x IN: /" >"$FILE.tmp"
46         done &&
47         test_cmp "$expect.tmp" "$actual.tmp" &&
48         rm "$expect.tmp" "$actual.tmp"
49 }
50
51 # Compare two files but exclude all `clean` invocations because Git can
52 # call `clean` zero or more times.
53 # c.f. http://public-inbox.org/git/xmqqshv18i8i.fsf@gitster.mtv.corp.google.com/
54 test_cmp_exclude_clean () {
55         expect=$1
56         actual=$2
57         for FILE in "$expect" "$actual"
58         do
59                 grep -v "IN: clean" "$FILE" >"$FILE.tmp"
60         done &&
61         test_cmp "$expect.tmp" "$actual.tmp" &&
62         rm "$expect.tmp" "$actual.tmp"
63 }
64
65 # Check that the contents of two files are equal and that their rot13 version
66 # is equal to the committed content.
67 test_cmp_committed_rot13 () {
68         test_cmp "$1" "$2" &&
69         rot13.sh <"$1" >expected &&
70         git cat-file blob :"$2" >actual &&
71         test_cmp expected actual
72 }
73
74 test_expect_success setup '
75         git config filter.rot13.smudge ./rot13.sh &&
76         git config filter.rot13.clean ./rot13.sh &&
77
78         {
79             echo "*.t filter=rot13"
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
86             echo '\''$Id$'\''
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 &&
93         git checkout -- test test.t test.i &&
94
95         echo "content-test2" >test2.o &&
96         echo "content-test3 - filename with special characters" >"test3 '\''sq'\'',\$x=.o"
97 '
98
99 script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
100
101 test_expect_success check '
102
103         test_cmp test.o test &&
104         test_cmp test.o test.t &&
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) &&
110         test "z$id" = "z$embedded" &&
111
112         git cat-file blob :test.t >test.r &&
113
114         ./rot13.sh <test.o >test.t &&
115         test_cmp test.r test.t
116 '
117
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
120 test_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"
130                 echo "\$Id: Foreign Commit With Spaces \$"
131         } >expanded-keywords.0 &&
132
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 &&
139         git commit -m "File with keywords expanded" &&
140         id=$(git rev-parse --verify :expanded-keywords) &&
141
142         {
143                 echo "File with expanded keywords"
144                 echo "\$Id: $id \$"
145                 echo "\$Id: $id \$"
146                 echo "\$Id: $id \$"
147                 echo "\$Id: $id \$"
148                 echo "\$Id: $id \$"
149                 echo "\$Id: $id \$"
150                 echo "\$Id: NoTerminatingSymbol"
151                 echo "\$Id: Foreign Commit With Spaces \$"
152         } >expected-output.0 &&
153         {
154                 cat expected-output.0 &&
155                 printf "\$Id: NoTerminatingSymbolAtEOF"
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 &&
165
166         rm -f expanded-keywords expanded-keywords-crlf &&
167
168         git checkout -- expanded-keywords &&
169         test_cmp expected-output expanded-keywords &&
170
171         git checkout -- expanded-keywords-crlf &&
172         test_cmp expected-output-crlf expanded-keywords-crlf
173 '
174
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.
179 test_expect_success 'filter shell-escaped filenames' '
180         cat >argc.sh <<-EOF &&
181         #!$SHELL_PATH
182         cat >/dev/null
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
195         test_config filter.argc.smudge "sh ./argc.sh %f" &&
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
206         test_config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
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
218 test_expect_success 'required filter should filter data' '
219         test_config filter.required.smudge ./rot13.sh &&
220         test_config filter.required.clean ./rot13.sh &&
221         test_config filter.required.required true &&
222
223         echo "*.r filter=required" >.gitattributes &&
224
225         cat test.o >test.r &&
226         git add test.r &&
227
228         rm -f test.r &&
229         git checkout -- test.r &&
230         test_cmp test.o test.r &&
231
232         ./rot13.sh <test.o >expected &&
233         git cat-file blob :test.r >actual &&
234         test_cmp expected actual
235 '
236
237 test_expect_success 'required filter smudge failure' '
238         test_config filter.failsmudge.smudge false &&
239         test_config filter.failsmudge.clean cat &&
240         test_config filter.failsmudge.required true &&
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
250 test_expect_success 'required filter clean failure' '
251         test_config filter.failclean.smudge cat &&
252         test_config filter.failclean.clean false &&
253         test_config filter.failclean.required true &&
254
255         echo "*.fc filter=failclean" >.gitattributes &&
256
257         echo test >test.fc &&
258         test_must_fail git add test.fc
259 '
260
261 test_expect_success 'filtering large input to small output should use little memory' '
262         test_config filter.devnull.clean "cat >/dev/null" &&
263         test_config filter.devnull.required true &&
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
269 test_expect_success 'filter that does not read is fine' '
270         test-tool genrandom foo $((128 * 1024 + 1)) >big &&
271         echo "big filter=epipe" >.gitattributes &&
272         test_config filter.epipe.clean "echo xyzzy" &&
273         git add big &&
274         git cat-file blob :big >actual &&
275         echo xyzzy >expect &&
276         test_cmp expect actual
277 '
278
279 test_expect_success EXPENSIVE 'filter large file' '
280         test_config filter.largefile.smudge cat &&
281         test_config filter.largefile.clean cat &&
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 &&
285         test_must_be_empty err &&
286         rm -f 2GB &&
287         git checkout -- 2GB 2>err &&
288         test_must_be_empty err
289 '
290
291 test_expect_success "filter: clean empty file" '
292         test_config filter.in-repo-header.clean  "echo cleaned && cat" &&
293         test_config filter.in-repo-header.smudge "sed 1d" &&
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
304 test_expect_success "filter: smudge empty file" '
305         test_config filter.empty-in-repo.clean "cat >/dev/null" &&
306         test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
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
317 test_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
333 test_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
344 test_expect_success PERL 'required process filter should filter data' '
345         test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
346         test_config_global filter.protocol.required true &&
347         rm -rf repo &&
348         mkdir repo &&
349         (
350                 cd repo &&
351                 git init &&
352
353                 echo "*.r filter=protocol" >.gitattributes &&
354                 git add . &&
355                 git commit -m "test commit 1" &&
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 &&
361                 cp "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" &&
362                 >test4-empty.r &&
363
364                 S=$(file_size test.r) &&
365                 S2=$(file_size test2.r) &&
366                 S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
367
368                 filter_git add . &&
369                 cat >expected.log <<-EOF &&
370                         START
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]
376                         STOP
377                 EOF
378                 test_cmp_count expected.log debug.log &&
379
380                 git commit -m "test commit 2" &&
381                 rm -f test2.r "testsubdir/test3 '\''sq'\'',\$x=.r" &&
382
383                 filter_git checkout --quiet --no-progress . &&
384                 cat >expected.log <<-EOF &&
385                         START
386                         init handshake complete
387                         IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
388                         IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
389                         STOP
390                 EOF
391                 test_cmp_exclude_clean expected.log debug.log &&
392
393                 # Make sure that the file appears dirty, so checkout below has to
394                 # run the configured filter.
395                 touch test.r &&
396                 filter_git checkout --quiet --no-progress empty-branch &&
397                 cat >expected.log <<-EOF &&
398                         START
399                         init handshake complete
400                         IN: clean test.r $S [OK] -- OUT: $S . [OK]
401                         STOP
402                 EOF
403                 test_cmp_exclude_clean expected.log debug.log &&
404
405                 filter_git checkout --quiet --no-progress master &&
406                 cat >expected.log <<-EOF &&
407                         START
408                         init handshake complete
409                         IN: smudge test.r $S [OK] -- OUT: $S . [OK]
410                         IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
411                         IN: smudge test4-empty.r 0 [OK] -- OUT: 0  [OK]
412                         IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $S3 [OK] -- OUT: $S3 . [OK]
413                         STOP
414                 EOF
415                 test_cmp_exclude_clean expected.log debug.log &&
416
417                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
418                 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
419                 test_cmp_committed_rot13 "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r"
420         )
421 '
422
423 test_expect_success PERL 'required process filter takes precedence' '
424         test_config_global filter.protocol.clean false &&
425         test_config_global filter.protocol.process "rot13-filter.pl debug.log clean" &&
426         test_config_global filter.protocol.required true &&
427         rm -rf repo &&
428         mkdir repo &&
429         (
430                 cd repo &&
431                 git init &&
432
433                 echo "*.r filter=protocol" >.gitattributes &&
434                 cp "$TEST_ROOT/test.o" test.r &&
435                 S=$(file_size test.r) &&
436
437                 # Check that the process filter is invoked here
438                 filter_git add . &&
439                 cat >expected.log <<-EOF &&
440                         START
441                         init handshake complete
442                         IN: clean test.r $S [OK] -- OUT: $S . [OK]
443                         STOP
444                 EOF
445                 test_cmp_count expected.log debug.log
446         )
447 '
448
449 test_expect_success PERL 'required process filter should be used only for "clean" operation only' '
450         test_config_global filter.protocol.process "rot13-filter.pl debug.log clean" &&
451         rm -rf repo &&
452         mkdir repo &&
453         (
454                 cd repo &&
455                 git init &&
456
457                 echo "*.r filter=protocol" >.gitattributes &&
458                 cp "$TEST_ROOT/test.o" test.r &&
459                 S=$(file_size test.r) &&
460
461                 filter_git add . &&
462                 cat >expected.log <<-EOF &&
463                         START
464                         init handshake complete
465                         IN: clean test.r $S [OK] -- OUT: $S . [OK]
466                         STOP
467                 EOF
468                 test_cmp_count expected.log debug.log &&
469
470                 rm test.r &&
471
472                 filter_git checkout --quiet --no-progress . &&
473                 # If the filter would be used for "smudge", too, we would see
474                 # "IN: smudge test.r 57 [OK] -- OUT: 57 . [OK]" here
475                 cat >expected.log <<-EOF &&
476                         START
477                         init handshake complete
478                         STOP
479                 EOF
480                 test_cmp_exclude_clean expected.log debug.log
481         )
482 '
483
484 test_expect_success PERL 'required process filter should process multiple packets' '
485         test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
486         test_config_global filter.protocol.required true &&
487
488         rm -rf repo &&
489         mkdir repo &&
490         (
491                 cd repo &&
492                 git init &&
493
494                 # Generate data requiring 1, 2, 3 packets
495                 S=65516 && # PKTLINE_DATA_MAXLEN -> Maximal size of a packet
496                 generate_random_characters $(($S    )) 1pkt_1__.file &&
497                 generate_random_characters $(($S  +1)) 2pkt_1+1.file &&
498                 generate_random_characters $(($S*2-1)) 2pkt_2-1.file &&
499                 generate_random_characters $(($S*2  )) 2pkt_2__.file &&
500                 generate_random_characters $(($S*2+1)) 3pkt_2+1.file &&
501
502                 for FILE in "$TEST_ROOT"/*.file
503                 do
504                         cp "$FILE" . &&
505                         rot13.sh <"$FILE" >"$FILE.rot13"
506                 done &&
507
508                 echo "*.file filter=protocol" >.gitattributes &&
509                 filter_git add *.file .gitattributes &&
510                 cat >expected.log <<-EOF &&
511                         START
512                         init handshake complete
513                         IN: clean 1pkt_1__.file $(($S    )) [OK] -- OUT: $(($S    )) . [OK]
514                         IN: clean 2pkt_1+1.file $(($S  +1)) [OK] -- OUT: $(($S  +1)) .. [OK]
515                         IN: clean 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
516                         IN: clean 2pkt_2__.file $(($S*2  )) [OK] -- OUT: $(($S*2  )) .. [OK]
517                         IN: clean 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
518                         STOP
519                 EOF
520                 test_cmp_count expected.log debug.log &&
521
522                 rm -f *.file &&
523
524                 filter_git checkout --quiet --no-progress -- *.file &&
525                 cat >expected.log <<-EOF &&
526                         START
527                         init handshake complete
528                         IN: smudge 1pkt_1__.file $(($S    )) [OK] -- OUT: $(($S    )) . [OK]
529                         IN: smudge 2pkt_1+1.file $(($S  +1)) [OK] -- OUT: $(($S  +1)) .. [OK]
530                         IN: smudge 2pkt_2-1.file $(($S*2-1)) [OK] -- OUT: $(($S*2-1)) .. [OK]
531                         IN: smudge 2pkt_2__.file $(($S*2  )) [OK] -- OUT: $(($S*2  )) .. [OK]
532                         IN: smudge 3pkt_2+1.file $(($S*2+1)) [OK] -- OUT: $(($S*2+1)) ... [OK]
533                         STOP
534                 EOF
535                 test_cmp_exclude_clean expected.log debug.log &&
536
537                 for FILE in *.file
538                 do
539                         test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE
540                 done
541         )
542 '
543
544 test_expect_success PERL 'required process filter with clean error should fail' '
545         test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
546         test_config_global filter.protocol.required true &&
547         rm -rf repo &&
548         mkdir repo &&
549         (
550                 cd repo &&
551                 git init &&
552
553                 echo "*.r filter=protocol" >.gitattributes &&
554
555                 cp "$TEST_ROOT/test.o" test.r &&
556                 echo "this is going to fail" >clean-write-fail.r &&
557                 echo "content-test3-subdir" >test3.r &&
558
559                 test_must_fail git add .
560         )
561 '
562
563 test_expect_success PERL 'process filter should restart after unexpected write failure' '
564         test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
565         rm -rf repo &&
566         mkdir repo &&
567         (
568                 cd repo &&
569                 git init &&
570
571                 echo "*.r filter=protocol" >.gitattributes &&
572
573                 cp "$TEST_ROOT/test.o" test.r &&
574                 cp "$TEST_ROOT/test2.o" test2.r &&
575                 echo "this is going to fail" >smudge-write-fail.o &&
576                 cp smudge-write-fail.o smudge-write-fail.r &&
577
578                 S=$(file_size test.r) &&
579                 S2=$(file_size test2.r) &&
580                 SF=$(file_size smudge-write-fail.r) &&
581
582                 git add . &&
583                 rm -f *.r &&
584
585                 rm -f debug.log &&
586                 git checkout --quiet --no-progress . 2>git-stderr.log &&
587
588                 grep "smudge write error at" git-stderr.log &&
589                 test_i18ngrep "error: external filter" git-stderr.log &&
590
591                 cat >expected.log <<-EOF &&
592                         START
593                         init handshake complete
594                         IN: smudge smudge-write-fail.r $SF [OK] -- [WRITE FAIL]
595                         START
596                         init handshake complete
597                         IN: smudge test.r $S [OK] -- OUT: $S . [OK]
598                         IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
599                         STOP
600                 EOF
601                 test_cmp_exclude_clean expected.log debug.log &&
602
603                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
604                 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
605
606                 # Smudge failed
607                 ! test_cmp smudge-write-fail.o smudge-write-fail.r &&
608                 rot13.sh <smudge-write-fail.o >expected &&
609                 git cat-file blob :smudge-write-fail.r >actual &&
610                 test_cmp expected actual
611         )
612 '
613
614 test_expect_success PERL 'process filter should not be restarted if it signals an error' '
615         test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
616         rm -rf repo &&
617         mkdir repo &&
618         (
619                 cd repo &&
620                 git init &&
621
622                 echo "*.r filter=protocol" >.gitattributes &&
623
624                 cp "$TEST_ROOT/test.o" test.r &&
625                 cp "$TEST_ROOT/test2.o" test2.r &&
626                 echo "this will cause an error" >error.o &&
627                 cp error.o error.r &&
628
629                 S=$(file_size test.r) &&
630                 S2=$(file_size test2.r) &&
631                 SE=$(file_size error.r) &&
632
633                 git add . &&
634                 rm -f *.r &&
635
636                 filter_git checkout --quiet --no-progress . &&
637                 cat >expected.log <<-EOF &&
638                         START
639                         init handshake complete
640                         IN: smudge error.r $SE [OK] -- [ERROR]
641                         IN: smudge test.r $S [OK] -- OUT: $S . [OK]
642                         IN: smudge test2.r $S2 [OK] -- OUT: $S2 . [OK]
643                         STOP
644                 EOF
645                 test_cmp_exclude_clean expected.log debug.log &&
646
647                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.r &&
648                 test_cmp_committed_rot13 "$TEST_ROOT/test2.o" test2.r &&
649                 test_cmp error.o error.r
650         )
651 '
652
653 test_expect_success PERL 'process filter abort stops processing of all further files' '
654         test_config_global filter.protocol.process "rot13-filter.pl debug.log clean smudge" &&
655         rm -rf repo &&
656         mkdir repo &&
657         (
658                 cd repo &&
659                 git init &&
660
661                 echo "*.r filter=protocol" >.gitattributes &&
662
663                 cp "$TEST_ROOT/test.o" test.r &&
664                 cp "$TEST_ROOT/test2.o" test2.r &&
665                 echo "error this blob and all future blobs" >abort.o &&
666                 cp abort.o abort.r &&
667
668                 SA=$(file_size abort.r) &&
669
670                 git add . &&
671                 rm -f *.r &&
672
673                 # Note: This test assumes that Git filters files in alphabetical
674                 # order ("abort.r" before "test.r").
675                 filter_git checkout --quiet --no-progress . &&
676                 cat >expected.log <<-EOF &&
677                         START
678                         init handshake complete
679                         IN: smudge abort.r $SA [OK] -- [ABORT]
680                         STOP
681                 EOF
682                 test_cmp_exclude_clean expected.log debug.log &&
683
684                 test_cmp "$TEST_ROOT/test.o" test.r &&
685                 test_cmp "$TEST_ROOT/test2.o" test2.r &&
686                 test_cmp abort.o abort.r
687         )
688 '
689
690 test_expect_success PERL 'invalid process filter must fail (and not hang!)' '
691         test_config_global filter.protocol.process cat &&
692         test_config_global filter.protocol.required true &&
693         rm -rf repo &&
694         mkdir repo &&
695         (
696                 cd repo &&
697                 git init &&
698
699                 echo "*.r filter=protocol" >.gitattributes &&
700
701                 cp "$TEST_ROOT/test.o" test.r &&
702                 test_must_fail git add . 2>git-stderr.log &&
703                 grep "expected git-filter-server" git-stderr.log
704         )
705 '
706
707 test_expect_success PERL 'delayed checkout in process filter' '
708         test_config_global filter.a.process "rot13-filter.pl a.log clean smudge delay" &&
709         test_config_global filter.a.required true &&
710         test_config_global filter.b.process "rot13-filter.pl b.log clean smudge delay" &&
711         test_config_global filter.b.required true &&
712
713         rm -rf repo &&
714         mkdir repo &&
715         (
716                 cd repo &&
717                 git init &&
718                 echo "*.a filter=a" >.gitattributes &&
719                 echo "*.b filter=b" >>.gitattributes &&
720                 cp "$TEST_ROOT/test.o" test.a &&
721                 cp "$TEST_ROOT/test.o" test-delay10.a &&
722                 cp "$TEST_ROOT/test.o" test-delay11.a &&
723                 cp "$TEST_ROOT/test.o" test-delay20.a &&
724                 cp "$TEST_ROOT/test.o" test-delay10.b &&
725                 git add . &&
726                 git commit -m "test commit"
727         ) &&
728
729         S=$(file_size "$TEST_ROOT/test.o") &&
730         cat >a.exp <<-EOF &&
731                 START
732                 init handshake complete
733                 IN: smudge test.a $S [OK] -- OUT: $S . [OK]
734                 IN: smudge test-delay10.a $S [OK] -- [DELAYED]
735                 IN: smudge test-delay11.a $S [OK] -- [DELAYED]
736                 IN: smudge test-delay20.a $S [OK] -- [DELAYED]
737                 IN: list_available_blobs test-delay10.a test-delay11.a [OK]
738                 IN: smudge test-delay10.a 0 [OK] -- OUT: $S . [OK]
739                 IN: smudge test-delay11.a 0 [OK] -- OUT: $S . [OK]
740                 IN: list_available_blobs test-delay20.a [OK]
741                 IN: smudge test-delay20.a 0 [OK] -- OUT: $S . [OK]
742                 IN: list_available_blobs [OK]
743                 STOP
744         EOF
745         cat >b.exp <<-EOF &&
746                 START
747                 init handshake complete
748                 IN: smudge test-delay10.b $S [OK] -- [DELAYED]
749                 IN: list_available_blobs test-delay10.b [OK]
750                 IN: smudge test-delay10.b 0 [OK] -- OUT: $S . [OK]
751                 IN: list_available_blobs [OK]
752                 STOP
753         EOF
754
755         rm -rf repo-cloned &&
756         filter_git clone repo repo-cloned &&
757         test_cmp_count a.exp repo-cloned/a.log &&
758         test_cmp_count b.exp repo-cloned/b.log &&
759
760         (
761                 cd repo-cloned &&
762                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
763                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&
764                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a &&
765                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a &&
766                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b &&
767
768                 rm *.a *.b &&
769                 filter_git checkout . &&
770                 test_cmp_count ../a.exp a.log &&
771                 test_cmp_count ../b.exp b.log &&
772
773                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test.a &&
774                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.a &&
775                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay11.a &&
776                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay20.a &&
777                 test_cmp_committed_rot13 "$TEST_ROOT/test.o" test-delay10.b
778         )
779 '
780
781 test_expect_success PERL 'missing file in delayed checkout' '
782         test_config_global filter.bug.process "rot13-filter.pl bug.log clean smudge delay" &&
783         test_config_global filter.bug.required true &&
784
785         rm -rf repo &&
786         mkdir repo &&
787         (
788                 cd repo &&
789                 git init &&
790                 echo "*.a filter=bug" >.gitattributes &&
791                 cp "$TEST_ROOT/test.o" missing-delay.a &&
792                 git add . &&
793                 git commit -m "test commit"
794         ) &&
795
796         rm -rf repo-cloned &&
797         test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
798         cat git-stderr.log &&
799         grep "error: .missing-delay\.a. was not filtered properly" git-stderr.log
800 '
801
802 test_expect_success PERL 'invalid file in delayed checkout' '
803         test_config_global filter.bug.process "rot13-filter.pl bug.log clean smudge delay" &&
804         test_config_global filter.bug.required true &&
805
806         rm -rf repo &&
807         mkdir repo &&
808         (
809                 cd repo &&
810                 git init &&
811                 echo "*.a filter=bug" >.gitattributes &&
812                 cp "$TEST_ROOT/test.o" invalid-delay.a &&
813                 cp "$TEST_ROOT/test.o" unfiltered &&
814                 git add . &&
815                 git commit -m "test commit"
816         ) &&
817
818         rm -rf repo-cloned &&
819         test_must_fail git clone repo repo-cloned 2>git-stderr.log &&
820         grep "error: external filter .* signaled that .unfiltered. is now available although it has not been delayed earlier" git-stderr.log
821 '
822
823 test_done