Skip to content

Commit f272696

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30030a3 commit f272696

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

t/t0021-conversion.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ tr \
1313
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
1414
EOF
1515

16+
write_script rot13-filter.pl "$PERL_PATH" \
17+
<"$TEST_DIRECTORY"/t0021/rot13-filter.pl
18+
1619
generate_random_characters () {
1720
LEN=$1
1821
NAME=$2
@@ -341,7 +344,7 @@ test_expect_success 'diff does not reuse worktree files that need cleaning' '
341344
'
342345

343346
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" &&
345348
test_config_global filter.protocol.required true &&
346349
rm -rf repo &&
347350
mkdir repo &&
@@ -434,7 +437,7 @@ test_expect_success PERL 'required process filter should filter data' '
434437

435438
test_expect_success PERL 'required process filter takes precedence' '
436439
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" &&
438441
test_config_global filter.protocol.required true &&
439442
rm -rf repo &&
440443
mkdir repo &&
@@ -459,7 +462,7 @@ test_expect_success PERL 'required process filter takes precedence' '
459462
'
460463

461464
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" &&
463466
rm -rf repo &&
464467
mkdir repo &&
465468
(
@@ -494,7 +497,7 @@ test_expect_success PERL 'required process filter should be used only for "clean
494497
'
495498

496499
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" &&
498501
test_config_global filter.protocol.required true &&
499502
500503
rm -rf repo &&
@@ -554,7 +557,7 @@ test_expect_success PERL 'required process filter should process multiple packet
554557
'
555558

556559
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" &&
558561
test_config_global filter.protocol.required true &&
559562
rm -rf repo &&
560563
mkdir repo &&
@@ -573,7 +576,7 @@ test_expect_success PERL 'required process filter with clean error should fail'
573576
'
574577

575578
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" &&
577580
rm -rf repo &&
578581
mkdir repo &&
579582
(
@@ -624,7 +627,7 @@ test_expect_success PERL 'process filter should restart after unexpected write f
624627
'
625628

626629
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" &&
628631
rm -rf repo &&
629632
mkdir repo &&
630633
(
@@ -663,7 +666,7 @@ test_expect_success PERL 'process filter should not be restarted if it signals a
663666
'
664667

665668
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" &&
667670
rm -rf repo &&
668671
mkdir repo &&
669672
(

t/t0021/rot13-filter.pl

100755100644
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/perl
21
#
32
# Example implementation for the Git filter protocol version 2
43
# See Documentation/gitattributes.txt, section "Filter Protocol"

0 commit comments

Comments
 (0)