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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jun 21, 2016 at 5:14 PM, Charles Bailey <charles@xxxxxxxxxxxxx> wrote:
> From: Charles Bailey <cbailey32@xxxxxxxxxxxxx>
>
> 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 ...

> 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@xxxxxxxxx>
> Signed-off-by: Charles Bailey <cbailey32@xxxxxxxxxxxxx>
> ---
>
> 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 &&

> +       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.

> +'
> +
> +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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]