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