git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] t0021: use $PERL_PATH for rot13-filter.pl

From
Jeff King <peff@peff.net>
Date
Nov 2, 2016, 18:20 UTC
Message-ID
<20161102182022.zalzmc6rcwmvrgqq@sigill.intra.peff.net>
In-Reply-To
<20161102181625.e2uprqdlzl7z2xrz@sigill.intra.peff.net>

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>
---
 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 c1ad20c61..a8fa52148 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 ae4c50f5c..e3ea58e1e
--- 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"
-- 
2.11.0.rc0.258.gf434c15
Previous: Lars SchneiderNext: Lars Schneider
Message 18 of 30 in “What's cooking in git.git (Oct 2016, #09; Mon, 31)”
  1. Junio C HamanoOct 31, 2016
  2. Torsten BögershausenNov 2, 2016
  3. Junio C HamanoNov 2, 2016
  4. Johannes SchindelinNov 2, 2016
  5. Junio C HamanoNov 2, 2016
  6. Torsten BögershausenNov 2, 2016
  7. Jeff KingNov 2, 2016
  8. 0/4 t0021 perl portability fixupsJeff King, Nov 2, 2016
  9. 1/4 t0021: use write_script to create rot13 shell scriptJeff King, Nov 2, 2016
  10. Lars SchneiderNov 6, 2016
  11. Jeff KingNov 6, 2016
  12. Lars SchneiderNov 6, 2016
  13. 2/4 t0021: put $TEST_ROOT in $PATHJeff King, Nov 2, 2016
  14. Johannes SixtNov 3, 2016
  15. Jeff KingNov 3, 2016
  16. Johannes SixtNov 3, 2016
  17. Lars SchneiderNov 6, 2016
  18. 3/4 t0021: use $PERL_PATH for rot13-filter.plJeff King, Nov 2, 2016
  19. Lars SchneiderNov 6, 2016
  20. Jeff KingNov 6, 2016
  21. 4/4 t0021: fix filehandle usage on older perlJeff King, Nov 2, 2016
  22. Torsten BögershausenNov 2, 2016
  23. Lars SchneiderNov 6, 2016
  24. Johannes SixtNov 2, 2016
  25. Lars SchneiderNov 3, 2016
  26. Lars SchneiderNov 2, 2016
  27. Torsten BögershausenNov 5, 2016
  28. Karthik NayakNov 8, 2016
  29. Torsten BögershausenNov 5, 2016
  30. Karthik NayakNov 8, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.