remove #!interpreter line from shell libraries
authorJonathan Nieder <jrnieder@gmail.com>
Mon, 25 Nov 2013 21:03:52 +0000 (13:03 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 26 Nov 2013 22:23:56 +0000 (14:23 -0800)
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}).

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash
contrib/completion/git-completion.tcsh
git-mergetool--lib.sh
git-parse-remote.sh
git-rebase--am.sh
git-rebase--interactive.sh
git-rebase--merge.sh
git-sh-i18n.sh
git-sh-setup.sh
t/test-lib.sh
index dba3c15700fae1ae8a7a43fd7a6ad7a5b9cbd5dd..be6193162737bec2fc5eac840f75956dae9e00e5 100644 (file)
@@ -1,5 +1,3 @@
-#!bash
-#
 # bash/zsh completion support for core Git.
 #
 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
index eaacaf0c3e5c63967163f863ec8cd37c01f3e996..6104a42a23c4f38848a34c5c212bd7b74de81ab4 100644 (file)
@@ -1,5 +1,3 @@
-#!tcsh
-#
 # tcsh completion support for core Git.
 #
 # Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>
index a280f498179eb2747b32ba5de4111ccb32024848..c45a020301c16614057912b9a26d1466a94654a9 100644 (file)
@@ -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}
 
index 0e87e0915ee16e36385aa4182b3a4271d1308641..55fe8d56c9d5107df0843378ef137d64a48b2980 100644 (file)
@@ -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.
index 34e3102fcbfa64ec101c1fe009c9b14a5976e4c2..a4f683a5d70213151f3713cc0a2d76dfe8293fd3 100644 (file)
@@ -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.
 #
index 3c6bed9a28f7ff96fa619a9acbfc42e4a2c78828..43c19e0829ca727501ba7e4d29c952bc286ccb77 100644 (file)
@@ -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
index 16d18176ece5eecf4a3b0b0a9dea0a5b41ac43d4..e7d96de9adcb133982bbbc6d20cd3b52b3c89214 100644 (file)
@@ -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.
 #
index 6a27f6813624e10b479cae244ad3bb9d2127ff6d..e6c3116e181318fa4c1036b0a26a1d0f24a4ace7 100644 (file)
@@ -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
index ebfe8f7a4d0697422a826d7878855bf9e92d0060..190a5394b9265270faadf578685e9a12b4efebfd 100644 (file)
@@ -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
index c306bd0668f1a58c0986f5fede278447b1ab5b88..c3e07b9e162d6ec6984e07d1ea8061c14658642a 100644 (file)
@@ -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")