Skip to content

Commit 73fc7b6

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0ffc06 commit 73fc7b6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
12011201
if (!seen_dashdash) {
12021202
int j;
12031203
for (j = i; j < argc; j++)
1204-
verify_filename(prefix, argv[j], j == i);
1204+
verify_filename(prefix, argv[j], j == i && use_index);
12051205
}
12061206

12071207
parse_pathspec(&pathspec, 0,

t/t7810-grep.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,11 @@ test_expect_success 'grep --no-index prefers paths to revs' '
10431043
test_cmp expect actual
10441044
'
10451045

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+
10461051
cat >expected <<EOF
10471052
hello.c:int main(int argc, const char **argv)
10481053
hello.c: printf("Hello world.\n");

0 commit comments

Comments
 (0)