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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
May 14, 2018 at 18:04 UTC
b2aa84c789a032c60b81d6ad68527e3a9076b99b
1 file changed
+2
-1
builtin/grep.c
+2
-1
@@ -480,7 +480,8 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
480
strbuf_addstr(&name, repo->submodule_prefix);
481
}
482
483
- repo_read_index(repo);
483
+ if (repo_read_index(repo) < 0)
484
+ die("index file corrupt");
485
486
for (nr = 0; nr < repo->index->cache_nr; nr++) {
487
const struct cache_entry *ce = repo->index->cache[nr];