summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorLibravatar SZEDER Gábor <szeder.dev@gmail.com>2018-06-11 11:20:53 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-06-12 10:13:44 -0700
commit61d48c66ea7ef8acc0dd1114e0f79f4250aead38 (patch)
tree5c57f1d400ac328533bf6e77a3c77680972efdd8 /contrib
parentcompletion: reduce overhead of clearing cached --options (diff)
downloadtgif-61d48c66ea7ef8acc0dd1114e0f79f4250aead38.tar.xz
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 <wolph@wol.ph> Reported-by: Dave Borowitz <dborowitz@google.com> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/completion/git-completion.bash5
-rw-r--r--contrib/completion/git-completion.zsh2
2 files changed, 5 insertions, 2 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 4ef59a51be..1ed6b97f8a 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3134,7 +3134,10 @@ __gitk_main ()
__git_complete_revlist
}
-if [[ -n ${ZSH_VERSION-} ]]; then
+if [[ -n ${ZSH_VERSION-} ]] &&
+ # Don't define these functions when sourced from 'git-completion.zsh',
+ # it has its own implementations.
+ [[ -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
autoload -U +X compinit && compinit
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index c3521fbfc4..78808b1c5e 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -39,7 +39,7 @@ if [ -z "$script" ]; then
test -f $e && script="$e" && break
done
fi
-ZSH_VERSION='' . "$script"
+GIT_SOURCING_ZSH_COMPLETION=y . "$script"
__gitcomp ()
{