grep: do not diagnose misspelt revs with --no-index
authorJeff King <peff@peff.net>
Tue, 14 Feb 2017 06:08:09 +0000 (01:08 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Feb 2017 19:26:37 +0000 (11:26 -0800)
If we are using --no-index, then our arguments cannot be
revs in the first place. Not only is it pointless to
diagnose them, but if we are not in a repository, we should
not be trying to resolve any names.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c
t/t7810-grep.sh
index c4c63259412730b26ab599f433b252f069d17571..1454bef4966c7d2080544042e2b75642c73e6134 100644 (file)
@@ -1201,7 +1201,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
        if (!seen_dashdash) {
                int j;
                for (j = i; j < argc; j++)
-                       verify_filename(prefix, argv[j], j == i);
+                       verify_filename(prefix, argv[j], j == i && use_index);
        }
 
        parse_pathspec(&pathspec, 0,
index c051c7ee80801670dd33c564e57f9b44621468d6..0ff9f6cae8996b127379edea27cbda82a17b7982 100755 (executable)
@@ -1043,6 +1043,11 @@ test_expect_success 'grep --no-index prefers paths to revs' '
        test_cmp expect actual
 '
 
+test_expect_success 'grep --no-index does not "diagnose" revs' '
+       test_must_fail git grep --no-index o :1:hello.c 2>err &&
+       test_i18ngrep ! -i "did you mean" err
+'
+
 cat >expected <<EOF
 hello.c:int main(int argc, const char **argv)
 hello.c:       printf("Hello world.\n");