t0001: check syntax of sample hooks
PATCH 1/1 t0001: check syntax of sample hooks
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.
---
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(-)
t/t0001-init.sh +15 -0
@@ -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 &&
templates/hooks--pre-rebase.sample +3 -0
@@ -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
Signature · 1 line
1.7.1.rc1
Quoted 8 lines · Jonathan Nieder
t/t0001-init.sh +0
-0@@ -141,6 +141,21 @@ test_expect_success 'reinit' ' test_cmp again/empty again/err2 '
t/t0001-init.sh test_expect_success 'reinit' ' · line 153
Quoted 10 lines
t/t0001-init.sh +10
-0+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" ||
"#!/Program Files/bin/shell"???
I think, after observing what this outputs,
$ echo 'a b c' | (read shebang; echo "<$shebang>")
you would need something like this:
shell=$(sed -e '1{
s/^#!//p
q
}' "$i") &&
"$shell" -n "$i"templates/hooks--pre-rebase.sample fi · line 94
Quoted 9 lines
templates/hooks--pre-rebase.sample +1
-0@@ -91,6 +91,7 @@ fi exit 0 ################################################################ +cat <<\EOF
No need to meow here; just say ":" instead.
Quoted 10 lines
templates/hooks--pre-rebase.sample +2
-0This 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". + +EOFSignature · 1 line
1.7.1.rc1
Quoted 1 line · Junio C Hamano
"#!/Program Files/bin/shell"???
“#!/usr/bin/env sh”?
I will think a little more about this and look at what msysgit does.
Quoted 3 lines
Quoted 1 line
+cat <<\EOF
No need to meow here; just say ":" instead.
Makes sense.
Thanks,
Jonathan