Git development
 help / color / mirror / Atom feed
From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org,
	"Felipe Contreras" <felipe.contreras@gmail.com>,
	"Denton Liu" <liu.denton@gmail.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: [PATCH] contrib/completion: fix remote completion for "git push/remote"
Date: Sat, 29 May 2021 19:49:28 -0700	[thread overview]
Message-ID: <20210530024928.24158-1-davvid@gmail.com> (raw)

If __git_cmd_idx is empty then zsh will silelntly fail to
complete remotes when doing "git push <tab>".

Ensure that __git_cmd_idx is non-empty before using it in
__git_complete_remote_or_refspec.

This was tested on zsh 5.7.1 (x86_64-apple-darwin19.0).
Other versions of zsh, eg. zsh 5.0.2 (x86_64-redhat-linux-gnu),
do not exhibit this behavior.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
Further testing of the completion behavior spotted this regression.

This should be applied on top of,
"contrib/completion: avoid empty arithemetic expressions".
and could arguably be squashed into that commit.

I have my zshrc setup to point directly to a git.git worktree and a recent
update seems to have caused these regressions.

 contrib/completion/git-completion.bash | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index d51ff5302d..bc1aea82bf 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1006,6 +1006,9 @@ __git_complete_revlist ()
 
 __git_complete_remote_or_refspec ()
 {
+	if [ -z "$__git_cmd_idx" ]; then
+		__git_cmd_idx=1
+	fi
 	local cur_="$cur" cmd="${words[__git_cmd_idx]}"
 	local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
 	if [ "$cmd" = "remote" ]; then
-- 
2.32.0.rc2.2.ga063d53b1a


             reply	other threads:[~2021-05-30  3:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-30  2:49 David Aguilar [this message]
2021-05-30  3:12 ` [PATCH] contrib/completion: fix remote completion for "git push/remote" Eric Sunshine
2021-05-30  3:32   ` David Aguilar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210530024928.24158-1-davvid@gmail.com \
    --to=davvid@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=liu.denton@gmail.com \
    --cc=szeder.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox