Skip to content

Commit 11d6214

Browse files
jrngitster
authored andcommitted
remove #!interpreter line from shell libraries
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c74c720 commit 11d6214

10 files changed

+19
-28
lines changed

contrib/completion/git-completion.bash

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!bash
2-
#
31
# bash/zsh completion support for core Git.
42
#
53
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>

contrib/completion/git-completion.tcsh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!tcsh
2-
#
31
# tcsh completion support for core Git.
42
#
53
# Copyright (C) 2012 Marc Khouzam <[email protected]>

git-mergetool--lib.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#!/bin/sh
2-
# git-mergetool--lib is a library for common merge tool functions
1+
# git-mergetool--lib is a shell library for common merge tool functions
32

43
: ${MERGE_TOOLS_DIR=$(git --exec-path)/mergetools}
54

git-parse-remote.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#!/bin/sh
1+
# This is a shell library to calculate the remote repository and
2+
# upstream branch that should be pulled by "git pull" from the current
3+
# branch.
24

35
# git-ls-remote could be called from outside a git managed repository;
46
# this would fail in that case and would issue an error message.

git-rebase--am.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/sh
1+
# This shell script fragment is sourced by git-rebase to implement
2+
# its default, fast, patch-based, non-interactive mode.
23
#
34
# Copyright (c) 2010 Junio C Hamano.
45
#

git-rebase--interactive.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#!/bin/sh
1+
# This shell script fragment is sourced by git-rebase to implement
2+
# its interactive mode. "git rebase --interactive" makes it easy
3+
# to fix up commits in the middle of a series and rearrange commits.
24
#
35
# Copyright (c) 2006 Johannes E. Schindelin
4-
5-
# SHORT DESCRIPTION
6-
#
7-
# This script makes it easy to fix up commits in the middle of a series,
8-
# and rearrange commits.
96
#
107
# The original idea comes from Eric W. Biederman, in
118
# http://article.gmane.org/gmane.comp.version-control.git/22407

git-rebase--merge.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#!/bin/sh
1+
# This shell script fragment is sourced by git-rebase to implement
2+
# its merge-based non-interactive mode that copes well with renamed
3+
# files.
24
#
35
# Copyright (c) 2010 Junio C Hamano.
46
#

git-sh-i18n.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#!/bin/sh
1+
# This shell library is Git's interface to gettext.sh. See po/README
2+
# for usage instructions.
23
#
34
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
45
#
5-
# This is Git's interface to gettext.sh. See po/README for usage
6-
# instructions.
76

87
# Export the TEXTDOMAIN* data that we need for Git
98
TEXTDOMAIN=git

git-sh-setup.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
#!/bin/sh
2-
#
3-
# This is included in commands that either have to be run from the toplevel
4-
# of the repository, or with GIT_DIR environment variable properly.
5-
# If the GIT_DIR does not look like the right correct git-repository,
6-
# it dies.
1+
# This shell scriplet is meant to be included by other shell scripts
2+
# to set up some variables pointing at the normal git directories and
3+
# a few helper shell functions.
74

85
# Having this variable in your environment would break scripts because
96
# you would cause "cd" to be taken to unexpected places. If you

t/test-lib.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,9 @@ then
573573

574574
make_valgrind_symlink () {
575575
# handle only executables, unless they are shell libraries that
576-
# need to be in the exec-path. We will just use "#!" as a
577-
# guess for a shell-script, since we have no idea what the user
578-
# may have configured as the shell path.
576+
# need to be in the exec-path.
579577
test -x "$1" ||
580-
test "#!" = "$(head -c 2 <"$1")" ||
578+
test "# " = "$(head -c 2 <"$1")" ||
581579
return;
582580

583581
base=$(basename "$1")

0 commit comments

Comments
 (0)