git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ingo Brückl" <ib@wupperonline.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v3 3/3] t3700: add a test_mode_in_index helper function
Date: Mon, 01 Aug 2016 14:25:19 -0700	[thread overview]
Message-ID: <xmqqvazkgp1c.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <579d0a83.4bd3c8e4.bm002@wupperonline.de> ("Ingo Brückl"'s message of "Sat, 30 Jul 2016 22:13:54 +0200")

Ingo Brückl <ib@wupperonline.de> writes:

Ingo Brückl <ib@wupperonline.de> writes:

> The case statement to check the file mode of a staged file appears
> a number of times.
>
> Simplify the test by utilizing a test_mode_in_index helper function.
>
> Signed-off-by: Ingo Brückl <ib@wupperonline.de>
> ---
>  t/t3700-add.sh | 54 ++++++++++++++++++++++--------------------------------
>  1 file changed, 22 insertions(+), 32 deletions(-)

Nice.

> diff --git a/t/t3700-add.sh b/t/t3700-add.sh
> index 1fa5dfd..7b98483 100755
> --- a/t/t3700-add.sh
> +++ b/t/t3700-add.sh
> @@ -7,6 +7,20 @@ test_description='Test of git add, including the -- option.'
>
>  . ./test-lib.sh
>
> +# Test the file mode "$1" of the file "$2" in the index.
> +test_mode_in_index () {
> +	case "$(git ls-files --stage "$2")" in
> +		$1\ *"$2")
> +			echo pass
> +			;;
> +		*)
> +			echo fail
> +			git ls-files --stage "$2"
> +			return 1
> +			;;
> +	esac
> +}

This case/esac is misindented, but no need to resend; I can fix it
up trivially while queuing the patches.  It may be both easier to
read and more robust to tweak the pattern like this, though:

# Test the file mode "$1" of the file "$2" in the index.
test_mode_in_index () {
	case "$(git ls-files --stage "$2")" in
	"$1 "*"	$2")
		echo pass
		;;
	*)
		echo fail
		git ls-files --stage "$2"
		return 1
		;;
	esac
}

Thanks.

      reply	other threads:[~2016-08-01 21:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-30 20:13 [PATCH v3 3/3] t3700: add a test_mode_in_index helper function Ingo Brückl
2016-08-01 21:25 ` Junio C Hamano [this message]

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=xmqqvazkgp1c.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=ib@wupperonline.de \
    /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).