git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Hardcoded #!/bin/sh in t5532 causes problems on Solaris

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 12, 2016, 17:12 UTC
Message-ID
<xmqqoa9erbso.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqqvb3mrcgj.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 26 quoted lines
> Jeff King <peff@peff.net> writes:
> ...
>> Looks good and is the minimal change. I kind of wonder if the example
>> would be more clear, though, as just:
>>
>>   write_script .git/hooks/pre-commit <<-\EOF &&
>>   exit 1
>>   EOF
>>   echo whatever >file1 &&
>>   ...
>>
>> I don't think we ever actually need the pre-commit check to pass, as we
>> simply override it with --no-verify. But I dunno. Maybe people find it
>> easier to read with a pseudo-realistic example (it took me a minute to
>> realize the trailing whitespace in the content was important).
>
> I was mostly worried about closing the door for future enhancement
> where there are multiple commits to be replayed, some of which fail
> and others pass the test.  Unconditional "exit 1" would have to be
> reverted when it happens.
>
>> It could also stand to clean up its hook with test_when_finished. The
>> next test resorts to "rm -rf" on the hooks directory at the beginning.
>> Yuck.
>
> Yeah, that may be an accident waiting to happen.
In any case, lest we forget...
-- >8 --
Subject: [PATCH] t3404: use write_script

The test uses hardcoded #!/bin/sh to create a pre-commit hook script. Because the generated script uses $(command substitution), which is not supported by /bin/sh on some platforms (e.g. Solaris), the resulting pre-commit always fails.

Which is not noticeable as the test that uses the hook is about checking the behaviour of the command when the hook fails ;-), but nevertheless it is not testing what we wanted to test.

Use write_script so that the resulting script is run under the same shell our scripted Porcelain commands are run, which must support the necessary $(construct).

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t3404-rebase-interactive.sh | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 544f9ad..d6d65a3 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -555,10 +555,9 @@ test_expect_success 'rebase a detached HEAD' '
 test_expect_success 'rebase a commit violating pre-commit' '
 
 	mkdir -p .git/hooks &&
-	PRE_COMMIT=.git/hooks/pre-commit &&
-	echo "#!/bin/sh" > $PRE_COMMIT &&
-	echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT &&
-	chmod a+x $PRE_COMMIT &&
+	write_script .git/hooks/pre-commit <<-\EOF &&
+	test -z "$(git diff --cached --check)"
+	EOF
 	echo "monde! " >> file1 &&
 	test_tick &&
 	test_must_fail git commit -m doesnt-verify file1 &&
-- 
2.8.1-339-gc925d85
Previous: Junio C HamanoNext: Jeff King
Message 12 of 14 in “Hardcoded #!/bin/sh in t5532 causes problems on Solaris”
  1. Tom G. ChristensenApr 9, 2016
  2. Jeff KingApr 9, 2016
  3. Tom G. ChristensenApr 9, 2016
  4. Jeff KingApr 9, 2016
  5. Junio C HamanoApr 10, 2016
  6. Junio C HamanoApr 10, 2016
  7. Eric SunshineApr 10, 2016
  8. Junio C HamanoApr 11, 2016
  9. Jeff KingApr 11, 2016
  10. Jeff KingApr 11, 2016
  11. Junio C HamanoApr 12, 2016
  12. Junio C HamanoApr 12, 2016
  13. Jeff KingApr 12, 2016
  14. Jeff KingApr 12, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.