]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hook: detect & emit two more bugs
authorAdrian Ratiu <adrian.ratiu@collabora.com>
Wed, 25 Mar 2026 19:54:56 +0000 (21:54 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Mar 2026 21:00:46 +0000 (14:00 -0700)
Trigger a bug when an unknown hook type is encountered while
setting up hook execution.

Also issue a bug if a configured hook is enabled without a cmd.

Mostly useful for defensive coding.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
hook.c

diff --git a/hook.c b/hook.c
index 4a0db5cfebbf3d265da7138c174f1e0ce6fce4b9..b0226ed71677a9e5cd7e218246a1280ff95635b9 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -409,7 +409,11 @@ static int pick_next_hook(struct child_process *cp,
        } else if (h->kind == HOOK_CONFIGURED) {
                /* to enable oneliners, let config-specified hooks run in shell. */
                cp->use_shell = true;
+               if (!h->u.configured.command)
+                       BUG("non-disabled HOOK_CONFIGURED hook has no command");
                strvec_push(&cp->args, h->u.configured.command);
+       } else {
+               BUG("unknown hook kind");
        }
 
        if (!cp->args.nr)