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