Skip to contentSkip to conversation

War on #! lines in shell libraries

PATCH In review Jonathan Nieder 3 participants 13 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

cover War on #! lines in shell libraries

Hi,

This is an old series that I just wanted to flush out of my working directory. It does two things:

On one hand, it replaces the line

	#!/bin/sh

at the start of shell libraries with a simple comment

# Shell library for <etc, explaining how it is used>

to avoid confusing readers into thinking the shell library is going to be run directly with /bin/sh. And on the other hand, it sets the executable bit on actual scripts that are run directly with /bin/sh. (Likewise for some perl scripts, too.)

The heart of the series has been well tested in the context of Debian git for a couple of years. Thanks to list denizens for the improvements last time I brought it up[1]. Hopefully this version is more sensible.

Anyway, hopefully it can provide some amusement.

Thanks,
Jonathan Nieder (9):
mark Windows build scripts executable
mark perl test scripts executable
mark contributed hooks executable
contrib: remove git-p4import
gitk: chmod +x po2msg
git-gui: chmod +x po2msg, windows/git-gui.sh
test: make FILEMODE a lazy prereq
test: replace shebangs with descriptions in shell libraries remove #!interpreter line from shell libraries

[1] http://thread.gmane.org/gmane.comp.version-control.git/192582

 compat/vcbuild/scripts/clink.pl        |   0
 compat/vcbuild/scripts/lib.pl          |   0
 contrib/buildsystems/engine.pl         |   0
 contrib/buildsystems/generate          |   0
 contrib/buildsystems/parse.pl          |   0
 contrib/completion/git-completion.bash |   2 -
 contrib/completion/git-completion.tcsh |   2 -
 contrib/hooks/post-receive-email       |   1 -
 contrib/hooks/pre-auto-gc-battery      |   1 -
 contrib/hooks/setgitperms.perl         |   0
 contrib/hooks/update-paranoid          |   0
 contrib/p4import/README                |   1 -
 contrib/p4import/git-p4import.py       | 365 ---------------------------------
 contrib/p4import/git-p4import.txt      | 167 ---------------
 git-gui/po/po2msg.sh                   |   0
 git-gui/windows/git-gui.sh             |   0
 git-mergetool--lib.sh                  |   3 +-
 git-parse-remote.sh                    |   4 +-
 git-rebase--am.sh                      |   3 +-
 git-rebase--interactive.sh             |   9 +-
 git-rebase--merge.sh                   |   4 +-
 git-sh-i18n.sh                         |   5 +-
 git-sh-setup.sh                        |   9 +-
 gitk-git/po/po2msg.sh                  |   0
 t/Git-SVN/00compile.t                  |   0
 t/Git-SVN/Utils/add_path_to_url.t      |   0
 t/Git-SVN/Utils/can_compress.t         |   0
 t/Git-SVN/Utils/canonicalize_url.t     |   0
 t/Git-SVN/Utils/collapse_dotdot.t      |   0
 t/Git-SVN/Utils/fatal.t                |   0
 t/Git-SVN/Utils/join_paths.t           |   0
 t/gitweb-lib.sh                        |   3 +-
 t/lib-bash.sh                          |   7 +-
 t/lib-cvs.sh                           |   2 +-
 t/lib-diff-alternative.sh              |   3 +-
 t/lib-gettext.sh                       |   3 +-
 t/lib-git-daemon.sh                    |  18 +-
 t/lib-httpd.sh                         |  29 ++-
 t/lib-pack.sh                          |   2 -
 t/lib-pager.sh                         |   2 +-
 t/lib-prereq-FILEMODE.sh               |  11 -
 t/lib-read-tree.sh                     |   2 -
 t/lib-rebase.sh                        |   2 +-
 t/lib-terminal.sh                      |   2 +-
 t/perf/perf-lib.sh                     |   4 +-
 t/t0202/test.pl                        |   0
 t/t3701-add-interactive.sh             |   1 -
 t/t4102-apply-rename.sh                |   1 -
 t/t4120-apply-popt.sh                  |   1 -
 t/t4129-apply-samemode.sh              |   1 -
 t/t6031-merge-recursive.sh             |   1 -
 t/t9150/make-svk-dump                  |   0
 t/t9151/make-svnmerge-dump             |   0
 t/t9200-git-cvsexportcommit.sh         |   1 -
 t/test-lib-functions.sh                |   3 +-
 t/test-lib.sh                          |  12 +-
 56 files changed, 87 insertions(+), 600 deletions(-)
 mode change 100644 => 100755 compat/vcbuild/scripts/clink.pl
 mode change 100644 => 100755 compat/vcbuild/scripts/lib.pl
 mode change 100644 => 100755 contrib/buildsystems/engine.pl
 mode change 100644 => 100755 contrib/buildsystems/generate
 mode change 100644 => 100755 contrib/buildsystems/parse.pl
 mode change 100644 => 100755 contrib/hooks/pre-auto-gc-battery
 mode change 100644 => 100755 contrib/hooks/setgitperms.perl
 mode change 100644 => 100755 contrib/hooks/update-paranoid
 delete mode 100644 contrib/p4import/README
 delete mode 100644 contrib/p4import/git-p4import.py
 delete mode 100644 contrib/p4import/git-p4import.txt
 mode change 100644 => 100755 git-gui/po/po2msg.sh
 mode change 100644 => 100755 git-gui/windows/git-gui.sh
 mode change 100644 => 100755 gitk-git/po/po2msg.sh
 mode change 100644 => 100755 t/Git-SVN/00compile.t
 mode change 100644 => 100755 t/Git-SVN/Utils/add_path_to_url.t
 mode change 100644 => 100755 t/Git-SVN/Utils/can_compress.t
 mode change 100644 => 100755 t/Git-SVN/Utils/canonicalize_url.t
 mode change 100644 => 100755 t/Git-SVN/Utils/collapse_dotdot.t
 mode change 100644 => 100755 t/Git-SVN/Utils/fatal.t
 mode change 100644 => 100755 t/Git-SVN/Utils/join_paths.t
 delete mode 100644 t/lib-prereq-FILEMODE.sh
 mode change 100644 => 100755 t/t0202/test.pl
 mode change 100644 => 100755 t/t9150/make-svk-dump
 mode change 100644 => 100755 t/t9151/make-svnmerge-dump
