t / t0021-conversion.shon commit t0021-conversion.sh: fix NoTerminatingSymbolAtEOF test (dd555d8)
   1#!/bin/sh
   2
   3test_description='blob conversion via gitattributes'
   4
   5. ./test-lib.sh
   6
   7cat <<EOF >rot13.sh
   8#!$SHELL_PATH
   9tr \
  10  'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
  11  'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
  12EOF
  13chmod +x rot13.sh
  14
  15test_expect_success setup '
  16        git config filter.rot13.smudge ./rot13.sh &&
  17        git config filter.rot13.clean ./rot13.sh &&
  18
  19        {
  20            echo "*.t filter=rot13"
  21            echo "*.i ident"
  22        } >.gitattributes &&
  23
  24        {
  25            echo a b c d e f g h i j k l m
  26            echo n o p q r s t u v w x y z
  27            echo '\''$Id$'\''
  28        } >test &&
  29        cat test >test.t &&
  30        cat test >test.o &&
  31        cat test >test.i &&
  32        git add test test.t test.i &&
  33        rm -f test test.t test.i &&
  34        git checkout -- test test.t test.i
  35'
  36
  37script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
  38
  39test_expect_success check '
  40
  41        cmp test.o test &&
  42        cmp test.o test.t &&
  43
  44        # ident should be stripped in the repository
  45        git diff --raw --exit-code :test :test.i &&
  46        id=$(git rev-parse --verify :test) &&
  47        embedded=$(sed -ne "$script" test.i) &&
  48        test "z$id" = "z$embedded" &&
  49
  50        git cat-file blob :test.t > test.r &&
  51
  52        ./rot13.sh < test.o > test.t &&
  53        cmp test.r test.t
  54'
  55
  56# If an expanded ident ever gets into the repository, we want to make sure that
  57# it is collapsed before being expanded again on checkout
  58test_expect_success expanded_in_repo '
  59        {
  60                echo "File with expanded keywords"
  61                echo "\$Id\$"
  62                echo "\$Id:\$"
  63                echo "\$Id: 0000000000000000000000000000000000000000 \$"
  64                echo "\$Id: NoSpaceAtEnd\$"
  65                echo "\$Id:NoSpaceAtFront \$"
  66                echo "\$Id:NoSpaceAtEitherEnd\$"
  67                echo "\$Id: NoTerminatingSymbol"
  68                echo "\$Id: Foreign Commit With Spaces \$"
  69                printf "\$Id: NoTerminatingSymbolAtEOF"
  70        } > expanded-keywords &&
  71
  72        git add expanded-keywords &&
  73        git commit -m "File with keywords expanded" &&
  74        id=$(git rev-parse --verify :expanded-keywords) &&
  75
  76        {
  77                echo "File with expanded keywords"
  78                echo "\$Id: $id \$"
  79                echo "\$Id: $id \$"
  80                echo "\$Id: $id \$"
  81                echo "\$Id: $id \$"
  82                echo "\$Id: $id \$"
  83                echo "\$Id: $id \$"
  84                echo "\$Id: NoTerminatingSymbol"
  85                echo "\$Id: Foreign Commit With Spaces \$"
  86                printf "\$Id: NoTerminatingSymbolAtEOF"
  87        } > expected-output &&
  88
  89        echo "expanded-keywords ident" >> .gitattributes &&
  90
  91        rm -f expanded-keywords &&
  92        git checkout -- expanded-keywords &&
  93        cat expanded-keywords &&
  94        cmp expanded-keywords expected-output
  95'
  96
  97# The use of %f in a filter definition is expanded to the path to
  98# the filename being smudged or cleaned.  It must be shell escaped.
  99# First, set up some interesting file names and pet them in
 100# .gitattributes.
 101test_expect_success 'filter shell-escaped filenames' '
 102        cat >argc.sh <<-EOF &&
 103        #!$SHELL_PATH
 104        cat >/dev/null
 105        echo argc: \$# "\$@"
 106        EOF
 107        normal=name-no-magic &&
 108        special="name  with '\''sq'\'' and \$x" &&
 109        echo some test text >"$normal" &&
 110        echo some test text >"$special" &&
 111        git add "$normal" "$special" &&
 112        git commit -q -m "add files" &&
 113        echo "name* filter=argc" >.gitattributes &&
 114
 115        # delete the files and check them out again, using a smudge filter
 116        # that will count the args and echo the command-line back to us
 117        git config filter.argc.smudge "sh ./argc.sh %f" &&
 118        rm "$normal" "$special" &&
 119        git checkout -- "$normal" "$special" &&
 120
 121        # make sure argc.sh counted the right number of args
 122        echo "argc: 1 $normal" >expect &&
 123        test_cmp expect "$normal" &&
 124        echo "argc: 1 $special" >expect &&
 125        test_cmp expect "$special" &&
 126
 127        # do the same thing, but with more args in the filter expression
 128        git config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
 129        rm "$normal" "$special" &&
 130        git checkout -- "$normal" "$special" &&
 131
 132        # make sure argc.sh counted the right number of args
 133        echo "argc: 2 $normal --my-extra-arg" >expect &&
 134        test_cmp expect "$normal" &&
 135        echo "argc: 2 $special --my-extra-arg" >expect &&
 136        test_cmp expect "$special" &&
 137        :
 138'
 139
 140test_done