{"thread":{"id":"23523","subject":"[PATCH] t0001: check syntax of sample hooks","startedAt":"2010-04-19T08:41:33Z","lastAt":"2010-04-19T21:09:50Z","messageCount":3,"participants":["Jonathan Nieder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"139881","messageId":"20100419084132.GA25901@progeny.tock","threadId":"23523","inReplyTo":null,"subject":"[PATCH] t0001: check syntax of sample hooks","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-04-19T08:41:33Z","receivedAt":"2010-04-19T08:41:33Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Make sure that the sample hooks do not use any shell features\nthat the shell used to execute them does not support.\n\nThe documentation at the end of the sample pre-rebase script will\nnever be executed, but \"sh -n\" does not know that.  Convert it to\na HERE document to avoid spurious failures.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nI guess this serves as a test for 502be95 (Make templates honour\nSHELL_PATH and PERL_PATH, 2010-03-20).\n\nActually, my motivation is the second part, since I already run a test\nlike this locally.  But I thought, while fixing it, why not make it\neasy for others to suffer the same problem, too?\n\n t/t0001-init.sh                    |   15 +++++++++++++++\n templates/hooks--pre-rebase.sample |    3 +++\n 2 files changed, 18 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 6757734..3e6e1ed 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -141,6 +141,21 @@ test_expect_success 'reinit' '\n \ttest_cmp again/empty again/err2\n '\n \n+test_expect_success 'sample hooks use acceptable syntax' '\n+\tmkdir boring &&\n+\tgit init boring &&\n+\ttest -d boring/.git/hooks &&\n+\tfail=f &&\n+\tfor i in boring/.git/hooks/*.sample\n+\tdo\n+\t\tread shebang <\"$i\" &&\n+\t\tshell=${shebang#\"#!\"} &&\n+\t\t$shell -n \"$i\" ||\n+\t\tfail=t\n+\tdone &&\n+\ttest \"$fail\" = f\n+'\n+\n test_expect_success 'init with --template' '\n \tmkdir template-source &&\n \techo content >template-source/file &&\ndiff --git a/templates/hooks--pre-rebase.sample b/templates/hooks--pre-rebase.sample\nindex 053f111..22a9f07 100755\n--- a/templates/hooks--pre-rebase.sample\n+++ b/templates/hooks--pre-rebase.sample\n@@ -91,6 +91,7 @@ fi\n exit 0\n \n ################################################################\n+cat <<\\EOF\n \n This sample hook safeguards topic branches that have been\n published from being rewound.\n@@ -167,3 +168,5 @@ To compute (2):\n \tgit rev-list master..topic\n \n \tif this is empty, it is fully merged to \"master\".\n+\n+EOF\n-- \n1.7.1.rc1\n"},{"id":"139928","messageId":"7v633nqi6i.fsf@alter.siamese.dyndns.org","threadId":"23523","inReplyTo":"20100419084132.GA25901@progeny.tock","subject":"Re: [PATCH] t0001: check syntax of sample hooks","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-04-19T20:52:05Z","receivedAt":"2010-04-19T20:52:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Nieder <jrnieder@gmail.com> writes:\n\n> diff --git a/t/t0001-init.sh b/t/t0001-init.sh\n> index 6757734..3e6e1ed 100755\n> --- a/t/t0001-init.sh\n> +++ b/t/t0001-init.sh\n> @@ -141,6 +141,21 @@ test_expect_success 'reinit' '\n>  \ttest_cmp again/empty again/err2\n>  '\n>  \n> +test_expect_success 'sample hooks use acceptable syntax' '\n> +\tmkdir boring &&\n> +\tgit init boring &&\n> +\ttest -d boring/.git/hooks &&\n> +\tfail=f &&\n> +\tfor i in boring/.git/hooks/*.sample\n> +\tdo\n> +\t\tread shebang <\"$i\" &&\n> +\t\tshell=${shebang#\"#!\"} &&\n> +\t\t$shell -n \"$i\" ||\n\n\"#!/Program  Files/bin/shell\"???\n\nI think, after observing what this outputs,\n\n    $ echo 'a  b c' | (read shebang; echo \"<$shebang>\")\n\nyou would need something like this:\n\n\tshell=$(sed -e '1{\n        \ts/^#!//p\n                q\n\t}' \"$i\") &&\n        \"$shell\" -n \"$i\"\n\n> diff --git a/templates/hooks--pre-rebase.sample b/templates/hooks--pre-rebase.sample\n> index 053f111..22a9f07 100755\n> --- a/templates/hooks--pre-rebase.sample\n> +++ b/templates/hooks--pre-rebase.sample\n> @@ -91,6 +91,7 @@ fi\n>  exit 0\n>  \n>  ################################################################\n> +cat <<\\EOF\n\nNo need to meow here; just say \":\" instead.\n\n>  This sample hook safeguards topic branches that have been\n>  published from being rewound.\n> @@ -167,3 +168,5 @@ To compute (2):\n>  \tgit rev-list master..topic\n>  \n>  \tif this is empty, it is fully merged to \"master\".\n> +\n> +EOF\n> -- \n> 1.7.1.rc1\n"},{"id":"139930","messageId":"20100419210950.GA30284@progeny.tock","threadId":"23523","inReplyTo":"7v633nqi6i.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] t0001: check syntax of sample hooks","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-04-19T21:09:50Z","receivedAt":"2010-04-19T21:09:50Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n\n> \"#!/Program  Files/bin/shell\"???\n\n“#!/usr/bin/env sh”?\n\nI will think a little more about this and look at what msysgit does.\n\n>> +cat <<\\EOF\n>\n> No need to meow here; just say \":\" instead.\n\nMakes sense.\n\nThanks,\nJonathan\n"}]}