Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash completion incompatibility with git 2.30.0 #2684

Open
yermulnik opened this issue Dec 30, 2020 · 12 comments · May be fixed by #2948 or #3342
Open

bash completion incompatibility with git 2.30.0 #2684

yermulnik opened this issue Dec 30, 2020 · 12 comments · May be fixed by #2948 or #3342
Labels

Comments

@yermulnik
Copy link

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 yermulnik added the bug label Dec 30, 2020
@ches
Copy link

ches commented Jan 5, 2021

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.

@ddaza
Copy link

ddaza commented Jan 5, 2021

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)

@cblecker
Copy link

cblecker commented Jan 5, 2021

Yeah, looks like _git went away in git/git@441ecda

@ches I think your fix looks right to me.

@mislav
Copy link
Owner

mislav commented Jan 6, 2021

@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?

@simonweil
Copy link

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

@msgongora
Copy link

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

ikuwow added a commit to ikuwow/dotfiles that referenced this issue Jan 17, 2021
@leonklingele
Copy link

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 git/git@5a067ba.

dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Jan 28, 2021
Hub break git completions, see mislav/hub#2684
liskin added a commit to liskin/dotfiles that referenced this issue Feb 1, 2021
@liskin
Copy link

liskin commented Feb 1, 2021

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

danemacmillan added a commit to danemacmillan/dotfiles that referenced this issue Feb 9, 2021
This eliminates some cruft for supporting bash_completion v1, which is
really unnecessary at this point. Even servers used within all
infrastructure I manage are modern and support v2, like CentOS 7.

Note that this work was done in response to debugging why git
completions were not working. In the end, it had to do with the
installation of GitHub's hub utility: mislav/hub#2684. Ultimatelty,
hub was removed until that is fixed.
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 16, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 17, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 17, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 17, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 18, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Feb 22, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Mar 15, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Mar 15, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Mar 16, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Mar 16, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Mar 16, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Mar 16, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 2, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 2, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 3, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Aug 4, 2021
Hub break git completions, see mislav/hub#2684
myobie added a commit to myobie/dot-files that referenced this issue Mar 24, 2022
Until the bash completion issue is fixed mislav/hub#2684
@cblecker cblecker linked a pull request Mar 28, 2022 that will close this issue
@kbrock
Copy link
Contributor

kbrock commented Jul 28, 2023

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

@eli-schwartz
Copy link
Contributor

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"?

@liskin
Copy link

liskin commented Oct 24, 2023

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.

dylanpinn added a commit to dylanpinn/dotfiles that referenced this issue Jul 8, 2024
Hub break git completions, see mislav/hub#2684
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
13 participants