Signature · 1 line
1.8.4.1
#1 lore raw

PATCH 1/9 mark Windows build scripts executable

On Windows the convention is to rely on filename extensions to decide whether a file is executable so Windows users are probably not relying on the executable bit of these scripts, but on other platforms it can be useful documentation.

---
 compat/vcbuild/scripts/clink.pl | 0
 compat/vcbuild/scripts/lib.pl   | 0
 contrib/buildsystems/engine.pl  | 0
 contrib/buildsystems/generate   | 0
 contrib/buildsystems/parse.pl   | 0
 5 files changed, 0 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 compat/vcbuild/scripts/clink.pl
 mode change 100644 => 100755 compat/vcbuild/scripts/lib.pl
 mode change 100644 => 100755 contrib/buildsystems/engine.pl
 mode change 100644 => 100755 contrib/buildsystems/generate
 mode change 100644 => 100755 contrib/buildsystems/parse.pl
compat/vcbuild/scripts/clink.pl +0 -0
old mode 100644
new mode 100755
compat/vcbuild/scripts/lib.pl +0 -0
old mode 100644
new mode 100755
contrib/buildsystems/engine.pl +0 -0
old mode 100644
new mode 100755
contrib/buildsystems/generate +0 -0
old mode 100644
new mode 100755
contrib/buildsystems/parse.pl +0 -0
old mode 100644
new mode 100755
Signature · 1 line
1.8.4.1
#2 lore raw

PATCH 2/9 mark perl test scripts executable

In reply to Jonathan Nieder

These scripts are not run directly as part of a normal build, so no one noticed that they did not have the +x bit. Mark them executable to make it more obvious that they can be run directly (when debugging, for example).

---
 t/Git-SVN/00compile.t              | 0
 t/Git-SVN/Utils/add_path_to_url.t  | 0
 t/Git-SVN/Utils/can_compress.t     | 0
 t/Git-SVN/Utils/canonicalize_url.t | 0
 t/Git-SVN/Utils/collapse_dotdot.t  | 0
 t/Git-SVN/Utils/fatal.t            | 0
 t/Git-SVN/Utils/join_paths.t       | 0
 t/t0202/test.pl                    | 0
 t/t9150/make-svk-dump              | 0
 t/t9151/make-svnmerge-dump         | 0
 10 files changed, 0 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 t/Git-SVN/00compile.t
 mode change 100644 => 100755 t/Git-SVN/Utils/add_path_to_url.t
 mode change 100644 => 100755 t/Git-SVN/Utils/can_compress.t
 mode change 100644 => 100755 t/Git-SVN/Utils/canonicalize_url.t
 mode change 100644 => 100755 t/Git-SVN/Utils/collapse_dotdot.t
 mode change 100644 => 100755 t/Git-SVN/Utils/fatal.t
 mode change 100644 => 100755 t/Git-SVN/Utils/join_paths.t
 mode change 100644 => 100755 t/t0202/test.pl
 mode change 100644 => 100755 t/t9150/make-svk-dump
 mode change 100644 => 100755 t/t9151/make-svnmerge-dump
t/Git-SVN/00compile.t +0 -0
old mode 100644
new mode 100755
t/Git-SVN/Utils/add_path_to_url.t +0 -0
old mode 100644
new mode 100755
t/Git-SVN/Utils/can_compress.t +0 -0
old mode 100644
new mode 100755
t/Git-SVN/Utils/canonicalize_url.t +0 -0
old mode 100644
new mode 100755
t/Git-SVN/Utils/collapse_dotdot.t +0 -0
old mode 100644
new mode 100755
t/Git-SVN/Utils/fatal.t +0 -0
old mode 100644
new mode 100755
t/Git-SVN/Utils/join_paths.t +0 -0
old mode 100644
new mode 100755
t/t0202/test.pl +0 -0
old mode 100644
new mode 100755
t/t9150/make-svk-dump +0 -0
old mode 100644
new mode 100755
t/t9151/make-svnmerge-dump +0 -0
old mode 100644
new mode 100755
Signature · 1 line
1.8.4.1
#3 lore raw

