grep: do not diagnose misspelt revs with --no-index
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>
Jeff King committed
Feb 14, 2017 at 01:08 UTC
73fc7b6b9be495e2cabc546ed240efd77adaa8eb
2 files changed
+6
-1
builtin/grep.c
+1
-1
@@ -1201,7 +1201,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1201
if (!seen_dashdash) {
1202
int j;
1203
for (j = i; j < argc; j++)
1204
- verify_filename(prefix, argv[j], j == i);
1204
+ verify_filename(prefix, argv[j], j == i && use_index);
1205
}
1206
1207
parse_pathspec(&pathspec, 0,
t/t7810-grep.sh
+5
@@ -1043,6 +1043,11 @@ test_expect_success 'grep --no-index prefers paths to revs' '
1043
test_cmp expect actual
1044
'
1045
1046
+test_expect_success 'grep --no-index does not "diagnose" revs' '
1047
+ test_must_fail git grep --no-index o :1:hello.c 2>err &&
1048
+ test_i18ngrep ! -i "did you mean" err
1049
+'
1050
+
1051
cat >expected <<EOF
1052
hello.c:int main(int argc, const char **argv)
1053
hello.c: printf("Hello world.\n");