From cbb6707b1187392c9106a8c5405d1413f2db69d0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 2 Nov 2016 14:17:51 -0400 Subject: [PATCH 1/4] t0021: use write_script to create rot13 shell script This avoids us fooling around with $SHELL_PATH and the executable bit ourselves. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0021-conversion.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index a20b9f58e3..dfde225491 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -6,13 +6,11 @@ test_description='blob conversion via gitattributes' TEST_ROOT="$(pwd)" -cat <"$TEST_ROOT/rot13.sh" -#!$SHELL_PATH +write_script <<\EOF "$TEST_ROOT/rot13.sh" tr \ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \ 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM' EOF -chmod +x "$TEST_ROOT/rot13.sh" generate_random_characters () { LEN=$1 From 30030a36b6428e5e4b259b88bfac615ff253fd9f Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 2 Nov 2016 14:18:25 -0400 Subject: [PATCH 2/4] t0021: put $TEST_ROOT in $PATH We create a rot13.sh script in the trash directory, but need to call it by its full path when we have moved our cwd to another directory. Let's just put $TEST_ROOT in our $PATH so that the script is always found. This is a minor convenience for rot13.sh, but will be a major one when we switch rot13-filter.pl to a script in the same directory, as it means we will not have to deal with shell quoting inside the filter-process config. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0021-conversion.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index dfde225491..c1ad20c618 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -5,6 +5,7 @@ test_description='blob conversion via gitattributes' . ./test-lib.sh TEST_ROOT="$(pwd)" +PATH=$TEST_ROOT:$PATH write_script <<\EOF "$TEST_ROOT/rot13.sh" tr \ @@ -64,7 +65,7 @@ test_cmp_exclude_clean () { # is equal to the committed content. test_cmp_committed_rot13 () { test_cmp "$1" "$2" && - "$TEST_ROOT/rot13.sh" <"$1" >expected && + rot13.sh <"$1" >expected && git cat-file blob :"$2" >actual && test_cmp expected actual } @@ -513,7 +514,7 @@ test_expect_success PERL 'required process filter should process multiple packet for FILE in "$TEST_ROOT"/*.file do cp "$FILE" . && - "$TEST_ROOT/rot13.sh" <"$FILE" >"$FILE.rot13" + rot13.sh <"$FILE" >"$FILE.rot13" done && echo "*.file filter=protocol" >.gitattributes && @@ -616,7 +617,7 @@ test_expect_success PERL 'process filter should restart after unexpected write f # Smudge failed ! test_cmp smudge-write-fail.o smudge-write-fail.r && - "$TEST_ROOT/rot13.sh" expected && + rot13.sh expected && git cat-file blob :smudge-write-fail.r >actual && test_cmp expected actual ) From f272696a35678438a1edd0ad1d23c8c110ede3e5 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 2 Nov 2016 14:20:22 -0400 Subject: [PATCH 3/4] 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 Signed-off-by: Junio C Hamano --- t/t0021-conversion.sh | 19 +++++++++++-------- t/t0021/rot13-filter.pl | 1 - 2 files changed, 11 insertions(+), 9 deletions(-) mode change 100755 => 100644 t/t0021/rot13-filter.pl diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index c1ad20c618..a8fa52148d 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -13,6 +13,9 @@ tr \ 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM' EOF +write_script rot13-filter.pl "$PERL_PATH" \ + <"$TEST_DIRECTORY"/t0021/rot13-filter.pl + generate_random_characters () { LEN=$1 NAME=$2 @@ -341,7 +344,7 @@ test_expect_success 'diff does not reuse worktree files that need cleaning' ' ' test_expect_success PERL 'required process filter should filter data' ' - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" && + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" && test_config_global filter.protocol.required true && rm -rf repo && mkdir repo && @@ -434,7 +437,7 @@ test_expect_success PERL 'required process filter should filter data' ' test_expect_success PERL 'required process filter takes precedence' ' test_config_global filter.protocol.clean false && - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean" && + test_config_global filter.protocol.process "rot13-filter.pl clean" && test_config_global filter.protocol.required true && rm -rf repo && mkdir repo && @@ -459,7 +462,7 @@ test_expect_success PERL 'required process filter takes precedence' ' ' test_expect_success PERL 'required process filter should be used only for "clean" operation only' ' - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean" && + test_config_global filter.protocol.process "rot13-filter.pl clean" && rm -rf repo && mkdir repo && ( @@ -494,7 +497,7 @@ test_expect_success PERL 'required process filter should be used only for "clean ' test_expect_success PERL 'required process filter should process multiple packets' ' - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" && + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" && test_config_global filter.protocol.required true && rm -rf repo && @@ -554,7 +557,7 @@ test_expect_success PERL 'required process filter should process multiple packet ' test_expect_success PERL 'required process filter with clean error should fail' ' - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" && + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" && test_config_global filter.protocol.required true && rm -rf repo && mkdir repo && @@ -573,7 +576,7 @@ test_expect_success PERL 'required process filter with clean error should fail' ' test_expect_success PERL 'process filter should restart after unexpected write failure' ' - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" && + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" && rm -rf repo && mkdir repo && ( @@ -624,7 +627,7 @@ test_expect_success PERL 'process filter should restart after unexpected write f ' test_expect_success PERL 'process filter should not be restarted if it signals an error' ' - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" && + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" && rm -rf repo && mkdir repo && ( @@ -663,7 +666,7 @@ test_expect_success PERL 'process filter should not be restarted if it signals a ' test_expect_success PERL 'process filter abort stops processing of all further files' ' - test_config_global filter.protocol.process "$TEST_DIRECTORY/t0021/rot13-filter.pl clean smudge" && + test_config_global filter.protocol.process "rot13-filter.pl clean smudge" && rm -rf repo && mkdir repo && ( diff --git a/t/t0021/rot13-filter.pl b/t/t0021/rot13-filter.pl old mode 100755 new mode 100644 index ae4c50f5c5..e3ea58e1ed --- a/t/t0021/rot13-filter.pl +++ b/t/t0021/rot13-filter.pl @@ -1,4 +1,3 @@ -#!/usr/bin/perl # # Example implementation for the Git filter protocol version 2 # See Documentation/gitattributes.txt, section "Filter Protocol" From 4821494ebc0a86aea9ec50cc0f3168541467f3a1 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 2 Nov 2016 14:23:01 -0400 Subject: [PATCH 4/4] t0021: fix filehandle usage on older perl The rot13-filter.pl script calls methods on implicitly defined filehandles (STDOUT, and the result of an open() call). Prior to perl 5.13, these methods are not automatically loaded, and perl will complain with: Can't locate object method "flush" via package "IO::Handle" Let's explicitly load IO::File (which inherits from IO::Handle). That's more than we need for just "flush", but matches what perl has done since: http://perl5.git.perl.org/perl.git/commit/15e6cdd91beb4cefae4b65e855d68cf64766965d Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0021/rot13-filter.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t0021/rot13-filter.pl b/t/t0021/rot13-filter.pl index e3ea58e1ed..4d5697ee51 100644 --- a/t/t0021/rot13-filter.pl +++ b/t/t0021/rot13-filter.pl @@ -21,6 +21,7 @@ use strict; use warnings; +use IO::File; my $MAX_PACKET_CONTENT_SIZE = 65516; my @capabilities = @ARGV;