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

[PATCH v3] contrib/completion: fix zsh completion regression from 59d85a2a05

From
David Aguilar <davvid@gmail.com>
Date
Jun 1, 2021, 16:52 UTC
Message-ID
<20210601165254.18136-1-davvid@gmail.com>

A recent change to make git-completion.bash use $__git_cmd_idx in more places broke a number of completions on zsh because it modified __git_main but did not update __git_zsh_main.

Notably, completions for "add", "branch", "mv" and "push" were broken as a result of this change.

In addition to the undefined variable usage, "git mv <tab>" also prints the following error:

	__git_count_arguments:7: bad math expression:
	operand expected at `"1"'
	_git_mv:[:7: unknown condition: -gt

Remove the quotes around $__git_cmd_idx in __git_count_arguments and set __git_cmd_idx=1 early in __git_zsh_main to fix the regressions from 59d85a2a05.

Add "git" to the "words" array in _git_zsh_main to guarantee that "git" is at least always in the completion list. It may not be completely correct because __git_cmd_idx is not always 1, but it is enough to fix the regression.

This was tested on zsh 5.7.1 (x86_64-apple-darwin19.0).
Helped-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
 contrib/completion/git-completion.bash | 2 +-
 contrib/completion/git-completion.zsh  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 3c5739b905..b50c5d0ea3 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1306,7 +1306,7 @@ __git_count_arguments ()
 	local word i c=0
 
 	# Skip "git" (first argument)
-	for ((i="$__git_cmd_idx"; i < ${#words[@]}; i++)); do
+	for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do
 		word="${words[i]}"
 
 		case "$word" in
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 6c56296997..6405d7ba30 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
+		local command="${words[1]}" __git_dir __git_cmd_idx=1
 
 		if (( $+opt_args[--bare] )); then
 			__git_dir='.'
@@ -261,7 +261,7 @@ __git_zsh_main ()
 
 		(( $+opt_args[--help] )) && command='help'
 
-		words=( ${orig_words[@]} )
+		words=( git ${orig_words[@]} )
 
 		__git_zsh_bash_func $command
 		;;
-- 
2.32.0.rc2.1.gf67de2b3ac
Next: Felipe Contreras
Message 1 of 4 in “contrib/completion: fix zsh completion regression from 59d85a2a05”
  1. contrib/completion: fix zsh completion regression from 59d85a2a05David Aguilar, Jun 1, 2021
  2. Felipe ContrerasJun 1, 2021
  3. David AguilarJun 1, 2021
  4. Felipe ContrerasJun 1, 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.