ohmyzsh: git completion fails when complete_aliases option is set

I’m running zsh 5.0.4 on OS X 10.8 with oh-my-zsh a38af27 with the git plugin. When I type gco <TAB>, I get the following output:

% gco zsh:12: command not found: __git-checkout_main
extegco
file
MIT-LICENSE.txt  custom/          log/             plugins/         themes/
README.textile   lib/             oh-my-zsh.sh     templates/       tools/

I’ve found the culprit to be the option complete_aliases. Once I turn it off, everything works as expected.

What gives? Is there any option clash? I haven’t changed my .zshrc in ages, and I’ve always had complete_aliases on.

I don’t particularly need this option but I guess there’s some bug here.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 40 (20 by maintainers)

Commits related to this issue

Most upvoted comments

The problem here is that the official Git completion was not prepared for ‘complete_aliases’, I’ve pushed a fix:

https://github.com/felipec/git/commit/aaafa76

This way you can manually define the completion with:

compdef _git gco=git_checkout

However, if you want to use zsh’s format: gco=git-checkout and for it to work in the currently distributed version of Git, you can do this:

alias __git-checkout_main=_git_checkout

@mcornella Sorry for the late reply. I did not have access to the machine that exposed the problem.

Running

brew uninstall --force git && brew install git --without-completions

solved the problem indeed.

Thank you very much for your investigation.

@mecampbellsoup yes, that could be helpful! I recommend the use of git-bisect.


The non-reproducibility of the issue suggests that it has something to do with your config, and the fact that it still happens with the template .zshrc indicates that it is not related to your OMZ config.

Let us start with determining what the compdef statement should do. Reading through Zsh completion manual indicates a bit more about how it should work:

#compdef names... [ -[pP] patterns... [ -N names... ] ] Each name may also be of the form ‘cmd=service’. When completing the command cmd, the function typically behaves as if the command (or special context) service was being completed instead. This provides a way of altering the behaviour of functions that can perform many different completions. It is implemented by setting the parameter $service when calling the function; the function may choose to interpret this how it wishes, and simpler functions will probably ignore it.

compdef [ -ane ] function names... [ -[pP] patterns... [ -N names... ] ] The first form defines the function to call for completion in the given contexts as described for the #compdef tag above. Alternatively, all the arguments may have the form ‘cmd=service’. Here service should already have been defined by ‘cmd1=service’ lines in #compdef files, as described above. The argument for cmd will be completed in the same way as service.

But then I had a look at the Zsh git completion (with the oh-so-evil 6661 line count), and git-checkout is not listed in the #compdef statement, and $service is not checked for it either. So I have no clue as to why compdef _git gco=git-checkout works — but it does work!

@pielgrzym can you enlighten us about 2e9492969b0ea90932ad3f4298330b75ef8cf2ce?