path: root/builtin/grep.c
diff options
authorCharles Bailey <>2016-06-30 10:13:48 (GMT)
committerJunio C Hamano <>2016-07-01 20:27:41 (GMT)
commitb8e47d1acfa299299d1120241bdc6164867d1289 (patch)
treee0d9a43a3ef944291537b73410006d70210ac302 /builtin/grep.c
parent89e64100f414e9b2a6458ca8401cfd9626990e13 (diff)
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 <> Signed-off-by: Charles Bailey <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/grep.c')
1 files changed, 2 insertions, 2 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index f508179..08548cc 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -375,7 +375,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
for (nr = 0; nr < active_nr; nr++) {
const struct cache_entry *ce = active_cache[nr];
- if (!S_ISREG(ce->ce_mode) || ce_intent_to_add(ce))
+ if (!S_ISREG(ce->ce_mode))
if (!ce_path_match(ce, pathspec, NULL))
@@ -385,7 +385,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
* cache version instead
if (cached || (ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) {
- if (ce_stage(ce))
+ if (ce_stage(ce) || ce_intent_to_add(ce))
hit |= grep_sha1(opt, ce->sha1, ce->name, 0, ce->name);