git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] completion: avoid config variable name lookup error in nounset mode

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 11, 2021, 19:35 UTC
Message-ID
<xmqqfsvf93m0.fsf@gitster.g>
In-Reply-To
<20210811191637.775693-1-ville.skytta@iki.fi>
Ville Skyttä <ville.skytta@iki.fi> writes:
> Config variable name lookup accesses the `sfx` variable before it has

The above sounds as if the function always makes an access to an uninitialized variable, which puzzled me. The problem exists only when called from some callers that do not use the --sfx=X option, which may be worth mentioning.

I see that, ever since the helper function was introduced at e1e00089 (completion: complete configuration sections and variable names for 'git -c', 2019-08-13), it would have upset 'set -u' when the caller does not pass --sfx=X option, and even in that original version, there was such a caller (the original author Cc'ed).

And the fix looks trivially correct.

I'll be busy preparing the -rc2 today, and will not be queuing this patch right now, though. As this is not a recent regression, waiting for the current release cycle to be over and sending a reroll later next week would be greatly appreciated.

Thanks.
Show 23 quoted lines
> been set, causing an error in "nounset" mode. Initialize to an empty
> string to avoid that.
>
>     $ git config submodule.<Tab>bash: sfx: unbound variable
>
> Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
> ---
>  contrib/completion/git-completion.bash | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 4bdd27ddc8..ecc9352755 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -2631,7 +2631,7 @@ __git_complete_config_variable_value ()
>  #                 subsections) instead of the default space.
>  __git_complete_config_variable_name ()
>  {
> -	local cur_="$cur" sfx
> +	local cur_="$cur" sfx=""
>  
>  	while test $# != 0; do
>  		case "$1" in
Previous: Ville SkyttäNext: Felipe Contreras
Message 2 of 3 in “completion: avoid config variable name lookup error in nounset mode”
  1. completion: avoid config variable name lookup error in nounset modeVille Skyttä, Aug 11, 2021
  2. Junio C HamanoAug 11, 2021
  3. Felipe ContrerasAug 11, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.