Skip to content

Commit 61d48c6

Browse files
szedergitster
authored andcommitted
completion: correct zsh detection when run from git-completion.zsh
v2.18.0-rc0~90^2 (completion: reduce overhead of clearing cached --options, 2018-04-18) worked around a bug in bash's "set" builtin on MacOS by using compgen instead. It was careful to avoid breaking zsh by guarding this workaround with if [[ -n ${ZSH_VERSION-}} ]] Alas, this interacts poorly with git-completion.zsh's bash emulation: ZSH_VERSION='' . "$script" Correct it by instead using a new GIT_SOURCING_ZSH_COMPLETION shell variable to detect whether git-completion.bash is being sourced from git-completion.zsh. This way, the zsh variant is used both when run from zsh directly and when run via git-completion.zsh. Reproduction recipe: 1. cd git/contrib/completion && cp git-completion.zsh _git 2. Put the following in a new ~/.zshrc file: autoload -U compinit; compinit autoload -U bashcompinit; bashcompinit fpath=(~/src/git/contrib/completion $fpath) 3. Open zsh and "git <TAB>". With this patch: Triggers nice git-completion.bash based tab completion Without: contrib/completion/git-completion.bash:354: read-only variable: QISUFFIX zsh:12: command not found: ___main zsh:15: _default: function definition file not found _dispatch:70: bad math expression: operand expected at `/usr/bin/g...' Segmentation fault Reported-by: Rick van Hattem <[email protected]> Reported-by: Dave Borowitz <[email protected]> Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 94408dc commit 61d48c6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

contrib/completion/git-completion.bash

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3134,7 +3134,10 @@ __gitk_main ()
31343134
__git_complete_revlist
31353135
}
31363136

3137-
if [[ -n ${ZSH_VERSION-} ]]; then
3137+
if [[ -n ${ZSH_VERSION-} ]] &&
3138+
# Don't define these functions when sourced from 'git-completion.zsh',
3139+
# it has its own implementations.
3140+
[[ -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
31383141
echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
31393142

31403143
autoload -U +X compinit && compinit

contrib/completion/git-completion.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if [ -z "$script" ]; then
3939
test -f $e && script="$e" && break
4040
done
4141
fi
42-
ZSH_VERSION='' . "$script"
42+
GIT_SOURCING_ZSH_COMPLETION=y . "$script"
4343

4444
__gitcomp ()
4545
{

0 commit comments

Comments
 (0)