Skip to content

Commit b2aa84c

Browse files
stefanbellergitster
authored andcommitted
grep: handle corrupt index files early
Any other caller of 'repo_read_index' dies upon a negative return of it, so grep should, too. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3013dff commit b2aa84c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

builtin/grep.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
480480
strbuf_addstr(&name, repo->submodule_prefix);
481481
}
482482

483-
repo_read_index(repo);
483+
if (repo_read_index(repo) < 0)
484+
die("index file corrupt");
484485

485486
for (nr = 0; nr < repo->index->cache_nr; nr++) {
486487
const struct cache_entry *ce = repo->index->cache[nr];

0 commit comments

Comments
 (0)