{"thread":{"id":"24361","subject":"[PATCH v2] t0001: check syntax of sample hooks","startedAt":"2010-07-11T00:45:19Z","lastAt":"2010-07-11T00:53:27Z","messageCount":2,"participants":["Jonathan Nieder"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"145287","messageId":"20100711004518.GA5658@burratino","threadId":"24361","inReplyTo":null,"subject":"[PATCH v2] t0001: check syntax of sample hooks","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-07-11T00:45:19Z","receivedAt":"2010-07-11T00:45:19Z","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\nIf the shell specified in a hook’s #! line has a space in it, the\nnew test will break it into words, not even taking quoting into\naccount.  So\n\n #!\"c:/Program Files/bin/bash.exe\"\n\nspecifies a shell named ‘\"c:/Program’ with argument ‘Files/bin/bash.exe\"’.\nOn Unix, that is exactly what exec() would do; on Windows, it is close\nto what the exec() compatibility layer does (actually, the\n‘Files/bin/bash.exe\"’ argument is thrown away by parse_interpreter()).\nTo honor quoting during tests would be to set unreasonable\nexpectations for runtime.\n\nThe user may want to avoid specifying a path to the shell at all, by\nbuilding with\n\n make 'SHELL_PATH=/usr/bin/env bash'\n\nThe rules used in tests and at runtime on Unix allow this.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nAs before[1], the real motivation is the change to appease sh -n for\npre-rebase, since I occasionally run a test like this locally.\nPatch is against master.\n\nThoughts?\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/145281\n\n t/t0001-init.sh                    |   18 ++++++++++++++++++\n templates/hooks--pre-rebase.sample |    3 +++\n 2 files changed, 21 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 7c0a698..8421b86 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -141,6 +141,24 @@ test_expect_success 'reinit' '\n \ttest_cmp again/empty again/err2\n '\n \n+test_expect_success 'sample hooks use acceptable syntax' '\n+\trm -fr hook-syntax &&\n+\tgit init hook-syntax &&\n+\t(\n+\t\tcd hook-syntax &&\n+\t\ttest -d .git/hooks &&\n+\t\tfail=f &&\n+\t\tfor i in .git/hooks/*.sample\n+\t\tdo\n+\t\t\tread shebang <\"$i\" &&\n+\t\t\tshell=${shebang#\"#!\"} &&\n+\t\t\t$shell -n $i ||\n+\t\t\tfail=t\n+\t\tdone &&\n+\t\ttest \"$fail\" = f\n+\t)\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..6182192 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+: <<\\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.2.rc2.532.g65d9b.dirty\n"},{"id":"145288","messageId":"20100711005327.GA5744@burratino","threadId":"24361","inReplyTo":"20100711004518.GA5658@burratino","subject":"Re: [PATCH v2] t0001: check syntax of sample hooks","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-07-11T00:53:27Z","receivedAt":"2010-07-11T00:53:27Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jonathan Nieder wrote:\n\n> +++ b/t/t0001-init.sh\n> @@ -141,6 +141,24 @@ test_expect_success 'reinit' '\n>  \ttest_cmp again/empty again/err2\n>  '\n>  \n> +test_expect_success 'sample hooks use acceptable syntax' '\n> +\trm -fr hook-syntax &&\n> +\tgit init hook-syntax &&\n> +\t(\n> +\t\tcd hook-syntax &&\n> +\t\ttest -d .git/hooks &&\n> +\t\tfail=f &&\n> +\t\tfor i in .git/hooks/*.sample\n> +\t\tdo\n> +\t\t\tread shebang <\"$i\" &&\n\nThis should use ‘read -r’, for the sake of #!c:\\Users\\Xyzzy\\bin\\bash.exe\n\n*sigh*\nJonathan\n"}]}