{"thread":{"id":"55801","subject":"[PATCH v2] contrib/completion: fix zsh completion regression from 59d85a2a05","startedAt":"2021-05-30T06:24:45Z","lastAt":"2021-05-30T16:52:44Z","messageCount":2,"participants":["David Aguilar","Felipe Contreras"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"425902","messageId":"20210530062438.53527-1-davvid@gmail.com","threadId":"55801","inReplyTo":null,"subject":"[PATCH v2] contrib/completion: fix zsh completion regression from 59d85a2a05","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2021-05-30T06:24:38Z","receivedAt":"2021-05-30T06:24:45Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"A recent change to make git-completion.bash use $__git_cmd_idx\nin more places broke a number of completions on zsh because it\nmodified __git_main but did not update __git_zsh_main.\n\nNotably, completions for \"add\", \"branch\", \"mv\" and \"push\" were\nbroken as a result of this change.\n\nIn addition to the undefined variable usage, \"git mv <tab>\" also\nprints the following error:\n\n\t__git_count_arguments:7: bad math expression:\n\toperand expected at `\"1\"'\n\n\t_git_mv:[:7: unknown condition: -gt\n\nRemove the quotes around $__git_cmd_idx in __git_count_arguments\nand set __git_cmd_idx=1 early in __git_zsh_main to fix the\nregressions from 59d85a2a05.\n\nThis was tested on zsh 5.7.1 (x86_64-apple-darwin19.0).\n\nHelped-by: Felipe Contreras <felipe.contreras@gmail.com>\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n contrib/completion/git-completion.zsh  | 2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 3c5739b905..b50c5d0ea3 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1306,7 +1306,7 @@ __git_count_arguments ()\n \tlocal word i c=0\n \n \t# Skip \"git\" (first argument)\n-\tfor ((i=\"$__git_cmd_idx\"; i < ${#words[@]}; i++)); do\n+\tfor ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do\n \t\tword=\"${words[i]}\"\n \n \t\tcase \"$word\" in\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nindex 6c56296997..cac6f61881 100644\n--- a/contrib/completion/git-completion.zsh\n+++ b/contrib/completion/git-completion.zsh\n@@ -251,7 +251,7 @@ __git_zsh_main ()\n \t\tdone\n \t\t;;\n \t(arg)\n-\t\tlocal command=\"${words[1]}\" __git_dir\n+\t\tlocal command=\"${words[1]}\" __git_dir __git_cmd_idx=1\n \n \t\tif (( $+opt_args[--bare] )); then\n \t\t\t__git_dir='.'\n-- \n2.32.0.rc2.1.gffeee53afa\n\n"},{"id":"425932","messageId":"60b3c2d7557bd_be762089a@natae.notmuch","threadId":"55801","inReplyTo":"20210530062438.53527-1-davvid@gmail.com","subject":"RE: [PATCH v2] contrib/completion: fix zsh completion regression from 59d85a2a05","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-30T16:52:39Z","receivedAt":"2021-05-30T16:52:44Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"David Aguilar wrote:\n> --- a/contrib/completion/git-completion.zsh\n> +++ b/contrib/completion/git-completion.zsh\n> @@ -251,7 +251,7 @@ __git_zsh_main ()\n>  \t\tdone\n>  \t\t;;\n>  \t(arg)\n> -\t\tlocal command=\"${words[1]}\" __git_dir\n> +\t\tlocal command=\"${words[1]}\" __git_dir __git_cmd_idx=1\n>  \n>  \t\tif (( $+opt_args[--bare] )); then\n>  \t\t\t__git_dir='.'\n\nNote that this is not the correct fix, since the index of the command\nwill not always be 1.\n\nWe would probably need to at least do something like:\n\n--- a/git-completion.zsh\n+++ b/git-completion.zsh\n@@ -260,7 +260,7 @@ __git_zsh_main ()\n \n                (( $+opt_args[--help] )) && command='help'\n \n-               words=( ${orig_words[@]} )\n+               words=( git ${words[@]} )\n \n                __git_zsh_bash_func $command\n                ;;\n\nAnd then it will almost always do the correct thing (at least in\ngit-completion[1] which does have all the git main arguments).\n\nFor now doing __git_cmd_idx=1 should fix the regression.\n\nCheers.\n\n[1] https://github.com/felipec/git-completion\n\n-- \nFelipe Contreras\n"}]}