git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 3/3] t3700: add a test_mode_in_index helper function

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 1, 2016, 21:25 UTC
Message-ID
<xmqqvazkgp1c.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<579d0a83.4bd3c8e4.bm002@wupperonline.de>
Ingo Brückl <ib@wupperonline.de> writes:
Ingo Brückl <ib@wupperonline.de> writes:
Show 9 quoted lines
> 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.
Show 21 quoted lines
> 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.
Previous: Ingo Brückl
Message 2 of 2 in “t3700: add a test_mode_in_index helper function”
  1. 3/3 t3700: add a test_mode_in_index helper functionIngo Brückl, Jul 30, 2016
  2. Junio C HamanoAug 1, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.