PATCH 3/9 mark contributed hooks executable

In reply to Jonathan Nieder

The docs in contrib/hooks/pre-auto-gc-battery suggest:

For example, if the hook is stored in /usr/share/git-core/contrib/hooks/pre-auto-gc-battery:

chmod a+x pre-auto-gc-battery
cd /path/to/your/repository.git
ln -sf /usr/share/git-core/contrib/hooks/pre-auto-gc-battery \
hooks/pre-auto-gc

Unfortunately on multi-user systems most users do not have write access to /usr. Better to mark the sample hooks executable in the first place so users do not have to tweak their permissions to use them by symlinking into .git/hooks/.

---
 contrib/hooks/post-receive-email  | 1 -
 contrib/hooks/pre-auto-gc-battery | 1 -
 contrib/hooks/setgitperms.perl    | 0
 contrib/hooks/update-paranoid     | 0
 4 files changed, 2 deletions(-)
 mode change 100644 => 100755 contrib/hooks/pre-auto-gc-battery
 mode change 100644 => 100755 contrib/hooks/setgitperms.perl
 mode change 100644 => 100755 contrib/hooks/update-paranoid
contrib/hooks/post-receive-email +0 -1
index 8ee410f..8747b84 100755
@@ -22,7 +22,6 @@
 # For example, on debian the hook is stored in
 # /usr/share/git-core/contrib/hooks/post-receive-email:
 #
-#  chmod a+x post-receive-email
 #  cd /path/to/your/repository.git
 #  ln -sf /usr/share/git-core/contrib/hooks/post-receive-email hooks/post-receive
 #
contrib/hooks/pre-auto-gc-battery +0 -1
old mode 100644
new mode 100755
index 1f914c9..9d0c2d1
@@ -13,7 +13,6 @@
 # For example, if the hook is stored in
 # /usr/share/git-core/contrib/hooks/pre-auto-gc-battery:
 #
-# chmod a+x pre-auto-gc-battery
 # cd /path/to/your/repository.git
 # ln -sf /usr/share/git-core/contrib/hooks/pre-auto-gc-battery \
 #	hooks/pre-auto-gc
contrib/hooks/setgitperms.perl +0 -0
old mode 100644
new mode 100755
contrib/hooks/update-paranoid +0 -0
old mode 100644
new mode 100755
Signature · 1 line
1.8.4.1
#4 lore raw

PATCH 4/9 contrib: remove git-p4import

In reply to Jonathan Nieder

