Subject: Re: [PATCH v2] diff-lib: honor override_submodule_config flag bit

From: Junio C Hamano <[email-masked]>
Date: Wed, 14 Jun 2023 09:14:04 -0700

Josip Sokcevic <[email-masked]> writes:

> +add_submodule_commits_and_validate () {
> +	HASH=$(git rev-parse HEAD) &&
> +	git update-index --add --cacheinfo 160000,$HASH,sub &&
> +	git commit -m "create submodule" &&
> +	git ls-tree HEAD >output &&
> +	test_when_finished "rm -f output" &&
> +	grep "$HASH" output

If ls-tree exits with non-zero status, test_when_finished will not
be seen, and will not arrange output to be removed.  If we are going
to use test_when_finished to remove the file, we should do so before
we do anything that potentially creates the file.

The test with "grep" is overly loose, as I suspect that you won't be
happy to see the $HASH (i.e. the commit object name) just anywhere
in the output, but exactly where you placed it, i.e. at path "sub".

So it may make more sense to do the test like so:

	...
	git commit -m "create" &&

	echo "160000 commit $HASH	sub" >expect &&
	git ls-tree HEAD -- sub >actual &&
	test_cmp expect actual

If we were to add

	test_when_finished "rm -f expect actual" &&

we would do so immediately after "git commit" step, but I personally
do not think it is worth doing in this case.  These two files are
what many if not most of our test pieces use and having them as
untracked files is a norm.  Unless we have a need to have strict
control of what untracked files are in the working tree in later
tests, it is OK to leave these files around.

Other than that, looking much better.

Thanks.

> +}
> +
> +test_expect_success 'commit with staged submodule change' '
> +	add_submodule_commits_and_validate
> +'
> +
> +test_expect_success 'commit with staged submodule change with ignoreSubmodules dirty' '
> +	test_config diff.ignoreSubmodules dirty &&
> +	add_submodule_commits_and_validate
> +'
> +
> +test_expect_success 'commit with staged submodule change with ignoreSubmodules all' '
> +	test_config diff.ignoreSubmodules all &&
> +	add_submodule_commits_and_validate
> +'
> +
>  test_done