git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v4] contrib/completion: fix zsh completion regression from 59d85a2a05
@ 2021-06-01 20:52 David Aguilar
  2021-06-01 23:40 ` Felipe Contreras
  0 siblings, 1 reply; 3+ messages in thread
From: David Aguilar @ 2021-06-01 20:52 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Felipe Contreras, Denton Liu, SZEDER Gábor

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.

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>
---
Changes since v3:

- Dropped the addition of "git" in the words array.
- This is effectively the as the v2 patch after Felipe's suggestsions.
- The difference between this patch and v2 is the Suggested-by trailer.

 contrib/completion/git-completion.bash | 2 +-
 contrib/completion/git-completion.zsh  | 2 +-
 2 files changed, 2 insertions(+), 2 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..cac6f61881 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='.'
-- 
2.32.0.rc2.1.gf67de2b3ac


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH v4] contrib/completion: fix zsh completion regression from 59d85a2a05
  2021-06-01 20:52 [PATCH v4] contrib/completion: fix zsh completion regression from 59d85a2a05 David Aguilar
@ 2021-06-01 23:40 ` Felipe Contreras
  2021-06-02  7:13   ` Denton Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Felipe Contreras @ 2021-06-01 23:40 UTC (permalink / raw)
  To: David Aguilar, Junio C Hamano
  Cc: git, Felipe Contreras, Denton Liu, SZEDER Gábor

David Aguilar wrote:
> 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.

You might want to try this in the future to reference previous commits:

  % git show --quiet --format=reference
  59d85a2a05 (git-completion.bash: use $__git_cmd_idx in more places, 2021-04-22)

(one of the aliases I'm missing right now)
  
> Suggested-by: Felipe Contreras <felipe.contreras@gmail.com>
> Signed-off-by: David Aguilar <davvid@gmail.com>

I have not tested this particular version, but I have tested similar
changes, and this should work:

Acked-by: Felipe Contreras <felipe.contreras@gmail.com>

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] contrib/completion: fix zsh completion regression from 59d85a2a05
  2021-06-01 23:40 ` Felipe Contreras
@ 2021-06-02  7:13   ` Denton Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Denton Liu @ 2021-06-02  7:13 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: David Aguilar, Junio C Hamano, git, SZEDER Gábor

On Tue, Jun 01, 2021 at 06:40:44PM -0500, Felipe Contreras wrote:
> I have not tested this particular version, but I have tested similar
> changes, and this should work:
> 
> Acked-by: Felipe Contreras <felipe.contreras@gmail.com>

FWIW, since I was the one who introduced the bug,

Acked-by: Denton Liu <liu.denton@gmail.com>

Thanks for your help, David and Felipe.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-02  7:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01 20:52 [PATCH v4] contrib/completion: fix zsh completion regression from 59d85a2a05 David Aguilar
2021-06-01 23:40 ` Felipe Contreras
2021-06-02  7:13   ` Denton Liu

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).