public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Matthieu Moy <Matthieu.Moy@imag•fr>
Cc: git@vger•kernel.org, Manlio Perillo <manlio.perillo@gmail•com>
Subject: Re: [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility
Date: Mon, 11 Mar 2013 09:41:40 -0700	[thread overview]
Message-ID: <7vobepany3.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <7v38w1c3ms.fsf@alter.siamese.dyndns.org> (Junio C. Hamano's message of "Mon, 11 Mar 2013 09:17:31 -0700")

Junio C Hamano <gitster@pobox•com> writes:

> After all, I was right when I said that some implementations may get
> it wrong and we shouldn't use the construct X-<.
>
>> These two instances seem to be the only ones in the file.
>>
>> I'm not sure whether the 2>/dev/null would be needed for the command
>> on the RHS of the && too (git ls-files and git diff-index).
>
> It would not hurt to discard their standard error.

So here is an updated based on your patch.

-- >8 --
From: Matthieu Moy <Matthieu.Moy@imag•fr>
Date: Mon, 11 Mar 2013 13:21:27 +0100
Subject: [PATCH] git-completion.bash: zsh does not implement function
 redirection correctly

A recent change added functions whose entire standard error stream
is redirected to /dev/null using a construct that is valid POSIX.1
but is not widely used:

	funcname () {
		funcbody
	} 2>/dev/null

Even though this file is "git-completion.bash", zsh completion
support dot-sources it (instead of asking bash to grok it like tcsh
completion does), and zsh does not implement this redirection
correctly.

With zsh, trying to complete an inexistant directory gave this:

  git add no-such-dir/__git_ls_files_helper:cd:2: no such file or directory: no-such-dir/

It is easy to work around by refraining from using this construct.
The correct thing to do in the longer term may be to stop dot-sourcing
the source meant for bash into zsh, but this patch should suffice as
a band-aid in the meantime.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag•fr>
Signed-off-by: Junio C Hamano <gitster@pobox•com>
---
 contrib/completion/git-completion.bash | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 51b8b3b..3d4cc7c 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -300,8 +300,8 @@ __git_index_file_list_filter ()
 __git_ls_files_helper ()
 {
 	# NOTE: $2 is not quoted in order to support multiple options
-	cd "$1" && git ls-files --exclude-standard $2
-} 2>/dev/null
+	cd "$1" 2>/dev/null && git ls-files --exclude-standard $2 2>/dev/null
+}
 
 
 # Execute git diff-index, returning paths relative to the directory
@@ -309,8 +309,8 @@ __git_ls_files_helper ()
 # specified in the second argument.
 __git_diff_index_helper ()
 {
-	cd "$1" && git diff-index --name-only --relative "$2"
-} 2>/dev/null
+	cd "$1" 2>/dev/null && git diff-index --name-only --relative "$2" 2>/dev/null
+}
 
 # __git_index_files accepts 1 or 2 arguments:
 # 1: Options to pass to ls-files (required).
-- 
1.8.2-rc3-271-g00e868e

  reply	other threads:[~2013-03-11 16:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-11 12:21 [RFC/PATCH] git-completion.bash: remove bashism to fix ZSH compatibility Matthieu Moy
2013-03-11 16:17 ` Junio C Hamano
2013-03-11 16:41   ` Junio C Hamano [this message]
2013-03-11 16:47     ` Matthieu Moy
2013-03-11 17:01       ` Junio C Hamano
2013-03-11 17:12         ` Manlio Perillo
2013-03-11 17:09   ` Manlio Perillo
2013-03-11 17:23     ` Junio C Hamano
2013-03-11 17:48       ` Matthieu Moy
2013-03-11 18:09         ` Junio C Hamano
2013-03-11 18:19           ` Paul Smith
2013-03-11 19:09           ` Manlio Perillo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vobepany3.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox$(echo .)com \
    --cc=Matthieu.Moy@imag$(echo .)fr \
    --cc=git@vger$(echo .)kernel.org \
    --cc=manlio.perillo@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox