All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Armin Kunaschik <megabreit@googlemail.com>,
	Git List <git@vger.kernel.org>
Subject: Re: t3404 static check of bad SHA-1 failure
Date: Fri, 13 May 2016 12:52:44 -0700	[thread overview]
Message-ID: <xmqqwpmx91mb.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20160513182325.GB30700@sigill.intra.peff.net> (Jeff King's message of "Fri, 13 May 2016 14:23:26 -0400")

Jeff King <peff@peff.net> writes:

> On Fri, May 13, 2016 at 06:09:35PM +0200, Armin Kunaschik wrote:
>
>> in t3404 test 91 - static check of bad SHA-1 fails (with ksh) with a
>> syntax error in git-rebase.
>> git-rebase[6]: test: argument expected
>
> Here's a fix that covers these and another I found:
>
> -- >8 --
> Subject: [PATCH] always quote arguments to "test -z" in shell
>
> Modern shells are pretty forgiving about us doing:
>
>   test -z $foo
>
> If $foo is indeed empty, the test command will see only:
>
>   test -z
>
> and treat the missing argument as "yes, this is empty". But
> some older shells, reportedly ksh88, complain about the
> missing argument. We can be more portable by spelling this
> as:
>
>   test -z "$foo"
>
> so that "test" sees an empty argument, not a missing one.
>
> This covers all cases detected by:
>
>   git grep 'test -z [^"]'
>
> (though note that has a few false positives for tests which
> need an extra layer of quoting to do '\"').
>
> Reported-by: Armin Kunaschik <megabreit@googlemail.com>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> Actually, this misses the case in t4151 which already has a fix queued
> on pu. Arguably these should all just be squashed together (and I am
> happy, Junio, if you want to do so and leave Armin as the author of the
> new commit).

I _think_ "test -z" should succeed according to POSIX, because

 (1) it is not "test -z string" because it lacks string,

 (2) it is not any of the other "test -<option> thing" because -z,
    and

 (3) the only thing it matches in the supported form of "test" is
     "test <string>" that tests if the <string> is not the null
     string, and "-z" indeed is not the null string.

For the same reason, "test -n" succeeds.

But working around older/broken shells is easy and the resulting
script it more readable, so let's take this.  It makes the resulting
code easier to understand even when we know we run it under POSIX
shell.

Thanks.

>  git-rebase--interactive.sh | 4 ++--
>  git-stash.sh               | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> index 9ea3075..470413b 100644
> --- a/git-rebase--interactive.sh
> +++ b/git-rebase--interactive.sh
> @@ -866,12 +866,12 @@ add_exec_commands () {
>  # $3: the input filename
>  check_commit_sha () {
>  	badsha=0
> -	if test -z $1
> +	if test -z "$1"
>  	then
>  		badsha=1
>  	else
>  		sha1_verif="$(git rev-parse --verify --quiet $1^{commit})"
> -		if test -z $sha1_verif
> +		if test -z "$sha1_verif"
>  		then
>  			badsha=1
>  		fi
> diff --git a/git-stash.sh b/git-stash.sh
> index c7c65e2..57f9dc1 100755
> --- a/git-stash.sh
> +++ b/git-stash.sh
> @@ -185,7 +185,7 @@ store_stash () {
>  
>  	git update-ref --create-reflog -m "$stash_msg" $ref_stash $w_commit
>  	ret=$?
> -	test $ret != 0 && test -z $quiet &&
> +	test $ret != 0 && test -z "$quiet" &&
>  	die "$(eval_gettext "Cannot update \$ref_stash with \$w_commit")"
>  	return $ret
>  }

  reply	other threads:[~2016-05-13 19:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-13 16:09 t3404 static check of bad SHA-1 failure Armin Kunaschik
2016-05-13 18:23 ` Jeff King
2016-05-13 19:52   ` Junio C Hamano [this message]
2016-05-13 19:59     ` Jeff King
2016-05-13 20:02       ` Jeff King
2016-05-13 20:03       ` Junio C Hamano
2016-05-13 20:46         ` [PATCH 0/6] test -z/-n quoting fix + misc cleanups Jeff King
2016-05-13 20:47           ` [PATCH 1/6] t/lib-git-svn: drop $remote_git_svn and $git_svn_id Jeff King
2016-05-13 20:47           ` [PATCH 2/6] t9100,t3419: enclose all test code in single-quotes Jeff King
2016-05-13 20:47           ` [PATCH 3/6] t9107: use "return 1" instead of "exit 1" Jeff King
2016-05-13 22:59             ` Eric Wong
2016-05-13 23:45             ` Eric Sunshine
2016-05-13 23:47               ` Jeff King
2016-05-14 17:37                 ` Junio C Hamano
2016-05-14 19:51                   ` Jeff King
2016-05-13 20:47           ` [PATCH 4/6] t9107: switch inverted single/double quotes in test Jeff King
2016-05-13 20:47           ` [PATCH 5/6] t9103: modernize test style Jeff King
2016-05-13 20:47           ` [PATCH 6/6] always quote shell arguments to test -z/-n Jeff King
2016-05-13 22:09           ` [PATCH 0/6] test -z/-n quoting fix + misc cleanups Junio C Hamano

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=xmqqwpmx91mb.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=megabreit@googlemail.com \
    --cc=peff@peff.net \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.