From: "Thomas Bachem via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Adrian Ratiu <adrian.ratiu@collabora.com>,
Patrick Steinhardt <ps@pks.im>,
Emily Shaffer <nasamuffin@google.com>,
Junio C Hamano <gitster@pobox.com>,
Thomas Bachem <mail@thomasbachem.com>,
Thomas Bachem <mail@thomasbachem.com>
Subject: [PATCH 2/2] hook: accept .enabled and .parallel given without a value
Date: Tue, 20 Oct 2026 18:19:13 +0000 [thread overview]
Message-ID: <3db167c9d1449916d84f82151d68de9460512c3d.1792520353.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2272.git.1792520353.gitgitgadget@gmail.com>
From: Thomas Bachem <mail@thomasbachem.com>
hook.<name>.enabled and hook.<name>.parallel are booleans, and
git-config(1) documents a boolean without a value as true. But
hook_config_lookup_all() rejects every hook.<name>.<key> 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 <mail@thomasbachem.com>
---
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 27cb0eb01c..223c399ef0 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.<friendly-name>.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.<friendly-name>.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.<event>.jobs=-1 resolves to online_cpus()' '
test_config hook.hook-1.event test-hook &&
test_config hook.hook-1.command "true" &&
--
gitgitgadget
prev parent reply other threads:[~2026-10-20 18:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 18:19 [PATCH 0/2] Fix two hook configuration bugs Thomas Bachem via GitGitGadget
2026-10-20 18:19 ` [PATCH 1/2] hook: honor hook.<event>.enabled for the hookdir hook Thomas Bachem via GitGitGadget
2026-10-20 18:46 ` Junio C Hamano
2026-10-20 18:19 ` Thomas Bachem via GitGitGadget [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3db167c9d1449916d84f82151d68de9460512c3d.1792520353.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=adrian.ratiu@collabora.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mail@thomasbachem.com \
--cc=nasamuffin@google.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox