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

Re: [PATCH v2 2/2] grep: fix grepping for "intent to add" files

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 22, 2016, 01:13 UTC
Message-ID
<CAPig+cQ4CxRo460dcTJJtV_dPH8i5HC76_gpTv8attEZ8sdMZw@mail.gmail.com>
In-Reply-To
<20160621211412.28752-2-charles@hashpling.org>
On Tue, Jun 21, 2016 at 5:14 PM, Charles Bailey <charles@hashpling.org> wrote:
> From: Charles Bailey <cbailey32@bloomberg.net>
>
> This reverts commit 4d552005323034c1d6311796ac1074e9a4b4b57e and adds an
> alternative fix to maintain the -L --cached behavior.

It is common to provide some context along with the (shortened) commit ID. For instance:

    This reverts 4d55200 (grep: make it clear i-t-a entries are
    ignored, 2015-12-27) and adds ...
Show 9 quoted lines
> 4d5520053 caused 'git grep' to no longer find matches in new files in
> the working tree where the corresponding index entry had the "intent to
> add" bit set, despite the fact that these files are tracked.
> [...]
> Helped-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> Signed-off-by: Charles Bailey <cbailey32@bloomberg.net>
> ---
>
> Is "Helped-by" an appropriate attribution in this case?
Very much so.
> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
> @@ -1364,4 +1364,42 @@ test_expect_success 'grep --color -e A --and -e B -p with context' '
> +test_expect_success 'grep can find things only in the work tree' '
> +       touch work-tree-only &&
Avoid 'touch' if the timestamp of the file has no significance. Use '>' instead:
    >work-tree-only &&
Show 6 quoted lines
> +       git add work-tree-only &&
> +       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 &&
> +       git rm -f work-tree-only

If any statement before this cleanup code fails, then the cleanup will never take place (due to the &&-chain). To ensure cleanup regardless of test outcome, instead use test_when_finished() at the beginning of the test:

    test_when_finished "git rm -f work-tree-only" &&
Same applies to other added tests.
Show 31 quoted lines
> +'
> +
> +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 &&
> +       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 &&
> +       git rm -f intend-to-add
> +'
> +
> +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_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 &&
> +       git rm --cached cache-this
> +'
> +
> +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 &&
> +       git ls-files | grep -v "^intend-to-add\$" >expected &&
> +       git grep -L --cached "nonexistent_string" >actual &&
> +       test_cmp expected actual &&
> +       git rm -f intend-to-add
> +'
> +
>  test_done
Previous: Junio C HamanoNext: Duy Nguyen
Message 8 of 9 in “Fix duplicated test name”
  1. 1/2 Fix duplicated test nameCharles Bailey, Jun 21, 2016
  2. 2/2 grep: fix grepping for "intent to add" filesCharles Bailey, Jun 21, 2016
  3. Junio C HamanoJun 21, 2016
  4. Duy NguyenJun 22, 2016
  5. Junio C HamanoJun 22, 2016
  6. Duy NguyenJun 22, 2016
  7. Junio C HamanoJun 22, 2016
  8. Eric SunshineJun 22, 2016
  9. Duy NguyenJun 22, 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.