t0021: use $PERL_PATH for rot13-filter.pl

The rot13-filter.pl script hardcodes "#!/usr/bin/perl", and does not respect $PERL_PATH at all. That is a problem if the system does not have perl at that path, or if it has a perl that is too old to run a complicated script like the rot13-filter (but PERL_PATH points to a more modern one). We can fix this by using write_script() to create a new copy of the script with the correct #!-line. In theory we could move the whole script inside t0021-conversion.sh rather than having it as an auxiliary file, but it's long enough that it just makes things harder to read. As a bonus, we can stop using the full path to the script in the filter-process config we add (because the trash directory is in our PATH). Not only is this shorter, but it sidesteps any shell-quoting issues. The original was broken when $TEST_DIRECTORY contained a space, because it was interpolated in the outer script. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Nov 2, 2016 at 14:20 UTC f272696a35678438a1edd0ad1d23c8c110ede3e5
2 files changed +11 -9
t/t0021-conversion.sh
+11 -8
@@ -13,6 +13,9 @@ tr \
13 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
14 EOF
15
16 +write_script rot13-filter.pl "$PERL_PATH" \
17 + <"$TEST_DIRECTORY"/t0021/rot13-filter.pl
18 +
19 generate_random_characters () {
20 LEN=$1
21 NAME=$2
@@ -341,7 +344,7 @@ test_expect_success 'diff does not reuse worktree files that need cleaning' '
344 '
345
346 test_expect_success PERL 'required process filter should filter data' '
344 - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
347 + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
348 test_config_global filter.protocol.required true &&
349 rm -rf repo &&
350 mkdir repo &&
@@ -434,7 +437,7 @@ test_expect_success PERL 'required process filter should filter data' '
437
438 test_expect_success PERL 'required process filter takes precedence' '
439 test_config_global filter.protocol.clean false &&
437 - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean" &&
440 + test_config_global filter.protocol.process "rot13-filter.pl clean" &&
441 test_config_global filter.protocol.required true &&
442 rm -rf repo &&
443 mkdir repo &&
@@ -459,7 +462,7 @@ test_expect_success PERL 'required process filter takes precedence' '
462 '
463
464 test_expect_success PERL 'required process filter should be used only for "clean" operation only' '
462 - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean" &&
465 + test_config_global filter.protocol.process "rot13-filter.pl clean" &&
466 rm -rf repo &&
467 mkdir repo &&
468 (
@@ -494,7 +497,7 @@ test_expect_success PERL 'required process filter should be used only for "clean
497 '
498
499 test_expect_success PERL 'required process filter should process multiple packets' '
497 - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
500 + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
501 test_config_global filter.protocol.required true &&
502
503 rm -rf repo &&
@@ -554,7 +557,7 @@ test_expect_success PERL 'required process filter should process multiple packet
557 '
558
559 test_expect_success PERL 'required process filter with clean error should fail' '
557 - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
560 + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
561 test_config_global filter.protocol.required true &&
562 rm -rf repo &&
563 mkdir repo &&
@@ -573,7 +576,7 @@ test_expect_success PERL 'required process filter with clean error should fail'
576 '
577
578 test_expect_success PERL 'process filter should restart after unexpected write failure' '
576 - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
579 + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
580 rm -rf repo &&
581 mkdir repo &&
582 (
@@ -624,7 +627,7 @@ test_expect_success PERL 'process filter should restart after unexpected write f
627 '
628
629 test_expect_success PERL 'process filter should not be restarted if it signals an error' '
627 - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
630 + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
631 rm -rf repo &&
632 mkdir repo &&
633 (
@@ -663,7 +666,7 @@ test_expect_success PERL 'process filter should not be restarted if it signals a
666 '
667
668 test_expect_success PERL 'process filter abort stops processing of all further files' '
666 - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" &&
669 + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" &&
670 rm -rf repo &&
671 mkdir repo &&
672 (
t/t0021/rot13-filter.pl
-1
@@ -1,4 +1,3 @@
1 -#!/usr/bin/perl
1 #
2 # Example implementation for the Git filter protocol version 2
3 # See Documentation/gitattributes.txt, section "Filter Protocol"