Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- Documentation/git-grep.txt | 4 +++- builtin-grep.c | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index fa4d133..ee359c9 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -24,7 +24,9 @@ SYNOPSIS DESCRIPTION ----------- Look for specified patterns in the working tree files, blobs -registered in the index file, or given tree objects. +registered in the index file, or given tree objects. By default +it will search in the working tree files. When in sparse checkout +mode, it only searches checked-out files. OPTIONS diff --git a/builtin-grep.c b/builtin-grep.c index 3a51662..d5507d7 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -343,6 +343,8 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) continue; if (!pathspec_matches(paths, ce->name)) continue; + if (ce_no_checkout(ce)) + continue; name = ce->name; if (name[0] == '-') { int len = ce_namelen(ce); @@ -404,8 +406,11 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached) continue; hit |= grep_sha1(opt, ce->sha1, ce->name, 0); } - else + else { + if (ce_no_checkout(ce)) + continue; hit |= grep_file(opt, ce->name); + } if (ce_stage(ce)) { do { nr++; -- 1.6.0.96.g2fad1.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html