From a2b665de4b694b04959f6371f9887f7ad5cae404 Mon Sep 17 00:00:00 2001 From: Pete Wyckoff Date: Wed, 22 Dec 2010 06:40:13 -0800 Subject: convert filter: supply path to external driver Filtering to support keyword expansion may need the name of the file being filtered. In particular, to support p4 keywords like $File: //depot/product/dir/script.sh $ the smudge filter needs to know the name of the file it is smudging. Allow "%f" in the custom filter command line specified in the configuration. This will be substituted by the filename inside a single-quote pair to be passed to the shell. Signed-off-by: Pete Wyckoff Signed-off-by: Junio C Hamano --- t/t0021-conversion.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 't') diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index 828e35baf7..aacfd004b1 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -93,4 +93,46 @@ test_expect_success expanded_in_repo ' cmp expanded-keywords expected-output ' +# 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 + 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" && + : +' + test_done -- cgit v1.2.1 From 4290f690676bc14c49c7cddbcda1c09017948718 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 22 Dec 2010 15:18:47 -0800 Subject: t0021: avoid getting filter killed with SIGPIPE The fake filter did not read from the standard input at all, which caused the calling side to die with SIGPIPE, depending on the timing. Signed-off-by: Junio C Hamano --- t/t0021-conversion.sh | 1 + 1 file changed, 1 insertion(+) (limited to 't') diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index aacfd004b1..9078b84ae6 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -100,6 +100,7 @@ test_expect_success expanded_in_repo ' test_expect_success 'filter shell-escaped filenames' ' cat >argc.sh <<-EOF && #!$SHELL_PATH + cat >/dev/null echo argc: \$# "\$@" EOF normal=name-no-magic && -- cgit v1.2.1