git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Make templates honour SHELL_PATH and PERL_PATH

From
Ben Walton <bwalton@artsci.utoronto.ca>
Date
Mar 20, 2010, 14:48 UTC
Message-ID
<1269096489-12750-2-git-send-email-bwalton@artsci.utoronto.ca>
In-Reply-To
<1269096489-12750-1-git-send-email-bwalton@artsci.utoronto.ca>

The hook script templates were hard coded to use /bin/sh and perl. This patch ensures that they use the same tools specified for the rest of the suite.

The impetus for the change was noticing that, as shipped, some of the hooks used shell constructs that wouldn't work under Solaris' /bin/sh (eg: $(cmd...) substitutions).

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
---
 Makefile                                   |    2 +-
 templates/Makefile                         |   17 +++++++++++++++--
 templates/hooks--pre-rebase.sample         |    2 +-
 templates/hooks--prepare-commit-msg.sample |    4 ++--
 4 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
index 7c616f8..86638de 100644
--- a/Makefile
+++ b/Makefile
@@ -1469,7 +1469,7 @@ endif
 ifndef NO_PYTHON
 	$(QUIET_SUBDIR0)git_remote_helpers $(QUIET_SUBDIR1) PYTHON_PATH='$(PYTHON_PATH_SQ)' prefix='$(prefix_SQ)' all
 endif
-	$(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1)
+	$(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1) SHELL_PATH='$(SHELL_PATH_SQ)' PERL_PATH='$(PERL_PATH_SQ)'
 
 please_set_SHELL_PATH_to_a_more_modern_shell:
 	@$$(:)
diff --git a/templates/Makefile b/templates/Makefile
index 408f013..d22a71a 100644
--- a/templates/Makefile
+++ b/templates/Makefile
@@ -11,6 +11,16 @@ prefix ?= $(HOME)
 template_instdir ?= $(prefix)/share/git-core/templates
 # DESTDIR=
 
+ifndef SHELL_PATH
+	SHELL_PATH = /bin/sh
+endif
+ifndef PERL_PATH
+	PERL_PATH = perl
+endif
+
+SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
+PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
+
 # Shell quote (do not use $(call) to accommodate ancient setups);
 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
 template_instdir_SQ = $(subst ','\'',$(template_instdir))
@@ -33,8 +43,11 @@ boilerplates.made : $(bpsrc)
 		case "$$boilerplate" in \
 		*--) continue;; \
 		esac && \
-		cp $$boilerplate blt/$$dst && \
-		if test -x "blt/$$dst"; then rx=rx; else rx=r; fi && \
+		sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
+		    -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
+		    -e 's|@PERL_PATH@|$(PERL_PATH_SQ)|g' $$boilerplate > \
+			blt/$$dst && \
+		if test -x "$$boilerplate"; then rx=rx; else rx=r; fi && \
 		chmod a+$$rx "blt/$$dst" || exit; \
 	done && \
 	date >$@
diff --git a/templates/hooks--pre-rebase.sample b/templates/hooks--pre-rebase.sample
index be1b06e..ab1c4c8 100755
--- a/templates/hooks--pre-rebase.sample
+++ b/templates/hooks--pre-rebase.sample
@@ -65,7 +65,7 @@ then
 	fi
 else
 	not_in_next=`git-rev-list --pretty=oneline ^${publish} "$topic"`
-	perl -e '
+	@PERL_PATH@ -e '
 		my $topic = $ARGV[0];
 		my $msg = "* $topic has commits already merged to public branch:\n";
 		my (%not_in_next) = map {
diff --git a/templates/hooks--prepare-commit-msg.sample b/templates/hooks--prepare-commit-msg.sample
index 3652424..e8d1754 100755
--- a/templates/hooks--prepare-commit-msg.sample
+++ b/templates/hooks--prepare-commit-msg.sample
@@ -22,10 +22,10 @@
 
 case "$2,$3" in
   merge,)
-    perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
+    @PERL_PATH@ -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
 
 # ,|template,)
-#   perl -i.bak -pe '
+#   @PERL_PATH@ -i.bak -pe '
 #      print "\n" . `git diff --cached --name-status -r`
 #	 if /^#/ && $first++ == 0' "$1" ;;
 
-- 
1.7.0
Previous: Ben WaltonNext: Ben Walton
Message 2 of 3 in “Template cleanups”
  1. 0/2 Template cleanupsBen Walton, Mar 20, 2010
  2. 1/2 Make templates honour SHELL_PATH and PERL_PATHBen Walton, Mar 20, 2010
  3. 2/2 Modernize git calling conventions in hook templatesBen Walton, Mar 20, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.