The git p4import documentation has suggested git p4 as a better alternative for more than 6 years. (According to the mailing list discussion when it was moved to contrib/, git-p4import has serious bugs --- e.g., its incremental mode just doesn't work.) Since then, git p4 has been actively developed and was promoted to a standard git command alongside git svn.

Searches on google.com/trends and stackoverflow suggest that no one is looking for git-p4import any more. Remove it.

Noticed while considering marking the contrib/p4import/git-p4import.py script executable as part of a wider sweep.

---
Following up on
http://thread.gmane.org/gmane.comp.version-control.git/52580

 contrib/p4import/README           |   1 -
 contrib/p4import/git-p4import.py  | 365 --------------------------------------
 contrib/p4import/git-p4import.txt | 167 -----------------
 3 files changed, 533 deletions(-)
 delete mode 100644 contrib/p4import/README
 delete mode 100644 contrib/p4import/git-p4import.py
 delete mode 100644 contrib/p4import/git-p4import.txt
contrib/p4import/README deleted +0 -1
deleted file mode 100644
index b9892b6..0000000
@@ -1 +0,0 @@
-Please see contrib/fast-import/git-p4 for a better Perforce importer.
contrib/p4import/git-p4import.py deleted +0 -365

365 lines not on this page · raw message

contrib/p4import/git-p4import.txt deleted +0 -167

167 lines not on this page · raw message

Signature · 1 line
1.8.4.1
Acked-by on v1 4/9
#5 lore raw

Re: [PATCH 4/9] contrib: remove git-p4import

[email protected] wrote on Mon, 25 Nov 2013 12:58 -0800:

Quoted 7 lines

The git p4import documentation has suggested git p4 as a better alternative for more than 6 years. (According to the mailing list discussion when it was moved to contrib/, git-p4import has serious bugs --- e.g., its incremental mode just doesn't work.) Since then, git p4 has been actively developed and was promoted to a standard git command alongside git svn.

Quoted 5 lines

Searches on google.com/trends and stackoverflow suggest that no one is looking for git-p4import any more. Remove it.

Noticed while considering marking the contrib/p4import/git-p4import.py script executable as part of a wider sweep.

I haven't seen git-p4import mentioned for the last 6 years either. Thanks,

#6 lore raw

PATCH 5/9 gitk: chmod +x po2msg

In reply to Jonathan Nieder

The Makefile only runs it using tclsh, but because the fallback po2msg script has the usual tcl preamble starting with #!/bin/sh it can also be run directly.

---
 po/po2msg.sh | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 po/po2msg.sh
po/po2msg.sh +0 -0
old mode 100644
new mode 100755
Signature · 1 line
1.8.4.1
#7 lore raw

PATCH 6/9 git-gui: chmod +x po2msg, windows/git-gui.sh

In reply to Jonathan Nieder

The Makefile only runs po/po2msg.sh using tclsh, but because the script has the usual tcl preamble starting with #!/bin/sh it can also be run directly.

The Windows git-gui wrapper is usable in-place for the same reason.

---
 po/po2msg.sh       | 0
 windows/git-gui.sh | 0
 2 files changed, 0 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 po/po2msg.sh
 mode change 100644 => 100755 windows/git-gui.sh
po/po2msg.sh +0 -0
old mode 100644
new mode 100755
windows/git-gui.sh +0 -0
old mode 100644
new mode 100755
Signature · 1 line
1.8.4.1
#8 lore raw

PATCH 7/9 test: make FILEMODE a lazy prereq

In reply to Jonathan Nieder

This way, test authors don't need to remember to source lib-prereq-FILEMODE.sh before using the FILEMODE prereq to guard tests that rely on the executable bit being honored when checking out files.

---
 t/lib-prereq-FILEMODE.sh       | 11 -----------
 t/t3701-add-interactive.sh     |  1 -
 t/t4102-apply-rename.sh        |  1 -
 t/t4120-apply-popt.sh          |  1 -
 t/t4129-apply-samemode.sh      |  1 -
 t/t6031-merge-recursive.sh     |  1 -
 t/t9200-git-cvsexportcommit.sh |  1 -
 t/test-lib.sh                  |  4 ++++
 8 files changed, 4 insertions(+), 17 deletions(-)
 delete mode 100644 t/lib-prereq-FILEMODE.sh
t/lib-prereq-FILEMODE.sh deleted +0 -11
deleted file mode 100644
index bce5a4c..0000000
@@ -1,11 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
-#
-
-if test "$(git config --bool core.filemode)" = false
-then
-	say 'filemode disabled on the filesystem'
-else
-	test_set_prereq FILEMODE
-fi
t/t3701-add-interactive.sh +0 -1
index 9dc91d0..24ddd8a 100755
@@ -2,7 +2,6 @@
 
 test_description='add -i basic tests'
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 if ! test_have_prereq PERL
 then
t/t4102-apply-rename.sh +0 -1
index e3ea3d5..49e2d6c 100755
@@ -7,7 +7,6 @@ test_description='git apply handling copy/rename patch.
 
 '
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 # setup
 
t/t4120-apply-popt.sh +0 -1
index c5fecdf..497b628 100755
@@ -6,7 +6,6 @@
 test_description='git apply -p handling.'
 
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 test_expect_success setup '
 	mkdir sub &&
t/t4129-apply-samemode.sh +0 -1
index 0d36ebd..c268298 100755
@@ -3,7 +3,6 @@
 test_description='applying patch with mode bits'
 
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 test_expect_success setup '
 	echo original >file &&
t/t6031-merge-recursive.sh +0 -1
index 1cd649e..a953f1b 100755
@@ -2,7 +2,6 @@
 
 test_description='merge-recursive: handle file mode'
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 test_expect_success 'mode change in one branch: keep changed version' '
 	: >file1 &&
t/t9200-git-cvsexportcommit.sh +0 -1
index 3fb3368..812c9cd 100755
@@ -5,7 +5,6 @@
 test_description='Test export of commits to CVS'
 
 . ./test-lib.sh
-. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
 
 if ! test_have_prereq PERL; then
 	skip_all='skipping git cvsexportcommit tests, perl not available'
t/test-lib.sh +4 -0
index b25249e..5968157 100644
@@ -830,6 +830,10 @@ test_lazy_prereq SYMLINKS '
 	ln -s x y && test -h y
 '
 
+test_lazy_prereq FILEMODE '
+	test "$(git config --bool core.filemode)" = true
+'
+
 test_lazy_prereq CASE_INSENSITIVE_FS '
 	echo good >CamelCase &&
 	echo bad >camelcase &&
Signature · 1 line
1.8.4.1
#9 lore raw

PATCH 8/9 test: replace shebangs with descriptions in shell libraries

In reply to Jonathan Nieder

A #! line in these files is misleading, since these scriptlets are meant to be sourced with '.' (using whatever shell sources them) instead of run directly using the interpreter named on the #! line.

Removing the #! line shouldn't hurt syntax highlighting since these files have filenames ending with '.sh'. For documentation, add a brief description of how the files are meant to be used in place of the shebang line.

---
 t/gitweb-lib.sh           |  3 ++-
 t/lib-bash.sh             |  7 +++----
 t/lib-cvs.sh              |  2 +-
 t/lib-diff-alternative.sh |  3 ++-
 t/lib-gettext.sh          |  3 ++-
 t/lib-git-daemon.sh       | 18 +++++++++++++++++-
 t/lib-httpd.sh            | 29 ++++++++++++++++++++++++++++-
 t/lib-pack.sh             |  2 --
 t/lib-pager.sh            |  2 +-
 t/lib-read-tree.sh        |  2 --
 t/lib-rebase.sh           |  2 +-
 t/lib-terminal.sh         |  2 +-
 t/perf/perf-lib.sh        |  4 +++-
 t/test-lib-functions.sh   |  3 ++-
 t/test-lib.sh             |  2 +-
 15 files changed, 64 insertions(+), 20 deletions(-)
t/gitweb-lib.sh +2 -1
index 8cf909a..d5dab5a 100644
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Initialization and helpers for Gitweb tests, which source this
+# shell library instead of test-lib.sh.
 #
 # Copyright (c) 2007 Jakub Narebski
 #
t/lib-bash.sh +3 -4
index 11397f7..10b76df 100644
@@ -1,7 +1,6 @@
-#!/bin/sh
-#
-# Ensures that tests are run under Bash; primarily intended for running tests
-# of the completion script.
+# Shell library sourced instead of ./test-lib.sh by tests that need
+# to run under Bash; primary intended for tests of the completion
+# script.
 
 if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
 	# we are in full-on bash mode
t/lib-cvs.sh +1 -1
index 44263ad..5076718 100644
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Shell library sourced instead of ./test-lib.sh by cvsimport tests.
 
 . ./test-lib.sh
 
t/lib-diff-alternative.sh +2 -1
index 75ffd91..8b4dbf2 100644
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Helpers shared by the test scripts for diff algorithms (patience,
+# histogram, etc).
 
 test_diff_frobnitz() {
 	cat >file1 <<\EOF
t/lib-gettext.sh +2 -1
index ae8883a..eec757f 100644
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Initialization and Icelandic locale for basic git i18n tests,
+# which source this scriptlet instead of ./test-lib.sh.
 #
 # Copyright (c) 2010 Ævar Arnfjörð Bjarmason
 #
t/lib-git-daemon.sh +17 -1
index 87f0ad8..394b06b 100644
@@ -1,4 +1,20 @@
-#!/bin/sh
+# Shell library to run git-daemon in tests.  Ends the test early if
+# GIT_TEST_GIT_DAEMON is not set.
+#
+# Usage:
+#
+#	. ./test-lib.sh
+#	. "$TEST_DIRECTORY"/lib-git-daemon.sh
+#	start_git_daemon
+#
+#	test_expect_success '...' '
+#		...
+#	'
+#
+#	test_expect_success ...
+#
+#	stop_git_daemon
+#	test_done
 
 if test -z "$GIT_TEST_GIT_DAEMON"
 then
t/lib-httpd.sh +28 -1
index ad8f1ef..c470784 100644
@@ -1,4 +1,31 @@
-#!/bin/sh
+# Shell library to run an HTTP server for use in tests.
+# Ends the test early if httpd tests should not be run,
+# for example because the user has not enabled them.
+#
+# Usage:
+#
+#	. ./test-lib.sh
+#	. "$TEST_DIRECTORY"/lib-httpd.sh
+#	start_httpd
+#
+#	test_expect_success '...' '
+#		...
+#	'
+#
+#	test_expect_success ...
+#
+#	stop_httpd
+#	test_done
+#
+# Can be configured using the following variables.
+#
+#    GIT_TEST_HTTPD              enable HTTPD tests
+#    LIB_HTTPD_PATH              web server path
+#    LIB_HTTPD_MODULE_PATH       web server modules path
+#    LIB_HTTPD_PORT              listening port
+#    LIB_HTTPD_DAV               enable DAV
+#    LIB_HTTPD_SVN               enable SVN
+#    LIB_HTTPD_SSL               enable SSL
 #
 # Copyright (c) 2008 Clemens Buchacher <[email protected]>
 #
t/lib-pack.sh +0 -2
index b96e125..7509846 100644
@@ -1,5 +1,3 @@
-#!/bin/sh
-#
 # Support routines for hand-crafting weird or malicious packs.
 #
 # You can make a complete pack like:
t/lib-pager.sh +1 -1
index ba03eab..3aa7a3f 100644
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Helpers for tests of git's choice of pager.
 
 test_expect_success 'determine default pager' '
 	test_might_fail git config --unset core.pager &&
t/lib-read-tree.sh +0 -2
index abc2c6f..6442ae3 100644
@@ -1,5 +1,3 @@
-#!/bin/sh
-#
 # Helper functions to check if read-tree would succeed/fail as expected with
 # and without the dry-run option. They also test that the dry-run does not
 # write the index and that together with -u it doesn't touch the work tree.
t/lib-rebase.sh +1 -1
index 8ff87fb..6bd2522 100644
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Helper functions used by interactive rebase tests.
 
 # After setting the fake editor with this function, you can
 #
t/lib-terminal.sh +1 -1
index 737df28..9a2dca5 100644
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Helpers for terminal output tests.
 
 test_expect_success PERL 'set up terminal for tests' '
 	# Reading from the pty master seems to get stuck _sometimes_
t/perf/perf-lib.sh +3 -1
index f4eecaa..a8c9574 100644
@@ -1,4 +1,6 @@
-#!/bin/sh
+# Performance testing framework.  Each perf script starts much like
+# a normal test script, except it sources this library instead of
+# test-lib.sh.  See t/perf/README for documentation.
 #
 # Copyright (c) 2011 Thomas Rast
 #
t/test-lib-functions.sh +2 -1
index 2f79146..aeae3ca 100644
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Library of functions shared by all tests scripts, included by
+# test-lib.sh.
 #
 # Copyright (c) 2005 Junio C Hamano
 #
t/test-lib.sh +1 -1
index 5968157..c306bd0 100644
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Test framework for git.  See t/README for usage.
 #
 # Copyright (c) 2005 Junio C Hamano
 #
Signature · 1 line
1.8.4.1
#10 lore raw

Re: [PATCH 8/9] test: replace shebangs with descriptions in shell libraries

Quoted 16 lines · Jonathan Nieder

A #! line in these files is misleading, since these scriptlets are meant to be sourced with '.' (using whatever shell sources them) instead of run directly using the interpreter named on the #! line.

Removing the #! line shouldn't hurt syntax highlighting since these files have filenames ending with '.sh'. For documentation, add a brief description of how the files are meant to be used in place of the shebang line.

---

t/lib-bash.sh +0 -0
index 11397f7..10b76df 100644

t/lib-bash.sh line 2

Quoted 6 lines
t/lib-bash.sh +2 -4
@@ -1,7 +1,6 @@
-#!/bin/sh
-#
-# Ensures that tests are run under Bash; primarily intended for running tests
-# of the completion script.
+# Shell library sourced instead of ./test-lib.sh by tests that need
+# to run under Bash; primary intended for tests of the completion

s/primary/primarily/

Quoted 4 lines
t/lib-bash.sh +1 -0
+# script.
 
 if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
        # we are in full-on bash mode
#11 lore raw

PATCH v2 8/9 test: replace shebangs with descriptions in shell libraries

A #! line in these files is misleading, since these scriptlets are meant to be sourced with '.' (using whatever shell sources them) instead of run directly using the interpreter named on the #! line.

Removing the #! line shouldn't hurt syntax highlighting since these files have filenames ending with '.sh'. For documentation, add a brief description of how the files are meant to be used in place of the shebang line.

---

Quoted 12 lines · Eric Sunshine

Review line 2

Quoted 8 lines · Jonathan Nieder

+++ b/t/lib-bash.sh

(quoted diff) +2 -4
@@ -1,7 +1,6 @@
-#!/bin/sh
-#
-# Ensures that tests are run under Bash; primarily intended for running tests
-# of the completion script.
+# Shell library sourced instead of ./test-lib.sh by tests that need
+# to run under Bash; primary intended for tests of the completion

s/primary/primarily/

Good eyes. Here's an updated version of the patch with that change.

Thanks,
Jonathan

 t/gitweb-lib.sh           |  3 ++-
 t/lib-bash.sh             |  7 +++----
 t/lib-cvs.sh              |  2 +-
 t/lib-diff-alternative.sh |  3 ++-
 t/lib-gettext.sh          |  3 ++-
 t/lib-git-daemon.sh       | 18 +++++++++++++++++-
 t/lib-httpd.sh            | 29 ++++++++++++++++++++++++++++-
 t/lib-pack.sh             |  2 --
 t/lib-pager.sh            |  2 +-
 t/lib-read-tree.sh        |  2 --
 t/lib-rebase.sh           |  2 +-
 t/lib-terminal.sh         |  2 +-
 t/perf/perf-lib.sh        |  4 +++-
 t/test-lib-functions.sh   |  3 ++-
 t/test-lib.sh             |  2 +-
 15 files changed, 64 insertions(+), 20 deletions(-)
t/gitweb-lib.sh +2 -1
index 8cf909a..d5dab5a 100644
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Initialization and helpers for Gitweb tests, which source this
+# shell library instead of test-lib.sh.
 #
 # Copyright (c) 2007 Jakub Narebski
 #
t/lib-bash.sh +3 -4
index 11397f7..2be955f 100644
@@ -1,7 +1,6 @@
-#!/bin/sh
-#
-# Ensures that tests are run under Bash; primarily intended for running tests
-# of the completion script.
+# Shell library sourced instead of ./test-lib.sh by tests that need
+# to run under Bash; primarily intended for tests of the completion
+# script.
 
 if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then
 	# we are in full-on bash mode
t/lib-cvs.sh +1 -1
index 44263ad..5076718 100644
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Shell library sourced instead of ./test-lib.sh by cvsimport tests.
 
 . ./test-lib.sh
 
t/lib-diff-alternative.sh +2 -1
index 75ffd91..8b4dbf2 100644
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Helpers shared by the test scripts for diff algorithms (patience,
+# histogram, etc).
 
 test_diff_frobnitz() {
 	cat >file1 <<\EOF
t/lib-gettext.sh +2 -1
index ae8883a..eec757f 100644
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Initialization and Icelandic locale for basic git i18n tests,
+# which source this scriptlet instead of ./test-lib.sh.
 #
 # Copyright (c) 2010 Ævar Arnfjörð Bjarmason
 #
t/lib-git-daemon.sh +17 -1
index 87f0ad8..394b06b 100644
@@ -1,4 +1,20 @@
-#!/bin/sh
+# Shell library to run git-daemon in tests.  Ends the test early if
+# GIT_TEST_GIT_DAEMON is not set.
+#
+# Usage:
+#
+#	. ./test-lib.sh
+#	. "$TEST_DIRECTORY"/lib-git-daemon.sh
+#	start_git_daemon
+#
+#	test_expect_success '...' '
+#		...
+#	'
+#
+#	test_expect_success ...
+#
+#	stop_git_daemon
+#	test_done
 
 if test -z "$GIT_TEST_GIT_DAEMON"
 then
t/lib-httpd.sh +28 -1
index ad8f1ef..c470784 100644
@@ -1,4 +1,31 @@
-#!/bin/sh
+# Shell library to run an HTTP server for use in tests.
+# Ends the test early if httpd tests should not be run,
+# for example because the user has not enabled them.
+#
+# Usage:
+#
+#	. ./test-lib.sh
+#	. "$TEST_DIRECTORY"/lib-httpd.sh
+#	start_httpd
+#
+#	test_expect_success '...' '
+#		...
+#	'
+#
+#	test_expect_success ...
+#
+#	stop_httpd
+#	test_done
+#
+# Can be configured using the following variables.
+#
+#    GIT_TEST_HTTPD              enable HTTPD tests
+#    LIB_HTTPD_PATH              web server path
+#    LIB_HTTPD_MODULE_PATH       web server modules path
+#    LIB_HTTPD_PORT              listening port
+#    LIB_HTTPD_DAV               enable DAV
+#    LIB_HTTPD_SVN               enable SVN
+#    LIB_HTTPD_SSL               enable SSL
 #
 # Copyright (c) 2008 Clemens Buchacher <[email protected]>
 #
t/lib-pack.sh +0 -2
index b96e125..7509846 100644
@@ -1,5 +1,3 @@
-#!/bin/sh
-#
 # Support routines for hand-crafting weird or malicious packs.
 #
 # You can make a complete pack like:
t/lib-pager.sh +1 -1
index ba03eab..3aa7a3f 100644
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Helpers for tests of git's choice of pager.
 
 test_expect_success 'determine default pager' '
 	test_might_fail git config --unset core.pager &&
t/lib-read-tree.sh +0 -2
index abc2c6f..6442ae3 100644
@@ -1,5 +1,3 @@
-#!/bin/sh
-#
 # Helper functions to check if read-tree would succeed/fail as expected with
 # and without the dry-run option. They also test that the dry-run does not
 # write the index and that together with -u it doesn't touch the work tree.
t/lib-rebase.sh +1 -1
index 8ff87fb..6bd2522 100644
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Helper functions used by interactive rebase tests.
 
 # After setting the fake editor with this function, you can
 #
t/lib-terminal.sh +1 -1
index 737df28..9a2dca5 100644
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Helpers for terminal output tests.
 
 test_expect_success PERL 'set up terminal for tests' '
 	# Reading from the pty master seems to get stuck _sometimes_
t/perf/perf-lib.sh +3 -1
index f4eecaa..a8c9574 100644
@@ -1,4 +1,6 @@
-#!/bin/sh
+# Performance testing framework.  Each perf script starts much like
+# a normal test script, except it sources this library instead of
+# test-lib.sh.  See t/perf/README for documentation.
 #
 # Copyright (c) 2011 Thomas Rast
 #
t/test-lib-functions.sh +2 -1
index 2f79146..aeae3ca 100644
@@ -1,4 +1,5 @@
-#!/bin/sh
+# Library of functions shared by all tests scripts, included by
+# test-lib.sh.
 #
 # Copyright (c) 2005 Junio C Hamano
 #
t/test-lib.sh +1 -1
index 5968157..c306bd0 100644
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Test framework for git.  See t/README for usage.
 #
 # Copyright (c) 2005 Junio C Hamano
 #
Signature · 1 line
1.8.4.1
#12 lore raw

PATCH 9/9 remove #!interpreter line from shell libraries

In reply to Jonathan Nieder

In a shell snippet meant to be sourced by other shell scripts, an opening #! line does more harm than good.

The harm:

- When the shell library is sourced, the interpreter and options from the #! line are not used. Specifying a particular shell can confuse the reader into thinking it is safe for the shell library to rely on idiosyncrasies of that shell.

- Using #! instead of a plain comment drops a helpful visual clue that this is a shell library and not a self-contained script.

- Tools such as lintian can use a #! line to tell when an installation script has failed by forgetting to set a script executable. This check does not work if shell libraries also start with a #! line.

The good:

- Text editors notice the #! line and use it for syntax highlighting if you try to edit the installed scripts (without ".sh" suffix) in place.

The use of the #! for file type detection is not needed because Git's shell libraries are meant to be edited in source form (with ".sh" suffix). Replace the opening #! lines with comments.

This involves tweaking the test harness's valgrind support to find shell libraries by looking for "# " in the first line instead of "#!" (see v1.7.6-rc3~7, 2011-06-17).

Suggested by Russ Allbery through lintian. Thanks to Jeff King and Clemens Buchacher for further analysis.

Tested by searching for non-executable scripts with #! line:

find . -name .git -prune -o -type f -not -executable | while read file
do
read line <"$file"
case $line in
'#!'*)
echo "$file"
;;
esac
done

The only remaining scripts found are templates for shell scripts (unimplemented.sh, wrap-for-bin.sh) and sample input used in tests (t/t4034/perl/{pre,post}).

---
Thanks for reading.

 contrib/completion/git-completion.bash | 2 --
 contrib/completion/git-completion.tcsh | 2 --
 git-mergetool--lib.sh                  | 3 +--
 git-parse-remote.sh                    | 4 +++-
 git-rebase--am.sh                      | 3 ++-
 git-rebase--interactive.sh             | 9 +++------
 git-rebase--merge.sh                   | 4 +++-
 git-sh-i18n.sh                         | 5 ++---
 git-sh-setup.sh                        | 9 +++------
 t/test-lib.sh                          | 6 ++----
 10 files changed, 19 insertions(+), 28 deletions(-)
contrib/completion/git-completion.bash +0 -2
index dba3c15..be61931 100644
@@ -1,5 +1,3 @@
-#!bash
-#
 # bash/zsh completion support for core Git.
 #
 # Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
contrib/completion/git-completion.tcsh +0 -2
index eaacaf0..6104a42 100644
@@ -1,5 +1,3 @@
-#!tcsh
-#
 # tcsh completion support for core Git.
 #
 # Copyright (C) 2012 Marc Khouzam <[email protected]>
git-mergetool--lib.sh +1 -2
index a280f49..c45a020 100644
@@ -1,5 +1,4 @@
-#!/bin/sh
-# git-mergetool--lib is a library for common merge tool functions
+# git-mergetool--lib is a shell library for common merge tool functions
 
 : ${MERGE_TOOLS_DIR=$(git --exec-path)/mergetools}
 
git-parse-remote.sh +3 -1
index 0e87e09..55fe8d5 100644
@@ -1,4 +1,6 @@
-#!/bin/sh
+# This is a shell library to calculate the remote repository and
+# upstream branch that should be pulled by "git pull" from the current
+# branch.
 
 # git-ls-remote could be called from outside a git managed repository;
 # this would fail in that case and would issue an error message.
git-rebase--am.sh +2 -1
index 34e3102..a4f683a 100644
@@ -1,4 +1,5 @@
-#!/bin/sh
+# This shell script fragment is sourced by git-rebase to implement
+# its default, fast, patch-based, non-interactive mode.
 #
 # Copyright (c) 2010 Junio C Hamano.
 #
git-rebase--interactive.sh +3 -6
index 3c6bed9..43c19e0 100644
@@ -1,11 +1,8 @@
-#!/bin/sh
+# This shell script fragment is sourced by git-rebase to implement
+# its interactive mode.  "git rebase --interactive" makes it easy
+# to fix up commits in the middle of a series and rearrange commits.
 #
 # Copyright (c) 2006 Johannes E. Schindelin
-
-# SHORT DESCRIPTION
-#
-# This script makes it easy to fix up commits in the middle of a series,
-# and rearrange commits.
 #
 # The original idea comes from Eric W. Biederman, in
 # http://article.gmane.org/gmane.comp.version-control.git/22407
git-rebase--merge.sh +3 -1
index 16d1817..e7d96de 100644
@@ -1,4 +1,6 @@
-#!/bin/sh
+# This shell script fragment is sourced by git-rebase to implement
+# its merge-based non-interactive mode that copes well with renamed
+# files.
 #
 # Copyright (c) 2010 Junio C Hamano.
 #
git-sh-i18n.sh +2 -3
index 6a27f68..e6c3116 100644
@@ -1,9 +1,8 @@
-#!/bin/sh
+# This shell library is Git's interface to gettext.sh. See po/README
+# for usage instructions.
 #
 # Copyright (c) 2010 Ævar Arnfjörð Bjarmason
 #
-# This is Git's interface to gettext.sh. See po/README for usage
-# instructions.
 
 # Export the TEXTDOMAIN* data that we need for Git
 TEXTDOMAIN=git
git-sh-setup.sh +3 -6
index ebfe8f7..190a539 100644
@@ -1,9 +1,6 @@
-#!/bin/sh
-#
-# This is included in commands that either have to be run from the toplevel
-# of the repository, or with GIT_DIR environment variable properly.
-# If the GIT_DIR does not look like the right correct git-repository,
-# it dies.
+# This shell scriplet is meant to be included by other shell scripts
+# to set up some variables pointing at the normal git directories and
+# a few helper shell functions.
 
 # Having this variable in your environment would break scripts because
 # you would cause "cd" to be taken to unexpected places.  If you
t/test-lib.sh +2 -4
index c306bd0..c3e07b9 100644
@@ -573,11 +573,9 @@ then
 
 	make_valgrind_symlink () {
 		# handle only executables, unless they are shell libraries that
-		# need to be in the exec-path.  We will just use "#!" as a
-		# guess for a shell-script, since we have no idea what the user
-		# may have configured as the shell path.
+		# need to be in the exec-path.
 		test -x "$1" ||
-		test "#!" = "$(head -c 2 <"$1")" ||
+		test "# " = "$(head -c 2 <"$1")" ||
 		return;
 
 		base=$(basename "$1")
Signature · 1 line
1.8.4.1