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

Git completion does not work #603

Closed
3 tasks done
helhum opened this issue Sep 6, 2021 · 5 comments
Closed
3 tasks done

Git completion does not work #603

helhum opened this issue Sep 6, 2021 · 5 comments

Comments

@helhum
Copy link

helhum commented Sep 6, 2021

Describe the bug

I have installed git-completion@2 version 2.11

I'm using the following code in my .bash_profile

if which brew > /dev/null && [ -f "$(brew --prefix)/etc/profile.d/bash_completion.sh" ]; then
    export BASH_COMPLETION_COMPAT_DIR="$(brew --prefix)/etc/bash_completion.d"
    source "$(brew --prefix)/etc/profile.d/bash_completion.sh";
fi;

However git completion still does not work.

To reproduce

When I add the following additionally (after the completion inclusion from above), git completion is working:

if type ___git_complete &> /dev/null && [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then
    ___git_complete git __git_main;
fi;

Expected behavior

I would expect that sourcing the /etc/profile.d/bash_completion.sh file should be enough
for git completion to work.

Versions (please complete the following information)

  • Operating system name/distribution and version: OSX 11.5.2
  • bash version, echo "$BASH_VERSION": 5.1.8(1)-release
  • bash-completion version, (IFS=.; echo "${BASH_COMPLETION_VERSINFO[*]}"): 2.11

Additional context

When I remove everything from /usr/local/Cellar/bash-completion@2/2.11/share/bash-completion/bash_completion
except the part that sources the additional completion files, then it works like expected

basically when the file only has:

# source compat completion directory definitions
compat_dir=${BASH_COMPLETION_COMPAT_DIR:-/usr/local/etc/bash_completion.d}
if [[ -d $compat_dir && -r $compat_dir && -x $compat_dir ]]; then
    for i in "$compat_dir"/*; do
        [[ ${i##*/} != @($_backup_glob|Makefile*|$_blacklist_glob) && -f \
        $i && -r $i ]] && . "$i"
    done
fi
unset compat_dir i _blacklist_glob

Since I'm not too familiar with how exactly git completion works, it is quite hard for me to debug further.

Let me know though if you need additional information

@scop
Copy link
Owner

scop commented Sep 7, 2021

Let me know though if you need additional information

Seems the final part of the bug report template was skipped:

See Troubleshooting section in README.md how to generate a debug trace, copy-paste it into a separate file and attach the file here.

@scop scop added the need info label Sep 7, 2021
@helhum
Copy link
Author

helhum commented Sep 7, 2021

Seems the final part of the bug report template was skipped:

I'm sorry. Here we go:
trace.txt

@scop
Copy link
Owner

scop commented Sep 8, 2021

Thanks. It's kind of hard to tell why exactly what you see happens, but the trace shows that on line 545 the git completion is sourced:

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

...and on line 662 the completion is installed:

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

...but on line 699 we start the dynamic search for a file from which the git completion would be loaded. That should not happen if the git completion is already installed. I wonder if there's some subshell at play here when the completions are loaded...

Also, line 699 looks weird to me:

declare -F _git

I wonder what would be the thing that is defining the _git function at that point? Is /usr/local/etc/bash_completion.d/hub.bash_completion.sh doing something funny?

@helhum
Copy link
Author

helhum commented Sep 10, 2021

I wonder what would be the thing that is defining the _git function at that point? Is /usr/local/etc/bash_completion.d/hub.bash_completion.sh doing something funny?

Yupp, thanks! Removing /usr/local/etc/bash_completion.d/hub.bash_completion.sh makes it all work again.

Thanks a bunch for your help!

@helhum helhum closed this as completed Sep 10, 2021
@helhum
Copy link
Author

helhum commented Sep 10, 2021

Related issue in hub: mislav/hub#2684

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants