Skip to content

Commit 5825304

Browse files
committed
Merge branch 'ab/hooks-regression-fix' into maint
A follow-up fix to a fix for a regression in 2.36. source: <[email protected]> * ab/hooks-regression-fix: hook API: don't segfault on strbuf_addf() to NULL "out"
2 parents ed051d4 + 99ddc24 commit 5825304

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

hook.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ static int pick_next_hook(struct child_process *cp,
6262
strvec_push(&cp->args, hook_path);
6363
strvec_pushv(&cp->args, hook_cb->options->args.v);
6464

65-
/* Provide context for errors if necessary */
66-
*pp_task_cb = (char *)hook_path;
67-
6865
/*
6966
* This pick_next_hook() will be called again, we're only
7067
* running one hook, so indicate that no more work will be
@@ -80,13 +77,9 @@ static int notify_start_failure(struct strbuf *out,
8077
void *pp_task_cp)
8178
{
8279
struct hook_cb_data *hook_cb = pp_cb;
83-
const char *hook_path = pp_task_cp;
8480

8581
hook_cb->rc |= 1;
8682

87-
strbuf_addf(out, _("Couldn't start hook '%s'\n"),
88-
hook_path);
89-
9083
return 1;
9184
}
9285

t/t1800-hook.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,30 @@ test_expect_success TTY 'git commit: stdout and stderr are connected to a TTY' '
151151
test_hook_tty commit -m"B.new"
152152
'
153153

154+
test_expect_success 'git hook run a hook with a bad shebang' '
155+
test_when_finished "rm -rf bad-hooks" &&
156+
mkdir bad-hooks &&
157+
write_script bad-hooks/test-hook "/bad/path/no/spaces" </dev/null &&
158+
159+
# TODO: We should emit the same (or at least a more similar)
160+
# error on Windows and !Windows. See the OS-specific code in
161+
# start_command()
162+
if test_have_prereq !WINDOWS
163+
then
164+
cat >expect <<-\EOF
165+
fatal: cannot run bad-hooks/test-hook: ...
166+
EOF
167+
else
168+
cat >expect <<-\EOF
169+
error: cannot spawn bad-hooks/test-hook: ...
170+
EOF
171+
fi &&
172+
test_expect_code 1 git \
173+
-c core.hooksPath=bad-hooks \
174+
hook run test-hook >out 2>err &&
175+
test_must_be_empty out &&
176+
sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
177+
test_cmp expect actual
178+
'
179+
154180
test_done

0 commit comments

Comments
 (0)