{"thread":{"id":"54304","subject":"[PATCH v2 1/2] completion: use \"prev\" variable instead of introducing \"prevword\"","startedAt":"2020-09-25T22:01:02Z","lastAt":"2020-09-26T22:32:06Z","messageCount":4,"participants":["Ákos Uzonyi","Jacob Keller","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"406402","messageId":"20200925211124.1673337-1-uzonyi.akos@gmail.com","threadId":"54304","inReplyTo":null,"subject":"[PATCH v2 1/2] completion: use \"prev\" variable instead of introducing \"prevword\"","fromName":"Ákos Uzonyi","fromEmail":"uzonyi.akos@gmail.com","sentAt":"2020-09-25T21:11:23Z","receivedAt":"2020-09-25T22:01:02Z","isPatch":true,"sender":{"key":"uzonyi.akos@gmail.com","avatar":"https://avatars.githubusercontent.com/u/15818682?v=4"},"body":"In both _git_checkout and _git_switch a new \"prevword\" variable were\nintroduced, however the \"prev\" variable already contains the last word.\n\nThe \"prevword\" variable is replaced with \"prev\", and the case is moved\nto the beginning of the function, like it's done in many other places\n(e.g. _git_commit). Also the indentaion of the case is fixed.\n\nSigned-off-by: Ákos Uzonyi <uzonyi.akos@gmail.com>\n---\n contrib/completion/git-completion.bash | 66 +++++++++++++-------------\n 1 file changed, 32 insertions(+), 34 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 8be4a0316e..3d02bd4de7 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1508,6 +1508,22 @@ _git_checkout ()\n {\n \t__git_has_doubledash && return\n \n+\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n+\n+\tcase \"$prev\" in\n+\t-b|-B|--orphan)\n+\t\t# Complete local branches (and DWIM branch\n+\t\t# remote branch names) for an option argument\n+\t\t# specifying a new branch name. This is for\n+\t\t# convenience, assuming new branches are\n+\t\t# possibly based on pre-existing branch names.\n+\t\t__git_complete_refs $dwim_opt --mode=\"heads\"\n+\t\treturn\n+\t\t;;\n+\t*)\n+\t\t;;\n+\tesac\n+\n \tcase \"$cur\" in\n \t--conflict=*)\n \t\t__gitcomp \"diff3 merge\" \"\" \"${cur##--conflict=}\"\n@@ -1516,23 +1532,6 @@ _git_checkout ()\n \t\t__gitcomp_builtin checkout\n \t\t;;\n \t*)\n-\t\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n-\t\tlocal prevword prevword=\"${words[cword-1]}\"\n-\n-\t\tcase \"$prevword\" in\n-\t\t\t-b|-B|--orphan)\n-\t\t\t\t# Complete local branches (and DWIM branch\n-\t\t\t\t# remote branch names) for an option argument\n-\t\t\t\t# specifying a new branch name. This is for\n-\t\t\t\t# convenience, assuming new branches are\n-\t\t\t\t# possibly based on pre-existing branch names.\n-\t\t\t\t__git_complete_refs $dwim_opt --mode=\"heads\"\n-\t\t\t\treturn\n-\t\t\t\t;;\n-\t\t\t*)\n-\t\t\t\t;;\n-\t\tesac\n-\n \t\t# At this point, we've already handled special completion for\n \t\t# the arguments to -b/-B, and --orphan. There are 3 main\n \t\t# things left we can possibly complete:\n@@ -2392,6 +2391,22 @@ _git_status ()\n \n _git_switch ()\n {\n+\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n+\n+\tcase \"$prev\" in\n+\t-c|-C|--orphan)\n+\t\t# Complete local branches (and DWIM branch\n+\t\t# remote branch names) for an option argument\n+\t\t# specifying a new branch name. This is for\n+\t\t# convenience, assuming new branches are\n+\t\t# possibly based on pre-existing branch names.\n+\t\t__git_complete_refs $dwim_opt --mode=\"heads\"\n+\t\treturn\n+\t\t;;\n+\t*)\n+\t\t;;\n+\tesac\n+\n \tcase \"$cur\" in\n \t--conflict=*)\n \t\t__gitcomp \"diff3 merge\" \"\" \"${cur##--conflict=}\"\n@@ -2400,23 +2415,6 @@ _git_switch ()\n \t\t__gitcomp_builtin switch\n \t\t;;\n \t*)\n-\t\tlocal dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n-\t\tlocal prevword prevword=\"${words[cword-1]}\"\n-\n-\t\tcase \"$prevword\" in\n-\t\t\t-c|-C|--orphan)\n-\t\t\t\t# Complete local branches (and DWIM branch\n-\t\t\t\t# remote branch names) for an option argument\n-\t\t\t\t# specifying a new branch name. This is for\n-\t\t\t\t# convenience, assuming new branches are\n-\t\t\t\t# possibly based on pre-existing branch names.\n-\t\t\t\t__git_complete_refs $dwim_opt --mode=\"heads\"\n-\t\t\t\treturn\n-\t\t\t\t;;\n-\t\t\t*)\n-\t\t\t\t;;\n-\t\tesac\n-\n \t\t# Unlike in git checkout, git switch --orphan does not take\n \t\t# a start point. Thus we really have nothing to complete after\n \t\t# the branch name.\n-- \n2.28.0\n\n"},{"id":"406403","messageId":"20200925211124.1673337-2-uzonyi.akos@gmail.com","threadId":"54304","inReplyTo":"20200925211124.1673337-1-uzonyi.akos@gmail.com","subject":"[PATCH v2 2/2] completion: complete refs after 'git restore -s'","fromName":"Ákos Uzonyi","fromEmail":"uzonyi.akos@gmail.com","sentAt":"2020-09-25T21:11:24Z","receivedAt":"2020-09-25T22:01:05Z","isPatch":true,"sender":{"key":"uzonyi.akos@gmail.com","avatar":"https://avatars.githubusercontent.com/u/15818682?v=4"},"body":"Currently only the long version (--source=) supports completion.\n\nAdd completion support to the short (-s) option too.\n\nSigned-off-by: Ákos Uzonyi <uzonyi.akos@gmail.com>\n---\n contrib/completion/git-completion.bash | 7 +++++++\n 1 file changed, 7 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 3d02bd4de7..0a96ad87e7 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2841,6 +2841,13 @@ _git_reset ()\n \n _git_restore ()\n {\n+\tcase \"$prev\" in\n+\t-s)\n+\t\t__git_complete_refs\n+\t\treturn\n+\t\t;;\n+\tesac\n+\n \tcase \"$cur\" in\n \t--conflict=*)\n \t\t__gitcomp \"diff3 merge\" \"\" \"${cur##--conflict=}\"\n-- \n2.28.0\n\n"},{"id":"406409","messageId":"CA+P7+xrBcKpDgFfDyp8=f_AaqqcVzjo3MV38=6geJ6bavZSTDw@mail.gmail.com","threadId":"54304","inReplyTo":"20200925211124.1673337-1-uzonyi.akos@gmail.com","subject":"Re: [PATCH v2 1/2] completion: use \"prev\" variable instead of introducing \"prevword\"","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2020-09-25T22:53:53Z","receivedAt":"2020-09-25T22:54:07Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Fri, Sep 25, 2020 at 3:00 PM Ákos Uzonyi <uzonyi.akos@gmail.com> wrote:\n>\n> In both _git_checkout and _git_switch a new \"prevword\" variable were\n> introduced, however the \"prev\" variable already contains the last word.\n>\n> The \"prevword\" variable is replaced with \"prev\", and the case is moved\n> to the beginning of the function, like it's done in many other places\n> (e.g. _git_commit). Also the indentaion of the case is fixed.\n>\n\nAhhh... didn't realize $prev existed.\n\n> Signed-off-by: Ákos Uzonyi <uzonyi.akos@gmail.com>\n> ---\n>  contrib/completion/git-completion.bash | 66 +++++++++++++-------------\n>  1 file changed, 32 insertions(+), 34 deletions(-)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 8be4a0316e..3d02bd4de7 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1508,6 +1508,22 @@ _git_checkout ()\n>  {\n>         __git_has_doubledash && return\n>\n> +       local dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n> +\n> +       case \"$prev\" in\n> +       -b|-B|--orphan)\n> +               # Complete local branches (and DWIM branch\n> +               # remote branch names) for an option argument\n> +               # specifying a new branch name. This is for\n> +               # convenience, assuming new branches are\n> +               # possibly based on pre-existing branch names.\n> +               __git_complete_refs $dwim_opt --mode=\"heads\"\n> +               return\n> +               ;;\n> +       *)\n> +               ;;\n> +       esac\n> +\n>         case \"$cur\" in\n>         --conflict=*)\n>                 __gitcomp \"diff3 merge\" \"\" \"${cur##--conflict=}\"\n> @@ -1516,23 +1532,6 @@ _git_checkout ()\n>                 __gitcomp_builtin checkout\n>                 ;;\n>         *)\n> -               local dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n> -               local prevword prevword=\"${words[cword-1]}\"\n> -\n> -               case \"$prevword\" in\n> -                       -b|-B|--orphan)\n> -                               # Complete local branches (and DWIM branch\n> -                               # remote branch names) for an option argument\n> -                               # specifying a new branch name. This is for\n> -                               # convenience, assuming new branches are\n> -                               # possibly based on pre-existing branch names.\n> -                               __git_complete_refs $dwim_opt --mode=\"heads\"\n> -                               return\n> -                               ;;\n> -                       *)\n> -                               ;;\n> -               esac\n> -\n>                 # At this point, we've already handled special completion for\n>                 # the arguments to -b/-B, and --orphan. There are 3 main\n>                 # things left we can possibly complete:\n> @@ -2392,6 +2391,22 @@ _git_status ()\n>\n>  _git_switch ()\n>  {\n> +       local dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n> +\n> +       case \"$prev\" in\n> +       -c|-C|--orphan)\n> +               # Complete local branches (and DWIM branch\n> +               # remote branch names) for an option argument\n> +               # specifying a new branch name. This is for\n> +               # convenience, assuming new branches are\n> +               # possibly based on pre-existing branch names.\n> +               __git_complete_refs $dwim_opt --mode=\"heads\"\n> +               return\n> +               ;;\n> +       *)\n> +               ;;\n> +       esac\n> +\n>         case \"$cur\" in\n>         --conflict=*)\n>                 __gitcomp \"diff3 merge\" \"\" \"${cur##--conflict=}\"\n> @@ -2400,23 +2415,6 @@ _git_switch ()\n>                 __gitcomp_builtin switch\n>                 ;;\n>         *)\n> -               local dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n> -               local prevword prevword=\"${words[cword-1]}\"\n> -\n> -               case \"$prevword\" in\n> -                       -c|-C|--orphan)\n> -                               # Complete local branches (and DWIM branch\n> -                               # remote branch names) for an option argument\n> -                               # specifying a new branch name. This is for\n> -                               # convenience, assuming new branches are\n> -                               # possibly based on pre-existing branch names.\n> -                               __git_complete_refs $dwim_opt --mode=\"heads\"\n> -                               return\n> -                               ;;\n> -                       *)\n> -                               ;;\n> -               esac\n> -\n>                 # Unlike in git checkout, git switch --orphan does not take\n>                 # a start point. Thus we really have nothing to complete after\n>                 # the branch name.\n> --\n> 2.28.0\n>\n"},{"id":"406459","messageId":"xmqqpn68i2zq.fsf@gitster.c.googlers.com","threadId":"54304","inReplyTo":"CA+P7+xrBcKpDgFfDyp8=f_AaqqcVzjo3MV38=6geJ6bavZSTDw@mail.gmail.com","subject":"Re: [PATCH v2 1/2] completion: use \"prev\" variable instead of introducing \"prevword\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-09-26T22:31:53Z","receivedAt":"2020-09-26T22:32:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jacob Keller <jacob.keller@gmail.com> writes:\n\n> On Fri, Sep 25, 2020 at 3:00 PM Ákos Uzonyi <uzonyi.akos@gmail.com> wrote:\n>>\n>> In both _git_checkout and _git_switch a new \"prevword\" variable were\n>> introduced, however the \"prev\" variable already contains the last word.\n>>\n>> The \"prevword\" variable is replaced with \"prev\", and the case is moved\n>> to the beginning of the function, like it's done in many other places\n>> (e.g. _git_commit). Also the indentaion of the case is fixed.\n>>\n>\n> Ahhh... didn't realize $prev existed.\n\nYup, makes a lot of sense.\n\nThanks, Ákos.  Will queue.\n\n>\n>> Signed-off-by: Ákos Uzonyi <uzonyi.akos@gmail.com>\n>> ---\n>>  contrib/completion/git-completion.bash | 66 +++++++++++++-------------\n>>  1 file changed, 32 insertions(+), 34 deletions(-)\n>>\n>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n>> index 8be4a0316e..3d02bd4de7 100644\n>> --- a/contrib/completion/git-completion.bash\n>> +++ b/contrib/completion/git-completion.bash\n>> @@ -1508,6 +1508,22 @@ _git_checkout ()\n>>  {\n>>         __git_has_doubledash && return\n>>\n>> +       local dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n>> +\n>> +       case \"$prev\" in\n>> +       -b|-B|--orphan)\n>> +               # Complete local branches (and DWIM branch\n>> +               # remote branch names) for an option argument\n>> +               # specifying a new branch name. This is for\n>> +               # convenience, assuming new branches are\n>> +               # possibly based on pre-existing branch names.\n>> +               __git_complete_refs $dwim_opt --mode=\"heads\"\n>> +               return\n>> +               ;;\n>> +       *)\n>> +               ;;\n>> +       esac\n>> +\n>>         case \"$cur\" in\n>>         --conflict=*)\n>>                 __gitcomp \"diff3 merge\" \"\" \"${cur##--conflict=}\"\n>> @@ -1516,23 +1532,6 @@ _git_checkout ()\n>>                 __gitcomp_builtin checkout\n>>                 ;;\n>>         *)\n>> -               local dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n>> -               local prevword prevword=\"${words[cword-1]}\"\n>> -\n>> -               case \"$prevword\" in\n>> -                       -b|-B|--orphan)\n>> -                               # Complete local branches (and DWIM branch\n>> -                               # remote branch names) for an option argument\n>> -                               # specifying a new branch name. This is for\n>> -                               # convenience, assuming new branches are\n>> -                               # possibly based on pre-existing branch names.\n>> -                               __git_complete_refs $dwim_opt --mode=\"heads\"\n>> -                               return\n>> -                               ;;\n>> -                       *)\n>> -                               ;;\n>> -               esac\n>> -\n>>                 # At this point, we've already handled special completion for\n>>                 # the arguments to -b/-B, and --orphan. There are 3 main\n>>                 # things left we can possibly complete:\n>> @@ -2392,6 +2391,22 @@ _git_status ()\n>>\n>>  _git_switch ()\n>>  {\n>> +       local dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n>> +\n>> +       case \"$prev\" in\n>> +       -c|-C|--orphan)\n>> +               # Complete local branches (and DWIM branch\n>> +               # remote branch names) for an option argument\n>> +               # specifying a new branch name. This is for\n>> +               # convenience, assuming new branches are\n>> +               # possibly based on pre-existing branch names.\n>> +               __git_complete_refs $dwim_opt --mode=\"heads\"\n>> +               return\n>> +               ;;\n>> +       *)\n>> +               ;;\n>> +       esac\n>> +\n>>         case \"$cur\" in\n>>         --conflict=*)\n>>                 __gitcomp \"diff3 merge\" \"\" \"${cur##--conflict=}\"\n>> @@ -2400,23 +2415,6 @@ _git_switch ()\n>>                 __gitcomp_builtin switch\n>>                 ;;\n>>         *)\n>> -               local dwim_opt=\"$(__git_checkout_default_dwim_mode)\"\n>> -               local prevword prevword=\"${words[cword-1]}\"\n>> -\n>> -               case \"$prevword\" in\n>> -                       -c|-C|--orphan)\n>> -                               # Complete local branches (and DWIM branch\n>> -                               # remote branch names) for an option argument\n>> -                               # specifying a new branch name. This is for\n>> -                               # convenience, assuming new branches are\n>> -                               # possibly based on pre-existing branch names.\n>> -                               __git_complete_refs $dwim_opt --mode=\"heads\"\n>> -                               return\n>> -                               ;;\n>> -                       *)\n>> -                               ;;\n>> -               esac\n>> -\n>>                 # Unlike in git checkout, git switch --orphan does not take\n>>                 # a start point. Thus we really have nothing to complete after\n>>                 # the branch name.\n>> --\n>> 2.28.0\n>>\n"}]}