hub icon indicating copy to clipboard operation
hub copied to clipboard

Auto-completion stop to work with Git version 2.18.0

Open arturoherrero opened this issue 6 years ago • 18 comments

I use macOS and Homebrew to install/update Git and hub.

After upgrade Git (brew upgrade git) from version 2.17.1 to 2.18.0 the auto-completion of the GitHub commands provided by hub (browse, ci-status, compare, etc...) stop to work in Bash.

Previous configuration with auto-completion working:

$ git --version
git version 2.17.1
hub version 2.4.0

Current configuration with auto-completion not working:

$ git --version
git version 2.18.0
hub version 2.4.0

I was able to reproduce the error in two different machines.

arturoherrero avatar Jun 26 '18 16:06 arturoherrero

Thank you for reporting! I can see the same.

mislav avatar Jun 26 '18 20:06 mislav

@mislav I'm still having this issue using hub 2.5.0:

$ hub version
git version 2.18.0
hub version 2.5.0
$ cat ~/.bash_profile
source /usr/local/etc/bash_completion.d/git-completion.bash
source /usr/local/etc/bash_completion.d/hub.bash_completion.sh

davishmcclurg avatar Jul 08 '18 21:07 davishmcclurg

It's working for me after install the new version of hub (2.5.0) with Homebrew.

arturoherrero avatar Jul 08 '18 22:07 arturoherrero

@davishmcclurg Unfortunately, the new workaround in hub 2.5.0 will only work when hub is aliased as git, even if the command invoked is hub. This is sub-optimal and PRs to improve this are welcome.

# without alias
$ hub p
pull      push

$ alias git=hub
$ hub p
pr        pull           pull-request   push

mislav avatar Jul 09 '18 09:07 mislav

Ok, that works. Thanks @mislav!

davishmcclurg avatar Jul 09 '18 19:07 davishmcclurg

Gonna reopen this until alias is no longer needed

mislav avatar Jul 10 '18 09:07 mislav

I did set alias git=hub. But, zsh compiletoin is not work.

Environment

❯ brew info zsh-completion
zsh-completions: stable 0.27.0, HEAD

❯ hub --version
git version 2.18.0
hub version 2.5.0

Should I talk about zsh-completion here?

engnakagawa avatar Aug 08 '18 10:08 engnakagawa

Should I talk about zsh-completion here?

zsh-completion is not relevant. But whether you have the Git-provided _git completion or the _zsh-provided one is. What is your zsh $fpath value, and is /usr/local/share/zsh/site-functions/_zsh present, and if so, what does it point to?

hub folks: what do you think about extending hub --version to examine its zsh environment and print an indication of which source of _zsh completion functions it's working with?

apjanke avatar Dec 22 '18 06:12 apjanke

Alias stops working for me recently.

$ type -f git
git is aliased to `hub'
$ hub pu
pull   push
$ hub pull-request -
-F   -M   -a   -b   -f   -h   -i   -l   -m

ushuz avatar Jun 21 '19 10:06 ushuz

Same here @ushuz

$ git --version
git version 2.22.0
hub version 2.12.0

arturoherrero avatar Jun 21 '19 10:06 arturoherrero

I get this with hub 2.12.0 and bash 3.2 on macOS:

$ alias git=hub
$ hub pu
pull           pull-request   push

@ushuz @arturoherrero Could you provide more information about your shell, OS, and how you installed hub and shell completions? Thanks

mislav avatar Jun 21 '19 17:06 mislav

Ah I see it now when I upgrade to git 2.22:

$ hub pu
pull   push

git must have changed something again in how they organize their shell completions. I think it's too risky that we build on top of their completion script, but then again I have no other ideas on how to hook into git's completions to inject extra hub stuff.

mislav avatar Jun 21 '19 17:06 mislav

Hotfix

alias __git=hub

FYI: https://github.com/git/git/blob/7c20df8/contrib/completion/git-completion.bash#L1029

yasuoza avatar Aug 05 '19 13:08 yasuoza

@yasuoza I suspect that will break some use cases because: https://github.com/git/git/blob/7c20df8/contrib/completion/git-completion.bash#L90

mgabeler-lee-6rs avatar Jan 24 '20 14:01 mgabeler-lee-6rs

Just in case this saves anyone time - these tips may seem obvious, but so many people including myself have been struggling to get this working.

  1. The alias workaround must occur before the sourcing of any git-completion script (e.g., in ~/.bash_profile).

  2. In your excitement, don't forget to source ~/.bash_profile (or whatever your shell config file is), or open a new terminal window before testing it out.

  3. With the alias workaround, you don't need anything like this:

if [ -f $(brew --prefix)/etc/bash_completion.d/hub.bash_completion.sh ]; then
  . $(brew --prefix)/etc/bash_completion.d/hub.bash_completion.sh
fi

@mislav Any update on #1995?

knightofiam avatar Nov 29 '20 01:11 knightofiam

Neither works here. This is macOS 11.4 on a Silicon M1 machine.

This is with home-brew in /opt/homebrew, and with

0:00 ~ > hub version
git version 2.31.1
hub version refs/heads/master

The hub version is the latest one from home-brew, I don't know why it is listed as "refs/heads/master", but apparently this is 2.14.2.

0:00 ~ > brew info hub
hub: stable 2.14.2 (bottled), HEAD

I had to disable asyncpreemptoff because of https://github.com/golang/go/issues/42700

radiospiel avatar Jun 21 '21 09:06 radiospiel

Also doesn't work with the very latest git version on home-brew (2.32.0). I accidentally also discovered that running hub, even without any arguments and any attempt to autocomplete, kills my iTerm session, when both __git and git are aliased to hub.

radiospiel avatar Jun 21 '21 09:06 radiospiel

hub --version
git version 2.32.1 (Apple Git-133)
hub version refs/heads/master

I have this

alias git=hub

when I tab on this

git [cursor]

it gives

git (eval):1: command not found: _hub
(eval):1: command not found: _hub
(eval):1: command not found: _hub

I don't know how to fix it

I am using mac os silicon M1

When i remove alias

git
zsh: do you wish to see all 154 possibilities (154 lines)?

git working fine

hub (eval):1: command not found: _hub
(eval):1: command not found: _hub
(eval):1: command not found: _hub

hub gives me an error.

I think this is related to zsh autocomplete but not sure how to solve it.

aquadesk avatar Aug 15 '22 17:08 aquadesk