summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-08-26 20:13:12 +0200
committerJunio C Hamano <gitster@pobox.com>2022-08-26 20:13:12 +0200
commit58253043281202e1c17364382fb4388ae6be53a7 (patch)
tree450467a56882d22278c7316e103ed6718623da50
parentMerge branch 'gc/git-reflog-doc-markup' into maint (diff)
parenthook API: don't segfault on strbuf_addf() to NULL "out" (diff)
downloadgit-58253043281202e1c17364382fb4388ae6be53a7.tar.xz
git-58253043281202e1c17364382fb4388ae6be53a7.zip
Merge branch 'ab/hooks-regression-fix' into maint
A follow-up fix to a fix for a regression in 2.36. source: <patch-1.1-2450e3e65cf-20220805T141402Z-avarab@gmail.com> * ab/hooks-regression-fix: hook API: don't segfault on strbuf_addf() to NULL "out"
-rw-r--r--hook.c7
-rwxr-xr-xt/t1800-hook.sh26
2 files changed, 26 insertions, 7 deletions
diff --git a/hook.c b/hook.c
index d113ee7faa..a493939a4f 100644
--- a/hook.c
+++ b/hook.c
@@ -62,9 +62,6 @@ static int pick_next_hook(struct child_process *cp,
strvec_push(&cp->args, hook_path);
strvec_pushv(&cp->args, hook_cb->options->args.v);
- /* Provide context for errors if necessary */
- *pp_task_cb = (char *)hook_path;
-
/*
* This pick_next_hook() will be called again, we're only
* running one hook, so indicate that no more work will be
@@ -80,13 +77,9 @@ static int notify_start_failure(struct strbuf *out,
void *pp_task_cp)
{
struct hook_cb_data *hook_cb = pp_cb;
- const char *hook_path = pp_task_cp;
hook_cb->rc |= 1;
- strbuf_addf(out, _("Couldn't start hook '%s'\n"),
- hook_path);
-
return 1;
}
diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh
index 210f429887..64096adac7 100755
--- a/t/t1800-hook.sh
+++ b/t/t1800-hook.sh
@@ -151,4 +151,30 @@ test_expect_success TTY 'git commit: stdout and stderr are connected to a TTY' '
test_hook_tty commit -m"B.new"
'
+test_expect_success 'git hook run a hook with a bad shebang' '
+ test_when_finished "rm -rf bad-hooks" &&
+ mkdir bad-hooks &&
+ write_script bad-hooks/test-hook "/bad/path/no/spaces" </dev/null &&
+
+ # TODO: We should emit the same (or at least a more similar)
+ # error on Windows and !Windows. See the OS-specific code in
+ # start_command()
+ if test_have_prereq !WINDOWS
+ then
+ cat >expect <<-\EOF
+ fatal: cannot run bad-hooks/test-hook: ...
+ EOF
+ else
+ cat >expect <<-\EOF
+ error: cannot spawn bad-hooks/test-hook: ...
+ EOF
+ fi &&
+ test_expect_code 1 git \
+ -c core.hooksPath=bad-hooks \
+ hook run test-hook >out 2>err &&
+ test_must_be_empty out &&
+ sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
+ test_cmp expect actual
+'
+
test_done