{"thread":{"id":"55799","subject":"[PATCH] contrib/completion: avoid empty arithemetic expressions","startedAt":"2021-05-30T02:15:35Z","lastAt":"2021-05-30T06:18:44Z","messageCount":3,"participants":["David Aguilar","Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"425894","messageId":"20210530021528.21287-1-davvid@gmail.com","threadId":"55799","inReplyTo":null,"subject":"[PATCH] contrib/completion: avoid empty arithemetic expressions","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2021-05-30T02:15:28Z","receivedAt":"2021-05-30T02:15:35Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"$__git_cmd_idx can be empty in some situations, which leads to\nerrors when using \"git add <tab>\", \"git mv <tab>\",\n\"git tag <tab>\" and \"git branch <tab>\".\n\n\"git mv <tab>\" prints this error:\n\n\t__git_count_arguments:5:\n\tbad math expression: operand expected at `\"\"'\n\n\t_git_mv:[:9: unknown condition: -gt\n\n\"git branch <tab>\" prints this error:\n\n\t_git_branch:[:4: unknown condition: -lt\n\n\"git tag <tab>\" prints this error:\n\n\t_git_tag:[:3: unknown condition: -lt\n\n\"git add <tab>\" prints this error:\n\n\t__git_find_on_cmdline:[:13: unknown condition: -lt\n\nFix _git_branch, __git_find_on_cmdline and _git_tag by\ninitializing the local \"c\" variable to 1 when empty.\n\nFix __git_count_arguments by initializing \"__git_cmd_idx\" to 1.\n\nAdjust the for loop in __git_count_arguments to avoid quoting\nthe numeric argument to avoid the following error:\n\n\t__git_count_arguments:8:\n\tbad math expression: operand expected at `\"1\"'\n\nThis was tested on zsh 5.7.1 (x86_64-apple-darwin19.0).\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n contrib/completion/git-completion.bash | 15 ++++++++++++++-\n 1 file changed, 14 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 3c5739b905..d51ff5302d 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1177,6 +1177,9 @@ __git_aliased_command ()\n __git_find_on_cmdline ()\n {\n \tlocal word c=\"$__git_cmd_idx\" show_idx\n+\tif [ -z \"$c\" ]; then\n+\t\tc=1\n+\tfi\n \n \twhile test $# -gt 1; do\n \t\tcase \"$1\" in\n@@ -1304,9 +1307,12 @@ __git_has_doubledash ()\n __git_count_arguments ()\n {\n \tlocal word i c=0\n+\tif [ -z \"$__git_cmd_idx\" ]; then\n+\t\t__git_cmd_idx=1\n+\tfi\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\n@@ -1448,6 +1454,9 @@ __git_ref_fieldlist=\"refname objecttype objectsize objectname upstream push HEAD\n _git_branch ()\n {\n \tlocal i c=\"$__git_cmd_idx\" only_local_ref=\"n\" has_r=\"n\"\n+\tif [ -z \"$c\" ]; then\n+\t\tc=1\n+\tfi\n \n \twhile [ $c -lt $cword ]; do\n \t\ti=\"${words[c]}\"\n@@ -3213,6 +3222,10 @@ _git_svn ()\n _git_tag ()\n {\n \tlocal i c=\"$__git_cmd_idx\" f=0\n+\tif [ -z \"$c\" ]; then\n+\t\tc=1\n+\tfi\n+\n \twhile [ $c -lt $cword ]; do\n \t\ti=\"${words[c]}\"\n \t\tcase \"$i\" in\n-- \n2.32.0.rc2.1.g6e92745b1d\n\n"},{"id":"425898","messageId":"60b30b159bda0_50fd208ee@natae.notmuch","threadId":"55799","inReplyTo":"20210530021528.21287-1-davvid@gmail.com","subject":"RE: [PATCH] contrib/completion: avoid empty arithemetic expressions","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-05-30T03:48:37Z","receivedAt":"2021-05-30T03:48:51Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"David Aguilar wrote:\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 3c5739b905..d51ff5302d 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1177,6 +1177,9 @@ __git_aliased_command ()\n>  __git_find_on_cmdline ()\n>  {\n>  \tlocal word c=\"$__git_cmd_idx\" show_idx\n> +\tif [ -z \"$c\" ]; then\n> +\t\tc=1\n> +\tfi\n\nThis is not the correct location to fix this, it's here:\n\ndiff --git a/git-completion.zsh b/git-completion.zsh\nindex 0ef15ff..df98e68 100644\n--- a/git-completion.zsh\n+++ b/git-completion.zsh\n@@ -233,7 +233,7 @@ __git_zsh_main ()\n                emulate ksh -c __git_complete_config_variable_name_and_value\n                ;;\n        (arg)\n-               local command=\"${words[1]}\" __git_dir\n+               local command=\"${words[1]}\" __git_dir __git_cmd_idx=1\n \n                if (( $+opt_args[--bare] )); then\n                        __git_dir='.'\n\nCommit 59d85a2a05 (git-completion.bash: use $__git_cmd_idx in more\nplaces, 2021-04-22) broke zsh because it modified __git_main, but not\n__git_zsh_main.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"425901","messageId":"CAJDDKr7rVpnCgMEbw4aeLXrUWMxV=sOYNCUn-2o69FgpbU3XwA@mail.gmail.com","threadId":"55799","inReplyTo":"60b30b159bda0_50fd208ee@natae.notmuch","subject":"Re: [PATCH] contrib/completion: avoid empty arithemetic expressions","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2021-05-30T06:18:01Z","receivedAt":"2021-05-30T06:18:44Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On Sat, May 29, 2021 at 8:48 PM Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n>\n> David Aguilar wrote:\n> > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> > index 3c5739b905..d51ff5302d 100644\n> > --- a/contrib/completion/git-completion.bash\n> > +++ b/contrib/completion/git-completion.bash\n> > @@ -1177,6 +1177,9 @@ __git_aliased_command ()\n> >  __git_find_on_cmdline ()\n> >  {\n> >       local word c=\"$__git_cmd_idx\" show_idx\n> > +     if [ -z \"$c\" ]; then\n> > +             c=1\n> > +     fi\n>\n> This is not the correct location to fix this, it's here:\n>\n> diff --git a/git-completion.zsh b/git-completion.zsh\n> index 0ef15ff..df98e68 100644\n> --- a/git-completion.zsh\n> +++ b/git-completion.zsh\n> @@ -233,7 +233,7 @@ __git_zsh_main ()\n>                 emulate ksh -c __git_complete_config_variable_name_and_value\n>                 ;;\n>         (arg)\n> -               local command=\"${words[1]}\" __git_dir\n> +               local command=\"${words[1]}\" __git_dir __git_cmd_idx=1\n>\n>                 if (( $+opt_args[--bare] )); then\n>                         __git_dir='.'\n>\n> Commit 59d85a2a05 (git-completion.bash: use $__git_cmd_idx in more\n> places, 2021-04-22) broke zsh because it modified __git_main, but not\n> __git_zsh_main.\n>\n> Cheers.\n>\n> --\n> Felipe Contreras\n\nSweet, thanks Felipe.\n\nThe resulting patch is much simpler now too. Please disregard the\nprevious patches, v2 is on the way.\n-- \nDavid\n"}]}