From 3a7784d0d5467ada7526356673c6653416ace302 Mon Sep 17 00:00:00 2001 From: Thomas Bachem Date: Fri, 23 Oct 2026 13:19:02 +0000 Subject: [PATCH] hook: accept .enabled and .parallel given without a value hook..enabled and hook..parallel are booleans, and git-config(1) documents a boolean without a value as true. But hook_config_lookup_all() rejects every hook.. that has no value, so "git -c hook.lint.parallel hook run pre-commit" fails with "missing value for 'hook.lint.parallel'", and so does a bare "parallel" under [hook "lint"]. The same happens with .enabled, for a hook as well as for an event. Keep rejecting a missing value for the other keys. For .enabled and .parallel, pass it to git_parse_maybe_bool(), which takes it as true. Assisted-by: Claude Fable 5.1 Signed-off-by: Thomas Bachem Signed-off-by: Junio C Hamano --- hook.c | 3 ++- t/t1800-hook.sh | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/hook.c b/hook.c index 5e756cb353..c500fec33e 100644 --- a/hook.c +++ b/hook.c @@ -184,7 +184,8 @@ static int hook_config_lookup_all(const char *key, const char *value, return 0; } - if (!value) + /* .enabled and .parallel are bools, where a missing value means true */ + if (!value && strcmp(subkey, "enabled") && strcmp(subkey, "parallel")) return config_error_nonbool(key); /* Extract name, ensuring it is null-terminated. */ diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 45b99a7f04..fca4cfc712 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -516,6 +516,17 @@ test_expect_success 'globally disabled hook can be re-enabled locally' ' test_cmp expected actual ' +test_expect_success 'hook..enabled without a value means true' ' + test_config_global hook.global-hook.event "test-hook" && + test_config_global hook.global-hook.command "echo \"global-hook ran\"" && + test_config_global hook.global-hook.enabled false && + + echo "global-hook ran" >expected && + git -c hook.global-hook.enabled \ + hook run --allow-unknown-hook-name test-hook 2>actual && + test_cmp expected actual +' + test_expect_success 'configured hooks run before hookdir hook' ' setup_hookdir && test_config hook.first.event "pre-commit" && @@ -1080,6 +1091,17 @@ test_expect_success 'hook.jobs=-1 resolves to online_cpus()' ' test_grep "\"region_enter\".*\"hook\".*\"test-hook\".*\"max:$cpus\"" trace.txt ' +test_expect_success 'hook..parallel without a value means true' ' + test_config hook.hook-1.event test-hook && + test_config hook.hook-1.command "true" && + test_config hook.jobs 2 && + + GIT_TRACE2_EVENT="$(pwd)/trace-parallel.txt" \ + git -c hook.hook-1.parallel \ + hook run --allow-unknown-hook-name test-hook >out 2>err && + test_grep "\"region_enter\".*\"hook\".*\"test-hook\".*\"max:2\"" trace-parallel.txt +' + test_expect_success 'hook..jobs=-1 resolves to online_cpus()' ' test_config hook.hook-1.event test-hook && test_config hook.hook-1.command "true" &&