git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: git@vger.kernel.org
Cc: Ben Walton <bwalton@artsci.utoronto.ca>
Subject: [PATCH] t0001: check syntax of sample hooks
Date: Mon, 19 Apr 2010 03:41:33 -0500	[thread overview]
Message-ID: <20100419084132.GA25901@progeny.tock> (raw)

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.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
I guess this serves as a test for 502be95 (Make templates honour
SHELL_PATH and PERL_PATH, 2010-03-20).

Actually, my motivation is the second part, since I already run a test
like this locally.  But I thought, while fixing it, why not make it
easy for others to suffer the same problem, too?

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

diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 6757734..3e6e1ed 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -141,6 +141,21 @@ test_expect_success 'reinit' '
 	test_cmp again/empty again/err2
 '
 
+test_expect_success 'sample hooks use acceptable syntax' '
+	mkdir boring &&
+	git init boring &&
+	test -d boring/.git/hooks &&
+	fail=f &&
+	for i in boring/.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..22a9f07 100755
--- a/templates/hooks--pre-rebase.sample
+++ b/templates/hooks--pre-rebase.sample
@@ -91,6 +91,7 @@ fi
 exit 0
 
 ################################################################
+cat <<\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.1.rc1

             reply	other threads:[~2010-04-19  8:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-19  8:41 Jonathan Nieder [this message]
2010-04-19 20:52 ` [PATCH] t0001: check syntax of sample hooks Junio C Hamano
2010-04-19 21:09   ` Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100419084132.GA25901@progeny.tock \
    --to=jrnieder@gmail.com \
    --cc=bwalton@artsci.utoronto.ca \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).