git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 (for maint)] git-completion: fix regression in zsh support
@ 2011-05-10 12:20 Felipe Contreras
  2011-05-10 17:17 ` Junio C Hamano
  2011-05-10 22:16 ` Jonathan Nieder
  0 siblings, 2 replies; 6+ messages in thread
From: Felipe Contreras @ 2011-05-10 12:20 UTC (permalink / raw)
  To: git; +Cc: SZEDER Gábor, Jonathan Nieder, Felipe Contreras

Right now zsh is quite broken; the completion doesn't 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. The
issue would be gone in zsh 4.3.12, but for now we can workaround it by
porting the same fix.

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.

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

v2: fix _gitk() too as Szeder suggested.

v3: improve commit message as Jonathan Nieder suggested.
    Also, improve comments.

v4: more commit message improvements

v5: even more commit message improvements from Jonathan's version

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 840ae38..a7d20df 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 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 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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-05-10 22:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-10 12:20 [PATCH v5 (for maint)] git-completion: fix regression in zsh support Felipe Contreras
2011-05-10 17:17 ` Junio C Hamano
2011-05-10 17:36   ` Felipe Contreras
2011-05-10 18:27     ` Junio C Hamano
2011-05-10 22:18       ` Jonathan Nieder
2011-05-10 22:16 ` Jonathan Nieder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).