t / t0021-conversion.shon commit Merge branch 'mk/maint-parse-careful' (eadbcd4)
   1#!/bin/sh
   2
   3test_description='blob conversion via gitattributes'
   4
   5. ./test-lib.sh
   6
   7cat <<\EOF >rot13.sh
   8tr '[a-zA-Z]' '[n-za-mN-ZA-M]'
   9EOF
  10chmod +x rot13.sh
  11
  12test_expect_success setup '
  13        git config filter.rot13.smudge ./rot13.sh &&
  14        git config filter.rot13.clean ./rot13.sh &&
  15
  16        {
  17            echo "*.t filter=rot13"
  18            echo "*.i ident"
  19        } >.gitattributes &&
  20
  21        {
  22            echo a b c d e f g h i j k l m
  23            echo n o p q r s t u v w x y z
  24            echo '\''$Id$'\''
  25        } >test &&
  26        cat test >test.t &&
  27        cat test >test.o &&
  28        cat test >test.i &&
  29        git add test test.t test.i &&
  30        rm -f test test.t test.i &&
  31        git checkout -- test test.t test.i
  32'
  33
  34script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
  35
  36test_expect_success check '
  37
  38        cmp test.o test &&
  39        cmp test.o test.t &&
  40
  41        # ident should be stripped in the repository
  42        git diff --raw --exit-code :test :test.i &&
  43        id=$(git rev-parse --verify :test) &&
  44        embedded=$(sed -ne "$script" test.i) &&
  45        test "z$id" = "z$embedded" &&
  46
  47        git cat-file blob :test.t > test.r &&
  48
  49        ./rot13.sh < test.o > test.t &&
  50        cmp test.r test.t
  51'
  52
  53# If an expanded ident ever gets into the repository, we want to make sure that
  54# it is collapsed before being expanded again on checkout
  55test_expect_success expanded_in_repo '
  56        {
  57                echo "File with expanded keywords"
  58                echo "\$Id\$"
  59                echo "\$Id:\$"
  60                echo "\$Id: 0000000000000000000000000000000000000000 \$"
  61                echo "\$Id: NoSpaceAtEnd\$"
  62                echo "\$Id:NoSpaceAtFront \$"
  63                echo "\$Id:NoSpaceAtEitherEnd\$"
  64                echo "\$Id: NoTerminatingSymbol"
  65        } > expanded-keywords &&
  66
  67        {
  68                echo "File with expanded keywords"
  69                echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
  70                echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
  71                echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
  72                echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
  73                echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
  74                echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$"
  75                echo "\$Id: NoTerminatingSymbol"
  76        } > expected-output &&
  77
  78        git add expanded-keywords &&
  79        git commit -m "File with keywords expanded" &&
  80
  81        echo "expanded-keywords ident" >> .gitattributes &&
  82
  83        rm -f expanded-keywords &&
  84        git checkout -- expanded-keywords &&
  85        cat expanded-keywords &&
  86        cmp expanded-keywords expected-output
  87'
  88
  89test_done