git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "SZEDER Gábor" <szeder.dev@gmail.com>
Cc: "Martin Ågren" <martin.agren@gmail.com>,
	"Alexander Pyhalov" <apyhalov@gmail.com>,
	"Git Mailing List" <git@vger.kernel.org>
Subject: Re: t7005-editor.sh failure
Date: Wed, 26 Sep 2018 12:16:16 -0700	[thread overview]
Message-ID: <xmqq36twkr27.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <xmqqlg7oktto.fsf@gitster-ct.c.googlers.com> (Junio C. Hamano's message of "Wed, 26 Sep 2018 11:16:35 -0700")

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

> SZEDER Gábor <szeder.dev@gmail.com> writes:
>
>> Having said all that, I didn't omit the quotes in 4362da078e with the
>> above in mind; in fact I tend to use quotes even when they are
>> unnecessary (e.g. in variable assignments: var="$1"), because unquoted
>> variables and command substitutions freak me out before I can think
>> through whether its safe to omit the quotes or not :)
>
> I quote >"$file" (but not var=$var) because the CodingGuidelines
> tells me to:
>
>  - Redirection operators should be written with space before, but no
>    space after them.  In other words, write 'echo test >"$file"'
>    instead of 'echo test> $file' or 'echo test > $file'.  Note that
>    even though it is not required by POSIX to double-quote the
>    redirection target in a variable (as shown above), our code does so
>    because some versions of bash issue a warning without the quotes.
>
> ;-)
>
>> Sidenote: this test should use the write_script helper to create this
>> editor script.
>
> Good suggestion.

Perhaps like this.

-- >8 --
Subject: t7005: make sure it passes under /bin/bash

In POSIX.1 compliant shells, you should be able to use a variable
reference without quoting for the target of the redirection, e.g.

	echo foo >$file
	echo bar >$1

without fear of substitution of $file getting split at $IFS.
However, some versions of bash throws a warning, especially when
they are invoked as /bin/bash (not as /bin/sh).  Those who build
with SHELL_PATH=/bin/bash and run t/t7005-editor.sh triggers an
unnecessary failure due to this issue.

Fix it by making sure that the generated "editor" script quotes the
target of redirection.  

While at it, update the way to creatd these scripts to use the
write_script wrapper, so that we do not have to worry about writing
the she-bang line and making the result executable.

Reported-by: Alexander Pyhalov <apyhalov@gmail.com>
Suggested-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t7005-editor.sh | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh
index b2ca77b338..b0c4cc4ca0 100755
--- a/t/t7005-editor.sh
+++ b/t/t7005-editor.sh
@@ -20,11 +20,9 @@ fi
 
 for i in GIT_EDITOR core_editor EDITOR VISUAL $vi
 do
-	cat >e-$i.sh <<-EOF
-	#!$SHELL_PATH
+	write_script "e-$i.sh" <<-EOF
 	echo "Edited by $i" >"\$1"
 	EOF
-	chmod +x e-$i.sh
 done
 
 if ! test -z "$vi"
@@ -112,8 +110,9 @@ do
 done
 
 test_expect_success 'editor with a space' '
-	echo "echo space >\$1" >"e space.sh" &&
-	chmod a+x "e space.sh" &&
+	write_script "e space.sh" <<-\EOF &&
+	echo space >"$1"
+	EOF
 	GIT_EDITOR="./e\ space.sh" git commit --amend &&
 	test space = "$(git show -s --pretty=format:%s)"
 

  reply	other threads:[~2018-09-26 19:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-26  6:52 t7005-editor.sh failure Alexander Pyhalov
2018-09-26  7:59 ` Martin Ågren
2018-09-26  9:00   ` Alexander Pyhalov
2018-09-26  9:52     ` Martin Ågren
2018-09-26 10:02       ` Alexander Pyhalov
2018-09-26 11:59       ` Eric Sunshine
2018-09-26 13:23         ` Martin Ågren
2018-09-26 12:11       ` SZEDER Gábor
2018-09-26 16:14         ` [PATCH] t7005-editor: quote filename to fix whitespace-issue Martin Ågren
2018-09-26 18:14           ` Taylor Blau
2018-09-26 19:21           ` Jeff King
2018-09-26 18:16         ` t7005-editor.sh failure Junio C Hamano
2018-09-26 19:16           ` Junio C Hamano [this message]
2018-09-26 19:29             ` Andrei Rybak
2018-09-27 20:53             ` SZEDER Gábor

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqq36twkr27.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=apyhalov@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=martin.agren@gmail.com \
    --cc=szeder.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).