hook: accept .enabled and .parallel given without a value
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
1 parent
c3764d15e6
commit
3a7784d0d5
2 files changed
+24
-1
No files matched your search
@@ -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. */
|
||||
|
||||
@@ -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" &&
|
||||
|
||||
Reference in new issue
Block a user