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

Re: [BUG] git checkout completion shows duplicated branch names



Daniel Shahaf wrote on Mon, Sep 24, 2018 at 16:04:23 +0000:
> Marc Cornellà wrote on Mon, 24 Sep 2018 14:51 +0000:
> > Furthermore, on versions prior to commit 4dddf3aa (< zsh-5.6), the
> > completion is even worse since a branch
> > is not fully completed even if there isn't any other branch with the
> > same prefix.
> > 
> > So typing this:
> > 
> > ~/repo% git checkout topic/<TAB>
> > topic/foo  -- Initial commit
> > topic/foo
> > 
> > gets completed to `git checkout topic` instead of the full branch name.
> > 
> 
> With 'zsh -f' + 'autoload compinit; compinit', «git checkout t<TAB>»
> gives me «git checkout topic/foo<CURSOR>» and a subsequent <TAB>
> displays possible completions.  That is better than the behaviour you
> get, but I agree it shouldn't be treating this situation as an ambiguous
> completion.  I don't know offhand where the relevant piece of code is,
> though.  Probably in the internals of bin_compdescribe/bin_compadd?
> 
> Here's a minimal example:
> 
> _f() {
>   local a=( foo:FOO bar:BAR ) expl
>   _describe -t lorem "lorem" a
>   _wanted ipsum expl 'ipsum' compadd foo bar
> } 
> compdef _f f
> f f<TAB>

This seems to fix it:

[[[
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index 8eca39447..6118c62c1 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -3160,9 +3160,7 @@ matcheq(Cmatch a, Cmatch b)
 	matchstreq(a->ppre, b->ppre) &&
 	matchstreq(a->psuf, b->psuf) &&
 	matchstreq(a->suf, b->suf) &&
-	((!a->disp && !b->disp && matchstreq(a->str, b->str)) ||
-	 (a->disp && b->disp && !strcmp(a->disp, b->disp) &&
-	  matchstreq(a->str, b->str)));
+	  matchstreq(a->str, b->str);
 }
 
 /* Make an array from a linked list. The second argument says whether *
]]]

Can anyone think of a reason to consider matches different if their display
strings both exist, and differ; or if one of them has a display string and one
does not?

Marc, thanks for asking — this has been annoying me, too. ☺

Cheers,

Daniel



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