2007-04-22 04:09:02 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='blob conversion via gitattributes'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2010-01-01 23:14:06 +01:00
|
|
|
cat <<EOF >rot13.sh
|
|
|
|
#!$SHELL_PATH
|
2008-03-11 18:40:45 +01:00
|
|
|
tr \
|
|
|
|
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
|
|
|
|
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
|
2007-04-21 12:14:13 +02:00
|
|
|
EOF
|
|
|
|
chmod +x rot13.sh
|
|
|
|
|
2007-04-22 04:09:02 +02:00
|
|
|
test_expect_success setup '
|
2007-04-21 12:14:13 +02:00
|
|
|
git config filter.rot13.smudge ./rot13.sh &&
|
|
|
|
git config filter.rot13.clean ./rot13.sh &&
|
|
|
|
|
2007-04-22 04:09:02 +02:00
|
|
|
{
|
2007-04-21 12:14:13 +02:00
|
|
|
echo "*.t filter=rot13"
|
2007-04-22 04:09:02 +02:00
|
|
|
echo "*.i ident"
|
|
|
|
} >.gitattributes &&
|
|
|
|
|
|
|
|
{
|
|
|
|
echo a b c d e f g h i j k l m
|
|
|
|
echo n o p q r s t u v w x y z
|
2007-05-14 15:37:25 +02:00
|
|
|
echo '\''$Id$'\''
|
2007-04-22 04:09:02 +02:00
|
|
|
} >test &&
|
|
|
|
cat test >test.t &&
|
|
|
|
cat test >test.o &&
|
|
|
|
cat test >test.i &&
|
|
|
|
git add test test.t test.i &&
|
|
|
|
rm -f test test.t test.i &&
|
|
|
|
git checkout -- test test.t test.i
|
|
|
|
'
|
|
|
|
|
2007-05-14 15:37:25 +02:00
|
|
|
script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
|
2007-04-22 04:09:02 +02:00
|
|
|
|
|
|
|
test_expect_success check '
|
|
|
|
|
|
|
|
cmp test.o test &&
|
|
|
|
cmp test.o test.t &&
|
|
|
|
|
|
|
|
# ident should be stripped in the repository
|
|
|
|
git diff --raw --exit-code :test :test.i &&
|
|
|
|
id=$(git rev-parse --verify :test) &&
|
|
|
|
embedded=$(sed -ne "$script" test.i) &&
|
2007-10-19 21:48:04 +02:00
|
|
|
test "z$id" = "z$embedded" &&
|
|
|
|
|
|
|
|
git cat-file blob :test.t > test.r &&
|
|
|
|
|
|
|
|
./rot13.sh < test.o > test.t &&
|
|
|
|
cmp test.r test.t
|
2007-04-22 04:09:02 +02:00
|
|
|
'
|
|
|
|
|
2007-05-27 12:52:11 +02:00
|
|
|
# If an expanded ident ever gets into the repository, we want to make sure that
|
|
|
|
# it is collapsed before being expanded again on checkout
|
|
|
|
test_expect_success expanded_in_repo '
|
|
|
|
{
|
|
|
|
echo "File with expanded keywords"
|
|
|
|
echo "\$Id\$"
|
|
|
|
echo "\$Id:\$"
|
|
|
|
echo "\$Id: 0000000000000000000000000000000000000000 \$"
|
|
|
|
echo "\$Id: NoSpaceAtEnd\$"
|
|
|
|
echo "\$Id:NoSpaceAtFront \$"
|
|
|
|
echo "\$Id:NoSpaceAtEitherEnd\$"
|
|
|
|
echo "\$Id: NoTerminatingSymbol"
|
2010-04-06 14:46:37 +02:00
|
|
|
echo "\$Id: Foreign Commit With Spaces \$"
|
|
|
|
echo "\$Id: NoTerminatingSymbolAtEOF"
|
2007-05-27 12:52:11 +02:00
|
|
|
} > expanded-keywords &&
|
|
|
|
|
|
|
|
{
|
|
|
|
echo "File with expanded keywords"
|
2010-04-06 14:46:37 +02:00
|
|
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
|
|
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
|
|
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
|
|
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
|
|
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
|
|
|
echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$"
|
2007-05-27 12:52:11 +02:00
|
|
|
echo "\$Id: NoTerminatingSymbol"
|
2010-04-06 14:46:38 +02:00
|
|
|
echo "\$Id: Foreign Commit With Spaces \$"
|
2010-04-06 14:46:37 +02:00
|
|
|
echo "\$Id: NoTerminatingSymbolAtEOF"
|
2007-05-27 12:52:11 +02:00
|
|
|
} > expected-output &&
|
|
|
|
|
|
|
|
git add expanded-keywords &&
|
|
|
|
git commit -m "File with keywords expanded" &&
|
|
|
|
|
|
|
|
echo "expanded-keywords ident" >> .gitattributes &&
|
|
|
|
|
|
|
|
rm -f expanded-keywords &&
|
|
|
|
git checkout -- expanded-keywords &&
|
|
|
|
cat expanded-keywords &&
|
|
|
|
cmp expanded-keywords expected-output
|
|
|
|
'
|
|
|
|
|
2010-12-22 15:40:13 +01:00
|
|
|
# The use of %f in a filter definition is expanded to the path to
|
|
|
|
# the filename being smudged or cleaned. It must be shell escaped.
|
|
|
|
# First, set up some interesting file names and pet them in
|
|
|
|
# .gitattributes.
|
|
|
|
test_expect_success 'filter shell-escaped filenames' '
|
|
|
|
cat >argc.sh <<-EOF &&
|
|
|
|
#!$SHELL_PATH
|
2010-12-23 00:18:47 +01:00
|
|
|
cat >/dev/null
|
2010-12-22 15:40:13 +01:00
|
|
|
echo argc: \$# "\$@"
|
|
|
|
EOF
|
|
|
|
normal=name-no-magic &&
|
|
|
|
special="name with '\''sq'\'' and \$x" &&
|
|
|
|
echo some test text >"$normal" &&
|
|
|
|
echo some test text >"$special" &&
|
|
|
|
git add "$normal" "$special" &&
|
|
|
|
git commit -q -m "add files" &&
|
|
|
|
echo "name* filter=argc" >.gitattributes &&
|
|
|
|
|
|
|
|
# delete the files and check them out again, using a smudge filter
|
|
|
|
# that will count the args and echo the command-line back to us
|
|
|
|
git config filter.argc.smudge "sh ./argc.sh %f" &&
|
|
|
|
rm "$normal" "$special" &&
|
|
|
|
git checkout -- "$normal" "$special" &&
|
|
|
|
|
|
|
|
# make sure argc.sh counted the right number of args
|
|
|
|
echo "argc: 1 $normal" >expect &&
|
|
|
|
test_cmp expect "$normal" &&
|
|
|
|
echo "argc: 1 $special" >expect &&
|
|
|
|
test_cmp expect "$special" &&
|
|
|
|
|
|
|
|
# do the same thing, but with more args in the filter expression
|
|
|
|
git config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" &&
|
|
|
|
rm "$normal" "$special" &&
|
|
|
|
git checkout -- "$normal" "$special" &&
|
|
|
|
|
|
|
|
# make sure argc.sh counted the right number of args
|
|
|
|
echo "argc: 2 $normal --my-extra-arg" >expect &&
|
|
|
|
test_cmp expect "$normal" &&
|
|
|
|
echo "argc: 2 $special --my-extra-arg" >expect &&
|
|
|
|
test_cmp expect "$special" &&
|
|
|
|
:
|
|
|
|
'
|
|
|
|
|
2007-04-22 04:09:02 +02:00
|
|
|
test_done
|