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

[PATCH] contrib/completion: fix remote completion for "git push/remote"

From
David Aguilar <davvid@gmail.com>
Date
May 30, 2021, 02:49 UTC
Message-ID
<20210530024928.24158-1-davvid@gmail.com>

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
Next: Eric Sunshine
Message 1 of 3 in “contrib/completion: fix remote completion for "git push/remote"”
  1. contrib/completion: fix remote completion for "git push/remote"David Aguilar, May 30, 2021
  2. Eric SunshineMay 30, 2021
  3. David AguilarMay 30, 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.