From: Jonathan Nieder <jrnieder@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2] t0001: check syntax of sample hooks
Date: Sat, 10 Jul 2010 19:45:19 -0500 [thread overview]
Message-ID: <20100711004518.GA5658@burratino> (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.
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
next reply other threads:[~2010-07-11 0:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-11 0:45 Jonathan Nieder [this message]
2010-07-11 0:53 ` [PATCH v2] t0001: check syntax of sample hooks 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=20100711004518.GA5658@burratino \
--to=jrnieder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).