threads / patch / 55504

patchcompletion: avoid aliased command lookup error in nounset mode

Subject: [PATCH] completion: avoid aliased command lookup error in nounset mode

## tl;dr

2 messages between Apr 16, 2021 and Apr 16, 2021. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Ville Skyttä· Apr 16, 2021, 19:19 UTC · lore

Aliased command lookup accesses the `list` variable before it has been set, causing an error in "nounset" mode. Initialize to an empty string to avoid that.

    $ git nonexistent-command <Tab>bash: list: unbound variable
Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
---
 contrib/completion/git-completion.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to contrib/completion/git-completion.bash +1 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index dfa735ea62..49e76e9d08 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1129,7 +1129,7 @@ __git_pretty_aliases ()
 # __git_aliased_command requires 1 argument
 __git_aliased_command ()
 {
-	local cur=$1 last list word cmdline
+	local cur=$1 last list= word cmdline
 
 	while [[ -n "$cur" ]]; do
 		if [[ "$list" == *" $cur "* ]]; then
-- 
2.25.1
Junio C Hamano· Apr 16, 2021, 20:40 UTC · re: Ville Skyttä · lore

Re: [PATCH] completion: avoid aliased command lookup error in nounset mode

Ville Skyttä <ville.skytta@iki.fi> writes:
Show 10 quoted lines
> Aliased command lookup accesses the `list` variable before it has been
> set, causing an error in "nounset" mode. Initialize to an empty string
> to avoid that.
>
>     $ git nonexistent-command <Tab>bash: list: unbound variable
>
> Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
> ---
>  contrib/completion/git-completion.bash | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
Thanks, will queue.
Show 13 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index dfa735ea62..49e76e9d08 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1129,7 +1129,7 @@ __git_pretty_aliases ()
>  # __git_aliased_command requires 1 argument
>  __git_aliased_command ()
>  {
> -	local cur=$1 last list word cmdline
> +	local cur=$1 last list= word cmdline
>  
>  	while [[ -n "$cur" ]]; do
>  		if [[ "$list" == *" $cur "* ]]; then

← back to recent threads