Homebrew/legacy-homebrew

git completion in zsh doesn't work after #16961

Closed this issue · 50 comments

Change introduced in #16961 breaks git completion in zsh: git formula now installs zsh completion function to /usr/local/share/zsh/site-functions/_git, but it is just a wrapper around bash completion script and expects bash completion script in the same folder. Currently, triggering git completion in zsh leads to:

_git:.:26: no such file or directory: /usr/local/share/zsh/site-functions/git-completion.bash

git-completion.bash should be copied to /usr/local/share/zsh/site-functions/ for this to work without being configured by user.

On the other hand, current version of zsh has a different version of git completion built-in, should it be replaced at all?

I was halfway done submitting this issue until I stumbled across yours. As a local quick-fix to prevent the error, I ran this:

ln -s \
    /usr/local/etc/bash_completion.d/git-completion.bash \
    /usr/local/share/zsh/site-functions/git-completion.bash

As for using git's git-completion over the ZSH default, it's more of a matter of preference. Git's is less wordy and seems to be better at autocompleting git aliases. ZSH's provides descriptions of the actions that get listed, but could potentially be out-of-sync with git's commands (I suppose that's why homebrew handles it that way).

Maybe the completion scripts could be put in a place relative to each other and if a ZSH user wants to use git's git-completion script over ZSH's git-completion script, they could just manually source it into their .zshrc rather than have homebrew copy it into site-functions/ where it gets automatically sourced.

Why don't I see this issue? Probaly because I use zprezto, which brings a lot of completions already.

@samueljohn Yeah, zpresto overwrites the _git function so your completion works fine. In this case, we're talking about the most up-to-date git and zsh homebrew recipes with nothing additional. Lots of people who uze zsh are using oh-my-zsh, zpresto, or plenty of other frameworks that have alternate autocomplete functions. For everyone else, this is an annoying bug.

I agree.

Kinda thinking we should just leave it in contrib and let zsh users copy it if they want something other than the built-in git support.

Not being a zsh user, I pulled the change blindly; let's revert. Do we need a comment about this in the formula?

I think a comment or a note in the caveats could be useful, something about renaming git-completion.zsh to _git and putting it in $fpath

For what it's worth I'd prefer the Git-provided one over the ZSH one.

Happy to implement it properly myself though.

I'm getting something a bit different:

git checkout (anon):6: command not found: __git_main

I was getting the same error as @harukizaemon but the same fix that @dflems mentioned fixed it for me.

Some maintainer using zsh user here please pull a fix; thanks.

I will when back from holiday.

This issue completed screwed up my Zsh git completion. I simply can't get the Zsh built-in completion back. Anyone else have any luck with that?

If you want the zsh built-in completion back: rm /usr/local/share/zsh/site-functions/_git

so what's the correct work-around here?

ln -s \
    /usr/local/etc/bash_completion.d/git-completion.bash \
    /usr/local/share/zsh/site-functions/git-completion.bash

_and_

rm /usr/local/share/zsh/site-functions/_git

Is that right?

An easy fix is adding this line to your zshrc:

zstyle ':completion:*:*:git:*' script /usr/local/etc/bash_completion.d/git-completion.bash

Basically as some mentioned before, the zsh completion relies on the bash completion which can usually be found next to the zsh completion script.
That being said, there is a lot of documentation in the completion script that I suggest everyone interested to read:

# zsh completion wrapper for git
#
# You need git's bash completion script installed somewhere, by default on the
# same directory as this script.
#
# If your script is on ~/.git-completion.sh instead, you can configure it on
# your ~/.zshrc:
#
#  zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
#
# The recommended way to install this script is to copy to
# '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file:
#
#  fpath=(~/.zsh/completion $fpath)

And just my 2p on the idea of automatically installing the git/contrib completion, some people are used to the builtin one which is working fine (and IMHO is even better).
A caveat on how to install the contrib script would make more sense than forcing everyone to use it.

I reverted the change; if someone wants to add a note to the caveats please open a new pull request. Thanks.

Has this actually been reverted? I still get this on current tip.

(Although removing the completion file as suggested gave me my completion back via the standard git completion).

Every time I brew update now, I have to run one of the listed workarounds because my git completion gets screwed up. What is going on?

I'm getting it too, even with the workaround proposed by @ColinHebert.

FWIW, I updated brew (to get the commit that reverted this change) then removed and re-installed git and voila! it's all working again.

lxyu commented

yah, need reinstall git to make the revert work.

Confirming that running brew update && brew remove git && brew install git and restarting my terminal session solved this.

Worked for me too.

xsyn commented

I've just tried a brew update && brew remove git && brew install git it pulled down version 1.8.1.2 but I'm still getting this error.

@xsyn What error?

xsyn commented

Warning rather than error.

WARNING: this script is deprecated, please see git-completion.zsh

Same here, tried the above mentioned fix and I still receive a warning.

brew update; brew uninstall git; brew install git

xsyn commented

That's what I've tried:

