git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 (for maint)] git-completion: fix zsh support

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 9, 2011, 22:14 UTC
Message-ID
<1304979299-6496-1-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<BANLkTikkhryMa69DSx4EAYjw+aar4icKcQ@mail.gmail.com>

It turns out 'words' is a special variable used by zsh completion. This was not isolated correctly in zsh's bash completion emulation, so by trying to set it as 'local' in git's completion, unexpected results occur; assignations are not propagated to outer levels in the call stack.

This is now fixed in the latest master branch of zsh[1] by simply defining 'words' as hidden (typeset -h), which removes the special meaning inside the emulated bash function. It probably won't be released until version 4.3.12.

In the meantime, we can workaround the issue by doing the same; defining words as hidden (typeset -h) as soon as possible.

Right now zsh is completely broken after commit da48616 (bash: get --pretty=m<tab> completion to work with bash v4), which introduced _get_comp_words_by_ref() that comes from bash-completion[2] scripts, and relies on the 'words' variable to behave like any normal variable.

[1] http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=commitdiff;h=e880604f029088f32fb1ecc39213d720ae526aaa [2] http://bash-completion.alioth.debian.org/

Comments-by: SZEDER Gábor <szeder@ira.uka.de>
Comments-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

This patch is meant for the maintenance branch, so Szeder's patches are not required.

v2: fix _gitk() too as Szeder suggested.
v3: improve commit message as Jonathan Nieder suggested.
    Also, improve comments.
v4: more commit message improvements
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 840ae38..763f145 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2710,6 +2710,10 @@ _git ()
 	if [[ -n ${ZSH_VERSION-} ]]; then
 		emulate -L bash
 		setopt KSH_TYPESET
+
+		# workaround zsh's bashinit's bug that leaves 'words' as a
+		# special variable in versions < 4.3.12
+		typeset -h words
 	fi
 
 	local cur words cword
@@ -2761,6 +2765,10 @@ _gitk ()
 	if [[ -n ${ZSH_VERSION-} ]]; then
 		emulate -L bash
 		setopt KSH_TYPESET
+
+		# workaround zsh's bashinit's bug that leaves 'words' as a
+		# special variable in versions < 4.3.12
+		typeset -h words
 	fi
 
 	__git_has_doubledash && return
-- 
1.7.5.1.1.g638e6
Previous: Felipe ContrerasNext: Jonathan Nieder
Message 4 of 19 in “git-completion: fix zsh support”
  1. git-completion: fix zsh supportFelipe Contreras, May 9, 2011
  2. Jonathan NiederMay 9, 2011
  3. Felipe ContrerasMay 9, 2011
  4. git-completion: fix zsh supportFelipe Contreras, May 9, 2011
  5. Jonathan NiederMay 9, 2011
  6. Felipe ContrerasMay 9, 2011
  7. Jonathan NiederMay 9, 2011
  8. Felipe ContrerasMay 9, 2011
  9. Junio C HamanoMay 9, 2011
  10. Jonathan NiederMay 9, 2011
  11. 0/2 git-completion: fix zsh supportJonathan Nieder, May 10, 2011
  12. 1/2 completion: suppress zsh's special 'words' variableJonathan Nieder, May 10, 2011
  13. Jonathan NiederMay 10, 2011
  14. Felipe ContrerasMay 10, 2011
  15. Felipe ContrerasMay 10, 2011
  16. 2/2 completion: move private shopt shim for zsh to __git_ namespaceJonathan Nieder, May 10, 2011
  17. Felipe ContrerasMay 10, 2011
  18. Jonathan NiederMay 10, 2011
  19. Felipe ContrerasMay 10, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.