git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v2] t0001: check syntax of sample hooks
@ 2010-07-11  0:45 Jonathan Nieder
  2010-07-11  0:53 ` Jonathan Nieder
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Nieder @ 2010-07-11  0:45 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano

Make sure that the sample hooks do not use any shell features
that the shell used to execute them does not support.

The documentation at the end of the sample pre-rebase script will
never be executed, but "sh -n" does not know that.  Convert it to
a HERE document to avoid spurious failures.

If the shell specified in a hook’s #! line has a space in it, the
new test will break it into words, not even taking quoting into
account.  So

 #!"c:/Program Files/bin/bash.exe"

specifies a shell named ‘"c:/Program’ with argument ‘Files/bin/bash.exe"’.
On Unix, that is exactly what exec() would do; on Windows, it is close
to what the exec() compatibility layer does (actually, the
‘Files/bin/bash.exe"’ argument is thrown away by parse_interpreter()).
To honor quoting during tests would be to set unreasonable
expectations for runtime.

The user may want to avoid specifying a path to the shell at all, by
building with

 make 'SHELL_PATH=/usr/bin/env bash'

The rules used in tests and at runtime on Unix allow this.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
As before[1], the real motivation is the change to appease sh -n for
pre-rebase, since I occasionally run a test like this locally.
Patch is against master.

Thoughts?

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

 t/t0001-init.sh                    |   18 ++++++++++++++++++
 templates/hooks--pre-rebase.sample |    3 +++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 7c0a698..8421b86 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -141,6 +141,24 @@ test_expect_success 'reinit' '
 	test_cmp again/empty again/err2
 '
 
+test_expect_success 'sample hooks use acceptable syntax' '
+	rm -fr hook-syntax &&
+	git init hook-syntax &&
+	(
+		cd hook-syntax &&
+		test -d .git/hooks &&
+		fail=f &&
+		for i in .git/hooks/*.sample
+		do
+			read shebang <"$i" &&
+			shell=${shebang#"#!"} &&
+			$shell -n $i ||
+			fail=t
+		done &&
+		test "$fail" = f
+	)
+'
+
 test_expect_success 'init with --template' '
 	mkdir template-source &&
 	echo content >template-source/file &&
diff --git a/templates/hooks--pre-rebase.sample b/templates/hooks--pre-rebase.sample
index 053f111..6182192 100755
--- a/templates/hooks--pre-rebase.sample
+++ b/templates/hooks--pre-rebase.sample
@@ -91,6 +91,7 @@ fi
 exit 0
 
 ################################################################
+: <<\EOF
 
 This sample hook safeguards topic branches that have been
 published from being rewound.
@@ -167,3 +168,5 @@ To compute (2):
 	git rev-list master..topic
 
 	if this is empty, it is fully merged to "master".
+
+EOF
-- 
1.7.2.rc2.532.g65d9b.dirty

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] t0001: check syntax of sample hooks
  2010-07-11  0:45 [PATCH v2] t0001: check syntax of sample hooks Jonathan Nieder
@ 2010-07-11  0:53 ` Jonathan Nieder
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Nieder @ 2010-07-11  0:53 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano

Jonathan Nieder wrote:

> +++ b/t/t0001-init.sh
> @@ -141,6 +141,24 @@ test_expect_success 'reinit' '
>  	test_cmp again/empty again/err2
>  '
>  
> +test_expect_success 'sample hooks use acceptable syntax' '
> +	rm -fr hook-syntax &&
> +	git init hook-syntax &&
> +	(
> +		cd hook-syntax &&
> +		test -d .git/hooks &&
> +		fail=f &&
> +		for i in .git/hooks/*.sample
> +		do
> +			read shebang <"$i" &&

This should use ‘read -r’, for the sake of #!c:\Users\Xyzzy\bin\bash.exe

*sigh*
Jonathan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-07-11  0:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-11  0:45 [PATCH v2] t0001: check syntax of sample hooks Jonathan Nieder
2010-07-11  0:53 ` Jonathan Nieder

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).