`Last login: Sat Feb 2 11:00:36 on ttys016
You have new mail.
WARNING: this script is deprecated, please see git-completion.zsh
WARNING: this script is deprecated, please see git-completion.zsh

1.9.3-p327 in xsyn/
› brew update; brew uninstall git; brew install git
Already up-to-date.
Uninstalling /usr/local/Cellar/git/1.8.1.2...
==> Downloading http://git-core.googlecode.com/files/git-1.8.1.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/git-1.8.1.2.tar.gz
==> make prefix=/usr/local/Cellar/git/1.8.1.2 CC=cc CFLAGS= LDFLAGS= install
==> make CC=cc CFLAGS= LDFLAGS=
==> make clean
==> make CC=cc CFLAGS= LDFLAGS=
==> Downloading http://git-core.googlecode.com/files/git-manpages-1.8.1.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/git-manpages-1.8.1.2.tar.gz
==> Downloading http://git-core.googlecode.com/files/git-htmldocs-1.8.1.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/git-htmldocs-1.8.1.2.tar.gz
==> Caveats
The OS X keychain credential helper has been installed to:
/usr/local/bin/git-credential-osxkeychain

The 'contrib' directory has been installed to:
/usr/local/share/git-core/contrib

Bash completion has been installed to:
/usr/local/etc/bash_completion.d

zsh completion has been installed to:
/usr/local/share/zsh/site-functions
==> Summary
/usr/local/Cellar/git/1.8.1.2: 1286 files, 26M, built in 86 seconds
`

I then open a new term:

Last login: Sun Feb 3 12:23:34 on ttys017 You have new mail. WARNING: this script is deprecated, please see git-completion.zsh WARNING: this script is deprecated, please see git-completion.zsh

I have also tried removing the downloaded tar ball to download a new copy of the source. My current brew version is on: d2f3185.

Try rm /usr/local/etc/bash_completion.d/*git* /usr/local/share/zsh/site-functions/*git*; brew uninstall git; brew install git

xsyn commented

No,

If I remove the symlinks manually, and then open a new term then it's fine. However if I then uninstall and re-install git the symlinks are replaced, and the same warning comes up.

For now, I'm just going to remove the symlinks.

On Feb 6, 2013, at 3:26 AM, Mike McQuaid notifications@github.com wrote:

Try rm /usr/local/etc/bash_completion.d/git /usr/local/share/zsh/site-functions/git; brew uninstall git; brew install git


Reply to this email directly or view it on GitHub.

I am still having this problem. I've tried everything in this thread, and removing the symlinks seems to work, but I wonder why this persists? Is there a definitive way to deal with this?

Not the biggest problem, for sure, but a little annoying...

Works for me with #16992 (comment)

@MikeMcQuaid Thanks.

@mshick I think this is an upgrade path issue if you'd installed a problem version in the past. It doesn't seem to affect most users. Is it working for you now?

@mikemcquid I was able to resolve this (I hope) by following @ColinHebert's advice above.

In case anyone just looks to the end of this thread, and is perhaps using a fork of Holman's dotfiles as I am:

I changed my git completion def from:

source /usr/local/etc/bash_completion.d/git-completion.bash

to

zstyle ':completion:*:*:git:*' source /usr/local/share/zsh/site-functions/_git

Not sure why you were doing source /usr/local/etc/bash_completion.d/git-completion.bash. I'm using export FPATH="$(brew --prefix)/share/zsh/site-functions:$FPATH"

I'm using a fork of this: https://github.com/holman/dotfiles/blob/master/git/completion.zsh, and this past month has been my first foray into zsh, so I'm still figuring some things out.

Thanks for your help!

@MikeMcQuaid would you be open to a pull request that adds an option to select between the two styles of completion? I personally prefer the zsh distribution's version of _git over the git distribution's bash-based version. Obviously, this is easy enough to fix for just me, but I suspect I'm not the only person out there with this preference.

If that's unpalatable, would you at least be willing to accept a PR that prevents the stock _git script from being installed? It's rather confusing for two _git scripts to be installed at the same time, even though zsh will clearly prefer the one that comes first in the $fpath array (site-functions w/ the bash version, by default).

If you make a pull request with an option to not install the git completions I'll happily merge it. Call it --without-completions or something.

mmh I am kinda new to this still. I dont know what exactly is going on, but can somebody check my file. As of now i don't get the error when i use my file like this, but i dont know if it s correct.

https://github.com/strages/dotfiles/commit/7bfdcbd7a56f422fea199d38b34eb2c79e95cb2a

PS also using holmans dotfiles

The problem is probably that you're adding both the bash and the zsh completion. Whatever the problem is it's with holman's dotfiles and not Homebrew though.

@strages Since we've both started at the same place, perhaps my file will help?

https://github.com/mshick/dotfiles/blob/master/git/completion.zsh

I'm using the globally installed homebrew, but if you did a local install the completion path might look like:

~/.homebrew/share/zsh/site-functions/_git

works like a charm :)

the formula overwrote by oh-my-zsh git plugin - is there a way to revert?

@bsiddiqui I don't follow you, can you clarify? Which formula overwrote which file (and what action did you perform to cause the overwrite)? Is this a problem with the fix to the git formula that I made several months ago (6d49b47) or the one that @MikeMcQuaid made (2c6c877)?

Oh I think it has to do with the fix @MikeMcQuaid made. Basically, when I installed the git formula (to update my version of git) there was a conflict with git-completion.zsh and it suggested that I use the -overwrite flag to resolve the error. I didn't know, however, that that would cause by oh-my-zsh git plugin (which has its own set of alias') to stop working.

@bsiddiqui I think you are right. oh-my-zsh has its own git-completion.bash file under oh-my-zsh/plugins / gitfast /, so we don't have to source any git-completion.bash files in ~/.zshrc, in other words, we must make sure there is no such lines in /.zshrc:source ~/.git-completion.bash or source ~/.git-flow-completion.sh.
I did't know this before, so I got an error like this:
WARNING: this script is deprecated, please see git-completion.zsh
**
/.git-flow-completion.sh:223: bad option: -t**
After I removed above two lines. it works.