grep: fix grepping for "intent to add" files
commitb8e47d1acfa299299d1120241bdc6164867d1289
authorCharles Bailey <cbailey32@bloomberg.net>
Thu, 30 Jun 2016 10:13:48 +0000 (30 11:13 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Jul 2016 20:27:41 +0000 (1 13:27 -0700)
treee0d9a43a3ef944291537b73410006d70210ac302
parent89e64100f414e9b2a6458ca8401cfd9626990e13
grep: fix grepping for "intent to add" files

This reverts commit 4d5520053 (grep: make it clear i-t-a entries are
ignored, 2015-12-27) and adds an alternative fix to maintain the -L
--cached behavior.

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.

The content in the index of a file for which the "intent to add" bit is
set is considered indeterminate and not empty. For most grep queries we
want these to behave the same, however for -L --cached (files without a
match) we don't want to respond positively for "intent to add" files as
their contents are indeterminate. This is in contrast to files with
empty contents in the index (no lines implies no matches for any grep
query expression) which should be reported in the output of a grep -L
--cached invocation.

Add tests to cover this case and a few related cases which previously
lacked coverage.

Helped-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Charles Bailey <cbailey32@bloomberg.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c
t/t7810-grep.sh