The majority of Perl scripts we carry in Git have a `#!/usr/bin/perl` shebang. This is not a portable location for the Perl interpreter and may thus break on some systems that have the interpreter installed in a different location. One such example is NixOS, where the only executable installed in `/usr/bin` is env(1). Convert the shebangs to resolve the location of the Perl interpreter via env(1) to make these scripts more portable. While the location of env(1) is not guaranteed by any standard either, in practice all distributions including NixOS have it available at `/usr/bin/env`. We're also already using this idiom in a small set of other scripts, and until now nobody complained about them. This makes the test suite pass on NixOS. Signed-off-by: Patrick Steinhardt --- Documentation/build-docdep.perl | 2 +- Documentation/cat-texi.perl | 2 +- Documentation/cmd-list.perl | 3 ++- Documentation/fix-texi.perl | 4 +++- Documentation/lint-fsck-msgids.perl | 2 +- Documentation/lint-gitlink.perl | 2 +- Documentation/lint-man-end-blurb.perl | 2 +- Documentation/lint-man-section-order.perl | 2 +- compat/vcbuild/scripts/clink.pl | 5 ++++- compat/vcbuild/scripts/lib.pl | 5 ++++- contrib/buildsystems/CMakeLists.txt | 2 +- contrib/buildsystems/engine.pl | 5 ++++- contrib/buildsystems/generate | 5 ++++- contrib/buildsystems/parse.pl | 5 ++++- contrib/contacts/git-contacts | 2 +- contrib/credential/netrc/git-credential-netrc.perl | 2 +- contrib/credential/netrc/test.pl | 2 +- contrib/diff-highlight/Makefile | 2 +- contrib/fast-import/git-import.perl | 2 +- contrib/fast-import/import-directories.perl | 2 +- contrib/fast-import/import-tars.perl | 2 +- contrib/hooks/setgitperms.perl | 2 +- contrib/hooks/update-paranoid | 2 +- contrib/long-running-filter/example.pl | 2 +- contrib/mw-to-git/git-mw.perl | 2 +- contrib/mw-to-git/git-remote-mediawiki.perl | 2 +- contrib/mw-to-git/t/test-gitmw.pl | 6 +++++- contrib/stats/mailmap.pl | 2 +- contrib/stats/packinfo.pl | 2 +- contrib/subtree/t/Makefile | 2 +- git-archimport.perl | 2 +- git-cvsexportcommit.perl | 2 +- git-cvsimport.perl | 2 +- git-cvsserver.perl | 2 +- git-send-email.perl | 2 +- git-svn.perl | 2 +- gitweb/gitweb.perl | 2 +- t/Git-SVN/Utils/can_compress.t | 2 +- t/Git-SVN/Utils/fatal.t | 2 +- t/check-non-portable-shell.pl | 2 +- t/lib-gitweb.sh | 2 +- t/perf/aggregate.perl | 2 +- t/perf/min_time.perl | 2 +- t/t0019/parse_json.perl | 2 +- t/t0202/test.pl | 2 +- t/t0210/scrub_normal.perl | 2 +- t/t0211/scrub_perf.perl | 2 +- t/t0212/parse_events.perl | 2 +- t/t4034/perl/post | 2 +- t/t4034/perl/pre | 2 +- t/t7519/fsmonitor-all-v2 | 2 +- t/t7519/fsmonitor-watchman | 2 +- t/t7519/fsmonitor-watchman-v2 | 2 +- t/t9700/test.pl | 2 +- t/test-terminal.perl | 2 +- templates/hooks--fsmonitor-watchman.sample | 2 +- 56 files changed, 78 insertions(+), 56 deletions(-) diff --git a/Documentation/build-docdep.perl b/Documentation/build-docdep.perl index 1b3ac8fdd9..fe6a1e724d 100755 --- a/Documentation/build-docdep.perl +++ b/Documentation/build-docdep.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl my %include = (); my %included = (); diff --git a/Documentation/cat-texi.perl b/Documentation/cat-texi.perl index 14d2f83415..5b44d64f7d 100755 --- a/Documentation/cat-texi.perl +++ b/Documentation/cat-texi.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl use strict; use warnings; diff --git a/Documentation/cmd-list.perl b/Documentation/cmd-list.perl index 755a110bc4..3fe43b8968 100755 --- a/Documentation/cmd-list.perl +++ b/Documentation/cmd-list.perl @@ -1,5 +1,6 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl +use warnings; use File::Compare qw(compare); sub format_one { diff --git a/Documentation/fix-texi.perl b/Documentation/fix-texi.perl index ff7d78f620..61287a0a9e 100755 --- a/Documentation/fix-texi.perl +++ b/Documentation/fix-texi.perl @@ -1,4 +1,6 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl + +use warnings; while (<>) { if (/^\@setfilename/) { diff --git a/Documentation/lint-fsck-msgids.perl b/Documentation/lint-fsck-msgids.perl index 1233ffe815..fd2209e4f8 100755 --- a/Documentation/lint-fsck-msgids.perl +++ b/Documentation/lint-fsck-msgids.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl my ($fsck_h, $fsck_msgids_txt, $okfile) = @ARGV; diff --git a/Documentation/lint-gitlink.perl b/Documentation/lint-gitlink.perl index 1c61dd9512..b27418ee16 100755 --- a/Documentation/lint-gitlink.perl +++ b/Documentation/lint-gitlink.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; diff --git a/Documentation/lint-man-end-blurb.perl b/Documentation/lint-man-end-blurb.perl index 6bdb13ad9f..d1ee7ba130 100755 --- a/Documentation/lint-man-end-blurb.perl +++ b/Documentation/lint-man-end-blurb.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; diff --git a/Documentation/lint-man-section-order.perl b/Documentation/lint-man-section-order.perl index 02408a0062..27921ef66f 100755 --- a/Documentation/lint-man-section-order.perl +++ b/Documentation/lint-man-section-order.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; diff --git a/compat/vcbuild/scripts/clink.pl b/compat/vcbuild/scripts/clink.pl index 3bd824154b..74be842ebd 100755 --- a/compat/vcbuild/scripts/clink.pl +++ b/compat/vcbuild/scripts/clink.pl @@ -1,4 +1,7 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl + +use warnings; + ###################################################################### # Compiles or links files # diff --git a/compat/vcbuild/scripts/lib.pl b/compat/vcbuild/scripts/lib.pl index d8054e469f..6f2c2cb89f 100755 --- a/compat/vcbuild/scripts/lib.pl +++ b/compat/vcbuild/scripts/lib.pl @@ -1,4 +1,7 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl + +use warnings; + ###################################################################### # Libifies files on Windows # diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 2f6e0197ff..43d64909cb 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -848,7 +848,7 @@ string(REPLACE "@@INSTLIBDIR@@" "${INSTLIBDIR}" perl_header "${perl_header}") foreach(script ${git_perl_scripts}) file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME) - string(REPLACE "#!/usr/bin/perl" "#!/usr/bin/perl\n${perl_header}\n" content "${content}") + string(REPLACE "#!/usr/bin/env perl" "#!/usr/bin/env perl\n${perl_header}\n" content "${content}") string(REPLACE "@@GIT_VERSION@@" "${PROJECT_VERSION}" content "${content}") file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content}) endforeach() diff --git a/contrib/buildsystems/engine.pl b/contrib/buildsystems/engine.pl index ed6c45988a..ea32de593c 100755 --- a/contrib/buildsystems/engine.pl +++ b/contrib/buildsystems/engine.pl @@ -1,4 +1,7 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl + +use warnings; + ###################################################################### # Do not call this script directly! # diff --git a/contrib/buildsystems/generate b/contrib/buildsystems/generate index bc10f25ff2..41c1967496 100755 --- a/contrib/buildsystems/generate +++ b/contrib/buildsystems/generate @@ -1,4 +1,7 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl + +use warnings; + ###################################################################### # Generate buildsystem files # diff --git a/contrib/buildsystems/parse.pl b/contrib/buildsystems/parse.pl index c9656ece99..03050ab28d 100755 --- a/contrib/buildsystems/parse.pl +++ b/contrib/buildsystems/parse.pl @@ -1,4 +1,7 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl + +use warnings; + ###################################################################### # Do not call this script directly! # diff --git a/contrib/contacts/git-contacts b/contrib/contacts/git-contacts index 85ad732fc0..a9ce8edb85 100755 --- a/contrib/contacts/git-contacts +++ b/contrib/contacts/git-contacts @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # List people who might be interested in a patch. Useful as the argument to # git-send-email --cc-cmd option, and in other situations. diff --git a/contrib/credential/netrc/git-credential-netrc.perl b/contrib/credential/netrc/git-credential-netrc.perl index 9fb998ae09..514f68d00b 100755 --- a/contrib/credential/netrc/git-credential-netrc.perl +++ b/contrib/credential/netrc/git-credential-netrc.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; diff --git a/contrib/credential/netrc/test.pl b/contrib/credential/netrc/test.pl index c0fb3718b2..4387379d52 100755 --- a/contrib/credential/netrc/test.pl +++ b/contrib/credential/netrc/test.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use warnings; use strict; diff --git a/contrib/diff-highlight/Makefile b/contrib/diff-highlight/Makefile index f2be7cc924..9da2a0b442 100644 --- a/contrib/diff-highlight/Makefile +++ b/contrib/diff-highlight/Makefile @@ -1,6 +1,6 @@ all: diff-highlight -PERL_PATH = /usr/bin/perl +PERL_PATH = /usr/bin/env perl -include ../../config.mak PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH)) diff --git a/contrib/fast-import/git-import.perl b/contrib/fast-import/git-import.perl index 0891b9e366..440790523d 100755 --- a/contrib/fast-import/git-import.perl +++ b/contrib/fast-import/git-import.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # Performs an initial import of a directory. This is the equivalent # of doing 'git init; git add .; git commit'. It's a little slower, diff --git a/contrib/fast-import/import-directories.perl b/contrib/fast-import/import-directories.perl index a16f79cfdc..5ea90dada9 100755 --- a/contrib/fast-import/import-directories.perl +++ b/contrib/fast-import/import-directories.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # Copyright 2008-2009 Peter Krefting # diff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl index d50ce26d5d..d28c7b1a4a 100755 --- a/contrib/fast-import/import-tars.perl +++ b/contrib/fast-import/import-tars.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl ## tar archive frontend for git-fast-import ## diff --git a/contrib/hooks/setgitperms.perl b/contrib/hooks/setgitperms.perl index 2770a1b1d2..18444e0157 100755 --- a/contrib/hooks/setgitperms.perl +++ b/contrib/hooks/setgitperms.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # Copyright (c) 2006 Josh England # diff --git a/contrib/hooks/update-paranoid b/contrib/hooks/update-paranoid index 0092d67b8a..a85d3badd1 100755 --- a/contrib/hooks/update-paranoid +++ b/contrib/hooks/update-paranoid @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use File::Spec; diff --git a/contrib/long-running-filter/example.pl b/contrib/long-running-filter/example.pl index a677569ddd..0ca49e370b 100755 --- a/contrib/long-running-filter/example.pl +++ b/contrib/long-running-filter/example.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # Example implementation for the Git filter protocol version 2 # See Documentation/gitattributes.txt, section "Filter Protocol" diff --git a/contrib/mw-to-git/git-mw.perl b/contrib/mw-to-git/git-mw.perl index eb52a53d32..cb0cd63ea7 100755 --- a/contrib/mw-to-git/git-mw.perl +++ b/contrib/mw-to-git/git-mw.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (C) 2013 # Benoit Person diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl index a5624413dc..9ae596f3b7 100755 --- a/contrib/mw-to-git/git-remote-mediawiki.perl +++ b/contrib/mw-to-git/git-remote-mediawiki.perl @@ -1,4 +1,4 @@ -#! /usr/bin/perl +#!/usr/bin/env perl # Copyright (C) 2011 # Jérémie Nikaes diff --git a/contrib/mw-to-git/t/test-gitmw.pl b/contrib/mw-to-git/t/test-gitmw.pl index c5d687f078..9005837713 100755 --- a/contrib/mw-to-git/t/test-gitmw.pl +++ b/contrib/mw-to-git/t/test-gitmw.pl @@ -1,4 +1,8 @@ -#!/usr/bin/perl -w -s +#!/usr/bin/env perl + +use strict; +use warnings; + # Copyright (C) 2012 # Charles Roussel # Simon Cathebras diff --git a/contrib/stats/mailmap.pl b/contrib/stats/mailmap.pl index 9513f5e35b..469af8240c 100755 --- a/contrib/stats/mailmap.pl +++ b/contrib/stats/mailmap.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use warnings 'all'; use strict; diff --git a/contrib/stats/packinfo.pl b/contrib/stats/packinfo.pl index be188c0f11..51823ac942 100755 --- a/contrib/stats/packinfo.pl +++ b/contrib/stats/packinfo.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # This tool will print vaguely pretty information about a pack. It # expects the output of "git verify-pack -v" as input on stdin. diff --git a/contrib/subtree/t/Makefile b/contrib/subtree/t/Makefile index 093399c788..b22cd62236 100644 --- a/contrib/subtree/t/Makefile +++ b/contrib/subtree/t/Makefile @@ -8,7 +8,7 @@ #GIT_TEST_OPTS=--verbose --debug SHELL_PATH ?= $(SHELL) -PERL_PATH ?= /usr/bin/perl +PERL_PATH ?= /usr/bin/env perl TAR ?= $(TAR) RM ?= rm -f PROVE ?= prove diff --git a/git-archimport.perl b/git-archimport.perl index b7c173c345..3f46e0c1dc 100755 --- a/git-archimport.perl +++ b/git-archimport.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # This tool is copyright (c) 2005, Martin Langhoff. # It is released under the Gnu Public License, version 2. diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl index 289d4bc684..c674c22e4f 100755 --- a/git-cvsexportcommit.perl +++ b/git-cvsexportcommit.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use 5.008; use strict; diff --git a/git-cvsimport.perl b/git-cvsimport.perl index 7bf3c12d67..56011991d6 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # This tool is copyright (c) 2005, Matthias Urlichs. # It is released under the Gnu Public License, version 2. diff --git a/git-cvsserver.perl b/git-cvsserver.perl index 7b757360e2..9388efddf2 100755 --- a/git-cvsserver.perl +++ b/git-cvsserver.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl #### #### This application is a CVS emulation layer for git. diff --git a/git-send-email.perl b/git-send-email.perl index 07f2a0cbea..d532c08439 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # # Copyright 2002,2005 Greg Kroah-Hartman # Copyright 2005 Ryan Anderson diff --git a/git-svn.perl b/git-svn.perl index be987e316f..1ba835613b 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (C) 2006, Eric Wong # License: GPL v2 or later use 5.008; diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index e66eb3d9ba..943099a024 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # gitweb - simple web interface to track changes in git repositories # diff --git a/t/Git-SVN/Utils/can_compress.t b/t/Git-SVN/Utils/can_compress.t index d7b49b8d54..0cdedb25bf 100755 --- a/t/Git-SVN/Utils/can_compress.t +++ b/t/Git-SVN/Utils/can_compress.t @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; diff --git a/t/Git-SVN/Utils/fatal.t b/t/Git-SVN/Utils/fatal.t index 49e1438295..75aaf1633d 100755 --- a/t/Git-SVN/Utils/fatal.t +++ b/t/Git-SVN/Utils/fatal.t @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl use strict; use warnings; diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl index dd8107cd7d..6fbec0162e 100755 --- a/t/check-non-portable-shell.pl +++ b/t/check-non-portable-shell.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Test t0000..t9999.sh for non portable shell scripts # This script can be called with one or more filenames as parameters diff --git a/t/lib-gitweb.sh b/t/lib-gitweb.sh index 1f32ca66ea..882c2e96f1 100644 --- a/t/lib-gitweb.sh +++ b/t/lib-gitweb.sh @@ -7,7 +7,7 @@ gitweb_init () { safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')" cat >gitweb_config.perl <