Subject: Re: [PATCH v2 09/10] hook: show config scope in git hook list

From: Patrick Steinhardt <[email-masked]>
Date: Tue, 24 Mar 2026 09:37:59 +0100

On Fri, Mar 20, 2026 at 01:52:10PM +0200, Adrian Ratiu wrote:
> diff --git a/Documentation/git-hook.adoc b/Documentation/git-hook.adoc
> index 966388660a..e7d399ae57 100644
> --- a/Documentation/git-hook.adoc
> +++ b/Documentation/git-hook.adoc
> @@ -9,7 +9,7 @@ SYNOPSIS
>  --------
>  [verse]
>  'git hook' run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]
> -'git hook' list [-z] <hook-name>
> +'git hook' list [-z] [--show-scope] <hook-name>
>  
>  DESCRIPTION
>  -----------

Taking a random patch that relates to the git-hook(1) command. I was
wondering whether we want to introduce another change here that will
cause git-hook(1) to bail out when given an unknown hook name.

I know that we explicitly want to allow having custom hook events, but I
would argue that 99% of all invocations will use any of Git's own hook
events. And given that it's really easy to misspell the "prereceive"
hook (which really is "pre-receive") I think it would be nice if we told
the user that it's an unknown hook instead of silently doing nothing.

To cover the original use case we could then add something like
"--allow-unknown-hook-name" to make the caller explicitly accept non-Git
hook events.

> diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh
> index 7eee84fc39..22cca15fda 100755
> --- a/t/t1800-hook.sh
> +++ b/t/t1800-hook.sh
> @@ -408,6 +408,25 @@ test_expect_success 'configured hooks run before hookdir hook' '
>  	test_cmp expected actual
>  '
>  
> +test_expect_success 'git hook list --show-scope shows config scope' '
> +	test_config_global hook.global-hook.command "echo global" &&
> +	test_config_global hook.global-hook.event test-hook --add &&
> +	test_config hook.local-hook.command "echo local" &&
> +	test_config hook.local-hook.event test-hook --add &&
> +
> +	cat >expected <<-\EOF &&
> +	global	global-hook
> +	local	local-hook
> +	EOF
> +	git hook list --show-scope test-hook >actual &&
> +	test_cmp expected actual &&
> +
> +	# without --show-scope the scope must not appear
> +	git hook list test-hook >actual &&
> +	test_grep ! "^global	" actual &&
> +	test_grep ! "^local	" actual
> +'

Do we also want to add a hook discovered via ".git/hooks" to show how it
interacts with the new flag?

Patrick