diff mbox series

[v2,01/45] completion: fix __git_cmd_idx regression

Message ID 20210618182518.697912-2-felipe.contreras@gmail.com (mailing list archive)
State New, archived
Headers show
Series completion: git-completion 1.3.3 patches | expand

Commit Message

Felipe Contreras June 18, 2021, 6:24 p.m. UTC
The commit 59d85a2a05 (git-completion.bash: use $__git_cmd_idx in more
places, 2021-04-22) caused a regression when using __git_complete and a
command relies on __git_cmd_idx.

We need the function wrapper to define __git_cmd_idx.

If the function wrapper defines __git_cmd_idx, then it's not necessary
for __git_zsh_main to do so.

Reported-by: Harrison McCullough <mccullough.harrison@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 2 +-
 contrib/completion/git-completion.zsh  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Comments

Felipe Contreras June 18, 2021, 7:04 p.m. UTC | #1
Felipe Contreras wrote:
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -3511,7 +3511,7 @@ fi
>  
>  __git_func_wrap ()
>  {
> -	local cur words cword prev
> +	local cur words cword prev __git_cmd_idx=1

I just realized this isn't 100% correct thanks to Fabian Wermelinger.
If we use __git_complete then the index should be 0. The above fixes the
annoying errors, but some commands don't complete correctly (e.g.
git_fetch).

I've sent an updated fix [1].

[1] https://lore.kernel.org/git/20210618185832.700477-1-felipe.contreras@gmail.com/
diff mbox series

Patch

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index b50c5d0ea3..52a2d283cd 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3511,7 +3511,7 @@  fi
 
 __git_func_wrap ()
 {
-	local cur words cword prev
+	local cur words cword prev __git_cmd_idx=1
 	_get_comp_words_by_ref -n =: cur words cword prev
 	$1
 }
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index cac6f61881..02ffeae768 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -251,7 +251,7 @@  __git_zsh_main ()
 		done
 		;;
 	(arg)
-		local command="${words[1]}" __git_dir __git_cmd_idx=1
+		local command="${words[1]}" __git_dir
 
 		if (( $+opt_args[--bare] )); then
 			__git_dir='.'
@@ -271,7 +271,7 @@  __git_zsh_main ()
 _git ()
 {
 	local _ret=1
-	local cur cword prev
+	local cur cword prev __git_cmd_idx=1
 
 	cur=${words[CURRENT]}
 	prev=${words[CURRENT-1]}