diff --git a/builtin/grep.c b/builtin/grep.c index 5a282c4d06..081e1b57a1 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -1154,6 +1154,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix) const char *arg = argv[i]; unsigned char sha1[20]; struct object_context oc; + if (!strcmp(arg, "--")) { + i++; + seen_dashdash = 1; + break; + } /* Is it a rev? */ if (!get_sha1_with_context(arg, 0, sha1, &oc)) { struct object *object = parse_object_or_die(sha1, arg); @@ -1162,10 +1167,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix) add_object_array_with_path(object, arg, &list, oc.mode, oc.path); continue; } - if (!strcmp(arg, "--")) { - i++; - seen_dashdash = 1; - } break; } diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 19f0108f8a..2c1f7373e6 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -982,6 +982,21 @@ test_expect_success 'grep -e -- -- path' ' test_cmp expected actual ' +test_expect_success 'grep --no-index pattern -- path' ' + rm -fr non && + mkdir -p non/git && + ( + GIT_CEILING_DIRECTORIES="$(pwd)/non" && + export GIT_CEILING_DIRECTORIES && + cd non/git && + echo hello >hello && + echo goodbye >goodbye && + echo hello:hello >expect && + git grep --no-index o -- hello >actual && + test_cmp expect actual + ) +' + cat >expected <