Skip to contentSkip to conversation

git-completion.zsh: do not clobber complete()

PATCH In review Mark Lodato 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-completion.zsh: do not clobber complete()

Previously, git-completion.zsh redefined complete() to make __git_complete() a no-op. This broke zsh's built-in bash completion compatibility layer (bashcompinit), which defines its own complete().

Sadly, since there is no way in zsh to restore the original defintion of complete() after bash-completion.bash is sourced, we must pass in a flag to git-completion.bash to change its behavior.

---
 contrib/completion/git-completion.bash | 1 +
 contrib/completion/git-completion.zsh  | 8 +-------
 2 files changed, 2 insertions(+), 7 deletions(-)
contrib/completion/git-completion.bash +1 -0
index 9525343..36aa8bb 100644
@@ -2650,6 +2650,7 @@ __git_func_wrap ()
 # This is NOT a public function; use at your own risk.
 __git_complete ()
 {
+	[[ -n $GIT_DO_NOT_CALL_COMPLETE ]] && return
 	local wrapper="__git_wrap${2}"
 	eval "$wrapper () { __git_func_wrap $2 ; }"
 	complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
contrib/completion/git-completion.zsh +1 -7
index 6b77968..9f68d63 100644
@@ -16,12 +16,6 @@
 #
 #  fpath=(~/.zsh $fpath)
 
-complete ()
-{
-	# do nothing
-	return 0
-}
-
 zstyle -T ':completion:*:*:git:*' tag-order && \
 	zstyle ':completion:*:*:git:*' tag-order 'common-commands'
 
@@ -39,7 +33,7 @@ if [ -z "$script" ]; then
 		test -f $e && script="$e" && break
 	done
 fi
-ZSH_VERSION='' . "$script"
+GIT_DO_NOT_CALL_COMPLETE=1 ZSH_VERSION='' . "$script"
 
 __gitcomp ()
 {
Signature · 1 line
1.9.0.rc1.175.g0b1dcb5
#1 lore raw
Quoted 3 lines · Mark Lodato

Previously, git-completion.zsh redefined complete() to make __git_complete() a no-op. This broke zsh's built-in bash completion compatibility layer (bashcompinit), which defines its own complete().

How exactly? I'm testing this and I don't see any problems. I run 'type -f _complete' and I get bashcompinit's complete, and the internal _complete() function is used only by the _git completion.

How have you configured this completion? Are you using the recommended instructions?

Signature · 1 line
Felipe Contreras
#2 lore raw
Quoted 8 lines · Felipe Contreras
Quoted 3 lines · Mark Lodato

Previously, git-completion.zsh redefined complete() to make __git_complete() a no-op. This broke zsh's built-in bash completion compatibility layer (bashcompinit), which defines its own complete().

How exactly? I'm testing this and I don't see any problems. I run 'type -f _complete' and I get bashcompinit's complete, and the internal _complete() function is used only by the _git completion.

Ah, it's complete(), not _complete(). I see the problem and I'll propose a similar patch.

Signature · 1 line
Felipe Contreras