Subject: Re: [PATCH v2 2/3] config: values of pathname type can be prefixed with :(optional)

From: Phillip Wood <[email-masked]>
Date: Tue, 30 Sep 2025 16:26:36 +0100

Hi Ben

On 28/09/2025 22:29, D. Ben Knoble wrote:
> From: Junio C Hamano <[email-masked]>
> 
> Sometimes people want to specify additional configuration data
> as "best effort" basis.  Maybe commit.template configuration file points
> at somewhere in ~/template/ but on a particular system, the file may not
> exist and the user may be OK without using the template in such a case.
> 
> When the value given to a configuration variable whose type is
> pathname wants to signal such an optional file, it can be marked by
> prepending ":(optional)" in front of it.  Such a setting that is
> marked optional would avoid getting the command barf for a missing
> file, as an optional configuration setting that names a missing
> file is not even seen.

I think this would be a useful addition, we've had several people 
wanting to make blame.ignoreRevsFile optional and this provides a 
general way to do that.

> --- a/config.c
> +++ b/config.c
> @@ -1279,11 +1279,23 @@ int git_config_string(char **dest, const char *var, const char *value)
>   
>   int git_config_pathname(char **dest, const char *var, const char *value)
>   {
> +	int is_optional;

This could be bool rather than int, the rest of the implementation looks 
good.

> --- a/t/t7500-commit-template-squash-signoff.sh
> +++ b/t/t7500-commit-template-squash-signoff.sh
> @@ -46,6 +46,15 @@ commit_msg_is ()
>   	)
>   '
>   
> +test_expect_success 'nonexistent optional template file in config' '
> +	test_config commit.template ":(optional)$PWD"/notexist &&
> +	(
> +		GIT_EDITOR="echo hello >\"\$1\"" &&

when git runs the editor this will be expanded to

     sh -c 'echo hello >"$1" "$@"' 'echo hello >"$1"' path/to/file

I think it should be

     GIT_EDITOR="echo hello >"

instead
> +		export GIT_EDITOR &&
> +		git commit --allow-empty

Maybe I'm missing something but don't we want to ensure that we have a 
non-empty message here? Also as it is a single command we can avoid the 
subshell with

     GIT_EDITOR="echo hello >" git commit

Thanks

Phillip