Skip to content

Commit 52fd972

Browse files
felipecgitster
authored andcommitted
git-completion: fix regression in zsh support
The zsh support of git-completion script in contrib/ is broken for current versions of zsh, and does not notice when there's a subcommand. For example: "git log origi<TAB>" gives no completions because it would try to find a "git origi..." command. This will be fixed by zsh 4.3.12, but for now we can workaround it by backporting the same fix as zsh folks implemented. The problem started after commit v1.7.4-rc0~11^2~2 (bash: get --pretty=m<tab> completion to work with bash v4), which introduced _get_comp_words_by_ref() that comes from bash-completion[1] scripts, and relies on the 'words' variable. However, it turns out 'words' is a special variable used by zsh completion. From zshcompwid(1): [...] the parameters are reset on each function exit (including nested function calls from within the completion widget) to the values they had when the function was entered. As a result, subcommand words are lost. Ouch. This is now fixed in the latest master branch of zsh[2] by simply defining 'words' as hidden (typeset -h), which removes the special meaning inside the emulated bash function. So let's do the same. Jonathan Nieder helped on the commit message. [1] http://bash-completion.alioth.debian.org/ [2] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=e880604f029088f32fb1ecc39213d720ae526aaa Reported-by: Stefan Haller <[email protected]> Comments-by: SZEDER Gábor <[email protected]> Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec014ea commit 52fd972

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

contrib/completion/git-completion.bash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,10 @@ _git ()
27102710
if [[ -n ${ZSH_VERSION-} ]]; then
27112711
emulate -L bash
27122712
setopt KSH_TYPESET
2713+
2714+
# workaround zsh's bug that leaves 'words' as a special
2715+
# variable in versions < 4.3.12
2716+
typeset -h words
27132717
fi
27142718

27152719
local cur words cword
@@ -2761,6 +2765,10 @@ _gitk ()
27612765
if [[ -n ${ZSH_VERSION-} ]]; then
27622766
emulate -L bash
27632767
setopt KSH_TYPESET
2768+
2769+
# workaround zsh's bug that leaves 'words' as a special
2770+
# variable in versions < 4.3.12
2771+
typeset -h words
27642772
fi
27652773

27662774
__git_has_doubledash && return

0 commit comments

Comments
 (0)