hub icon indicating copy to clipboard operation
hub copied to clipboard

bash completion incompatibility with git 2.30.0

Open yermulnik opened this issue 4 years ago • 12 comments

Command attempted: Bash completion doesn't trigger for git and hub commands (e.g. git p<tab><tab> doesn't suggest git subcommands but rather attempts a more general bash file/path completion)

What happened: With git got upgraded yesterday from 2.29.0 to 2.30.0 via brew bash completion within new shell invocation doesn't work anymore.

More info: hub version 2.14.2, OS: macOS Catalina 10.15.6 Deinstalling hub fixes the issue. There were no issues with git of 2.29.0 version. I'm trying to figure out whether it's only me or someone else is experiencing such issue too as turning off bash completion scripts sourcing and sourcing manually /usr/local/etc/bash_completion.d/git-completion.bash and then /usr/local/etc/bash_completion.d/hub.bash_completion.sh makes bash completion work as expected 😕

yermulnik avatar Dec 30 '20 17:12 yermulnik

Same experience here. I haven't checked the history of Git's completion script in the distribution, but it looks like—among other things—a wrapper function name changed from _git to __git.

Here's a fix that works for me, git and hub completion seem to work correctly independently and with the alias git='hub'.

$ diff -u /usr/local/Cellar/hub/2.14.2/etc/bash_completion.d/hub.bash_completion.sh{.orig,}
--- /usr/local/Cellar/hub/2.14.2/etc/bash_completion.d/hub.bash_completion.sh.orig	2021-01-05 21:11:04.000000000 +0700
+++ /usr/local/Cellar/hub/2.14.2/etc/bash_completion.d/hub.bash_completion.sh	2021-01-05 21:12:39.000000000 +0700
@@ -2,12 +2,12 @@
 # This script complements the completion script that ships with git.

 # If there is no git tab completion, but we have the _completion loader try to load it
-if ! declare -F _git > /dev/null && declare -F _completion_loader > /dev/null; then
+if ! declare -F __git > /dev/null && declare -F _completion_loader > /dev/null; then
   _completion_loader git
 fi

 # Check that git tab completion is available and we haven't already set up completion
-if declare -F _git > /dev/null && ! declare -F __git_list_all_commands_without_hub > /dev/null; then
+if declare -F __git > /dev/null && ! declare -F __git_list_all_commands_without_hub > /dev/null; then
   # Duplicate and rename the 'list_all_commands' function
   eval "$(declare -f __git_list_all_commands | \
         sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')"
@@ -382,6 +382,5 @@
   }

   # Enable completion for hub even when not using the alias
-  complete -o bashdefault -o default -o nospace -F _git hub 2>/dev/null \
-    || complete -o default -o nospace -F _git hub
+  __git_complete hub __git_main
 fi

Sharing here before I submit a PR because I'm not sure this is the "right way" to fix it going forward (and backward…), in particular the __git_complete function in git-completion.bash says

# This is NOT a public function; use at your own risk.

ches avatar Jan 05 '21 14:01 ches

Seeing same issue. hub completions work normally using the hub command (when adding the fix above), but when setting the alias it is not working.

Dunno if relevant, but there was recently a bash update as well. GNU bash, version 5.1.4(1)-release (x86_64-apple-darwin19.6.0)

ddaza avatar Jan 05 '21 18:01 ddaza

Yeah, looks like _git went away in https://github.com/git/git/commit/441ecdab37fefdacf32575a60aa523b2367c46f7

@ches I think your fix looks right to me.

cblecker avatar Jan 05 '21 21:01 cblecker

@ches Thanks for diving into this! Your diff looks good and you are welcome to submit it as a PR. Any chance that you can make it backwards-compatible, meaning that if _git is detected, use that; otherwise use __git?

mislav avatar Jan 06 '21 18:01 mislav

Having the same issue, uninstalled hub until it's fixed

simonweil avatar Jan 07 '21 10:01 simonweil

completion from git package:

$ complete -p git
complete -o bashdefault -o default -o nospace -F __git_wrap__git_main git

completion from hub package

$ complete -p git
complete -F _minimal git

msgongora avatar Jan 07 '21 18:01 msgongora

Sharing here before I submit a PR because I'm not sure this is the "right way" to fix it going forward (and backward…), in particular the __git_complete function in git-completion.bash says

# This is NOT a public function; use at your own risk.

FYI: __git_complete went public in https://github.com/git/git/commit/5a067ba9d04eebc92ad77f101b785219238f4f1e.

leonklingele avatar Jan 20 '21 10:01 leonklingele

Also it seems __git_list_all_commands is long gone: https://github.com/git/git/commit/3301d36b29467a05107340e4d9688ebf74335021. This seems to help: https://github.com/liskin/dotfiles/commit/6ca7aa90ed0efe11e69a8f431c1213b67222696a#diff-fb2d256214467c25c8e55a2180f2ea13de24f6d62529ebceb523bba0711403e1

liskin avatar Feb 01 '21 21:02 liskin

Any updates on when a resolution will be available? There might be an influx of attention to this issue with the recent git CVE.

https://github.blog/2021-03-09-git-clone-vulnerability-announced/

mattnelson avatar Mar 11 '21 16:03 mattnelson

Thanks for writing this up.

==> bash-completion@2: stable 2.11 (bottled), HEAD
==> git: stable 2.41.0 (bottled), HEAD
==> hub: stable 2.14.2 (bottled), HEAD

I noticed that https://github.com/scop/bash-completion introduces a few nuances to the problem:

eval $(/opt/homebrew/bin/brew shellenv)
. /opt/homebrew/etc/bash_completion.d/git-completion.bash
. /opt/homebrew/etc/bash_completion.d/hub.bash_completion.sh
complete | grep '\bgit\b'
# => complete -o bashdefault -o default -o nospace -F __git_wrap__git_main git
eval $(/opt/homebrew/bin/brew shellenv)
. "/opt/homebrew/etc/profile.d/bash_completion.sh"
complete | grep '\bgit\b'
# => complete -F _minimal git

kbrock avatar Jul 28 '23 17:07 kbrock

Also it seems __git_list_all_commands is long gone: git/git@3301d36. This seems to help: liskin/dotfiles@6ca7aa9#diff-fb2d256214467c25c8e55a2180f2ea13de24f6d62529ebceb523bba0711403e1

This is not a full solution AFAICT since internally git now depends on git --list-cmds=... which hub does wrap and extend, so some things work, but not everything seemingly? e.g. hub help <TAB> should likely complete custom commands but seemingly does not because hub --list-cmds=.... only lists its own when seeing "others"?

eli-schwartz avatar Oct 24 '23 04:10 eli-schwartz

Also it seems __git_list_all_commands is long gone: git/git@3301d36. This seems to help: liskin/dotfiles@6ca7aa9#diff-fb2d256214467c25c8e55a2180f2ea13de24f6d62529ebceb523bba0711403e1

This is not a full solution AFAICT since internally git now depends on git --list-cmds=... which hub does wrap and extend, so some things work, but not everything seemingly? e.g. hub help <TAB> should likely complete custom commands but seemingly does not because hub --list-cmds=.... only lists its own when seeing "others"?

I don't think hub help <Tab> ever did work, as there's no mention of help in https://github.com/mislav/hub/blob/master/etc/hub.bash_completion.sh, so it just falls back to git help completion.

liskin avatar Oct 24 '23 16:10 liskin