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