Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: RFC: [PATCH] Completion/Unix/Command/_git: replace a few "*::" with "*:"



On 24.02.19 20:46, dana wrote:

>> This patch changes some of the "*::" to "*:", but is not really tested
>> in detail.  Mostly based on trying if "--help" worked after any arg.
> 
> Some of these do look like they were just erroneously copied and pasted, but
> in other cases it's actually necessary, at least with the way it's written
> now. For example, the commit-range-or-file state checks to see if $CURRENT is
> 1, which can only ever be true if the *:: syntax (or equivalent) is used.

I see, thanks for looking into it!

Unfortunately this also affects / is true for state
branch-or-tree-ish-or-file with _git-checkout already, which I've wanted
to fix in the first place.

Can this be fixed in a different way then?

Currently it just returns:

  case $state in
    (branch-or-tree-ish-or-file)
      # TODO: Something about *:: brings us here when we complete at "-".  I
      # guess that this makes sense in a way, as we might want to treat it as
      # an argument, but I can't find anything in the documentation about this
      # behavior.
      [[ $line[CURRENT] = -* ]] && return

What about something like this (against master)?

diff --git i/Completion/Unix/Command/_git w/Completion/Unix/Command/_git
index b3e54f7f9..c134f13b8 100644
--- i/Completion/Unix/Command/_git
+++ w/Completion/Unix/Command/_git
@@ -449,7 +449,8 @@ _git-checkout () {
   local curcontext=$curcontext state line ret=1
   declare -A opt_args

-  _arguments -C -s \
+  local -a options
+  options=(
     '(-q --quiet --progress)'{-q,--quiet}'[suppress progress reporting]' \
     '(-f --force -m --merge --conflict --patch)'{-f,--force}'[force branch switch/ignore unmerged entries]' \
     '(-q --quiet -2 --ours -3 --theirs --patch)'{-2,--ours}'[check out stage #2 for unmerged paths]' \
@@ -469,6 +470,9 @@ _git-checkout () {
     '--recurse-submodules=-[control recursive updating of submodules]::checkout:__git_commits' \
     '(-q --quiet)--progress[force progress reporting]' \
     '(-)--[start file arguments]' \
+  )
+
+  _arguments -C -s $options \
     '*:: :->branch-or-tree-ish-or-file' && ret=0

   case $state in
@@ -477,7 +481,7 @@ _git-checkout () {
       # guess that this makes sense in a way, as we might want to treat it as
       # an argument, but I can't find anything in the documentation about this
       # behavior.
-      [[ $line[CURRENT] = -* ]] && return
+      _arguments -C -s $options && ret=0 && return
       if (( CURRENT == 1 )) && [[ -z $opt_args[(I)--] ]]; then
         # TODO: Allow A...B
         local \


> I didn't look at it much harder than that, but, in general, anywhere you're
> thinking about removing *:: or *:::, you need to check the corresponding state
> code to see if it does anything with $words or $CURRENT, or calls another
> function that does.
> 
> dana
> 


Attachment: signature.asc
Description: OpenPGP digital signature



Messages sorted by: Reverse Date, Date, Thread, Author