t: refactor environment sanitization to not use Perl

Before executing tests we first sanitize the environment. Part of the sanitization is to unset a couple of environment variables that we know will change the behaviour of Git. This is done with a small Perl script, which has the consequence that having a Perl interpreter available is a strict requirement for running our unit tests. The logic itself isn't particularly involved: we simply unset every environment variable whose key starts with 'GIT_', but then explicitly allow a subset of these. Refactor the logic to instead use sed(1) so that it becomes possible to execute our tests without Perl. Based-on-patch-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 3, 2025 at 07:05 UTC 7792d326f19bd1386600975d97f854d17d74c618
1 file changed +14 -18
t/test-lib.sh
+14 -18
@@ -499,24 +499,20 @@ EDITOR=:
499 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
500 # deriving from the command substitution clustered with the other
501 # ones.
502 -unset VISUAL EMAIL LANGUAGE $("$PERL_PATH" -e '
503 - my @env = keys %ENV;
504 - my $ok = join("|", qw(
505 - TRACE
506 - DEBUG
507 - TEST
508 - .*_TEST
509 - PROVE
510 - VALGRIND
511 - UNZIP
512 - PERF_
513 - CURL_VERBOSE
514 - TRACE_CURL
515 - BUILD_DIR
516 - ));
517 - my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
518 - print join("\n", @vars);
519 -')
502 +unset VISUAL EMAIL LANGUAGE $(env | sed -n \
503 + -e '/^GIT_TRACE/d' \
504 + -e '/^GIT_DEBUG/d' \
505 + -e '/^GIT_TEST/d' \
506 + -e '/^GIT_.*_TEST/d' \
507 + -e '/^GIT_PROVE/d' \
508 + -e '/^GIT_VALGRIND/d' \
509 + -e '/^GIT_UNZIP/d' \
510 + -e '/^GIT_PERF_/d' \
511 + -e '/^GIT_CURL_VERBOSE/d' \
512 + -e '/^GIT_TRACE_CURL/d' \
513 + -e '/^GIT_BUILD_DIR/d' \
514 + -e 's/^\(GIT_[^=]*\)=.*/\1/p'
515 +)
516 unset XDG_CACHE_HOME
517 unset XDG_CONFIG_HOME
518 unset GITPERLLIB