Skip to content

Commit

Permalink
contrib/completion: fix zsh completion regression from 59d85a2
Browse files Browse the repository at this point in the history
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 59d85a2.

This was tested on zsh 5.7.1 (x86_64-apple-darwin19.0).

Suggested-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
Acked-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
davvid authored and gitster committed Jun 2, 2021
1 parent ed125c4 commit 0b18023
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contrib/completion/git-completion.bash
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contrib/completion/git-completion.zsh
Expand Up @@ -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='.'
Expand Down

0 comments on commit 0b18023

Please sign in to comment.