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

Re: [PATCH v3 3/3] grep: fix grepping for "intent to add" files

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 1, 2016, 20:34 UTC
Message-ID
<xmqqpoqxw11d.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160630101348.15665-4-charles@hashpling.org>
Charles Bailey <charles@hashpling.org> writes:
> +test_expect_success 'grep can find things only in the work tree' '
> +	: >work-tree-only &&
> +	git add work-tree-only &&
> +	test_when_finished "git rm -f work-tree-only" &&

It is better to have the test_when_finished before "git add", and possibly before the creation of the test file.

It is not worth a reroll and it is perfectly fine to leave it as a low-hanging-fruit for later clean-up material, because this test is not about catchign a "git add" that suddenly starts failing in a strange way (e.g. adds to the index but exits with non-zero).

Same comment for the use of test_when_finished in the remainder of the patch.

Thanks.
Show 55 quoted lines
> +	echo "find in work tree" >work-tree-only &&
> +	git grep --quiet "find in work tree" &&
> +	test_must_fail git grep --quiet --cached "find in work tree" &&
> +	test_must_fail git grep --quiet "find in work tree" HEAD
> +'
> +
> +test_expect_success 'grep can find things only in the work tree (i-t-a)' '
> +	echo "intend to add this" >intend-to-add &&
> +	git add -N intend-to-add &&
> +	test_when_finished "git rm -f intend-to-add" &&
> +	git grep --quiet "intend to add this" &&
> +	test_must_fail git grep --quiet --cached "intend to add this" &&
> +	test_must_fail git grep --quiet "intend to add this" HEAD
> +'
> +
> +test_expect_success 'grep does not search work tree with assume unchanged' '
> +	echo "intend to add this" >intend-to-add &&
> +	git add -N intend-to-add &&
> +	git update-index --assume-unchanged intend-to-add &&
> +	test_when_finished "git rm -f intend-to-add" &&
> +	test_must_fail git grep --quiet "intend to add this" &&
> +	test_must_fail git grep --quiet --cached "intend to add this" &&
> +	test_must_fail git grep --quiet "intend to add this" HEAD
> +'
> +
> +test_expect_success 'grep can find things only in the index' '
> +	echo "only in the index" >cache-this &&
> +	git add cache-this &&
> +	rm cache-this &&
> +	test_when_finished "git rm --cached cache-this" &&
> +	test_must_fail git grep --quiet "only in the index" &&
> +	git grep --quiet --cached "only in the index" &&
> +	test_must_fail git grep --quiet "only in the index" HEAD
> +'
> +
> +test_expect_success 'grep does not report i-t-a with -L --cached' '
> +	echo "intend to add this" >intend-to-add &&
> +	git add -N intend-to-add &&
> +	test_when_finished "git rm -f intend-to-add" &&
> +	git ls-files | grep -v "^intend-to-add\$" >expected &&
> +	git grep -L --cached "nonexistent_string" >actual &&
> +	test_cmp expected actual
> +'
> +
> +test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '
> +	echo "intend to add this" >intend-to-add-assume-unchanged &&
> +	git add -N intend-to-add-assume-unchanged &&
> +	test_when_finished "git rm -f intend-to-add-assume-unchanged" &&
> +	git update-index --assume-unchanged intend-to-add-assume-unchanged &&
> +	git ls-files | grep -v "^intend-to-add-assume-unchanged\$" >expected &&
> +	git grep -L "nonexistent_string" >actual &&
> +	test_cmp expected actual
> +'
> +
>  test_done
Previous: Charles BaileyNext: Charles Bailey
Message 3 of 7 in “Grepping with intent to add”
  1. 0/3 Grepping with intent to addCharles Bailey, Jun 30, 2016
  2. 3/3 grep: fix grepping for "intent to add" filesCharles Bailey, Jun 30, 2016
  3. Junio C HamanoJul 1, 2016
  4. 2/3 t7810-grep.sh: fix a whitespace inconsistencyCharles Bailey, Jun 30, 2016
  5. 1/3 t7810-grep.sh: fix duplicated test nameCharles Bailey, Jun 30, 2016
  6. Junio C HamanoJul 1, 2016
  7. Junio C HamanoJul 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.