{"thread":{"id":"56264","subject":"[PATCH] completion: avoid config variable name lookup error in nounset mode","startedAt":"2021-08-11T19:16:42Z","lastAt":"2021-08-11T19:40:45Z","messageCount":3,"participants":["Ville Skyttä","Junio C Hamano","Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"432508","messageId":"20210811191637.775693-1-ville.skytta@iki.fi","threadId":"56264","inReplyTo":null,"subject":"[PATCH] completion: avoid config variable name lookup error in nounset mode","fromName":"Ville Skyttä","fromEmail":"ville.skytta@iki.fi","sentAt":"2021-08-11T19:16:37Z","receivedAt":"2021-08-11T19:16:42Z","isPatch":true,"sender":{"key":"ville.skytta@iki.fi","avatar":"https://avatars.githubusercontent.com/u/109152?v=4"},"body":"Config variable name lookup accesses the `sfx` variable before it has\nbeen set, causing an error in \"nounset\" mode. Initialize to an empty\nstring to avoid that.\n\n    $ git config submodule.<Tab>bash: sfx: unbound variable\n\nSigned-off-by: Ville Skyttä <ville.skytta@iki.fi>\n---\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 4bdd27ddc8..ecc9352755 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2631,7 +2631,7 @@ __git_complete_config_variable_value ()\n #                 subsections) instead of the default space.\n __git_complete_config_variable_name ()\n {\n-\tlocal cur_=\"$cur\" sfx\n+\tlocal cur_=\"$cur\" sfx=\"\"\n \n \twhile test $# != 0; do\n \t\tcase \"$1\" in\n-- \n2.25.1\n\n"},{"id":"432509","messageId":"xmqqfsvf93m0.fsf@gitster.g","threadId":"56264","inReplyTo":"20210811191637.775693-1-ville.skytta@iki.fi","subject":"Re: [PATCH] completion: avoid config variable name lookup error in nounset mode","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-08-11T19:35:19Z","receivedAt":"2021-08-11T19:35:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ville Skyttä <ville.skytta@iki.fi> writes:\n\n> Config variable name lookup accesses the `sfx` variable before it has\n\nThe above sounds as if the function always makes an access to an\nuninitialized variable, which puzzled me.  The problem exists only\nwhen called from some callers that do not use the --sfx=X option,\nwhich may be worth mentioning.\n\nI see that, ever since the helper function was introduced at e1e00089\n(completion: complete configuration sections and variable names for\n'git -c', 2019-08-13), it would have upset 'set -u' when the caller\ndoes not pass --sfx=X option, and even in that original version,\nthere was such a caller (the original author Cc'ed).\n\nAnd the fix looks trivially correct.\n\nI'll be busy preparing the -rc2 today, and will not be queuing this\npatch right now, though.  As this is not a recent regression, waiting\nfor the current release cycle to be over and sending a reroll later\nnext week would be greatly appreciated.\n\nThanks.\n\n> been set, causing an error in \"nounset\" mode. Initialize to an empty\n> string to avoid that.\n>\n>     $ git config submodule.<Tab>bash: sfx: unbound variable\n>\n> Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>\n> ---\n>  contrib/completion/git-completion.bash | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 4bdd27ddc8..ecc9352755 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -2631,7 +2631,7 @@ __git_complete_config_variable_value ()\n>  #                 subsections) instead of the default space.\n>  __git_complete_config_variable_name ()\n>  {\n> -\tlocal cur_=\"$cur\" sfx\n> +\tlocal cur_=\"$cur\" sfx=\"\"\n>  \n>  \twhile test $# != 0; do\n>  \t\tcase \"$1\" in\n"},{"id":"432510","messageId":"611427b9cd4f1_19f82088b@natae.notmuch","threadId":"56264","inReplyTo":"20210811191637.775693-1-ville.skytta@iki.fi","subject":"RE: [PATCH] completion: avoid config variable name lookup error in nounset mode","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-08-11T19:40:41Z","receivedAt":"2021-08-11T19:40:45Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Ville Skyttä wrote:\n> Config variable name lookup accesses the `sfx` variable before it has\n> been set, causing an error in \"nounset\" mode. Initialize to an empty\n> string to avoid that.\n> \n>     $ git config submodule.<Tab>bash: sfx: unbound variable\n> \n> Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>\n> ---\n>  contrib/completion/git-completion.bash | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 4bdd27ddc8..ecc9352755 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -2631,7 +2631,7 @@ __git_complete_config_variable_value ()\n>  #                 subsections) instead of the default space.\n>  __git_complete_config_variable_name ()\n>  {\n> -\tlocal cur_=\"$cur\" sfx\n> +\tlocal cur_=\"$cur\" sfx=\"\"\n\nFor what it's worth this would break a fix I've sent several times\nalready [1].\n\nThe proper fix requires changing __gitcomp as well, after that sfx can\nsimply be \" \".\n\nAll the patches that fix all these issues have been sent, and if you\nwant to try them out check git-completion [2].\n\nCheers.\n\n[1] https://lore.kernel.org/git/20210707023146.3132162-5-felipe.contreras@gmail.com/\n[2] https://github.com/felipec/git-completion\n\n-- \nFelipe Contreras"}]}