Skip to content

Commit 0c5d83b

Browse files
matheustavaresgitster
authored andcommitted
grep: error out if --untracked is used with --cached
The options --untracked and --cached are not compatible, but if they are used together, grep just silently ignores --cached and searches the working tree. Error out, instead, to avoid any potential confusion. Signed-off-by: Matheus Tavares <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 773e25a commit 0c5d83b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

builtin/grep.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
11571157
if (!use_index && (untracked || cached))
11581158
die(_("--cached or --untracked cannot be used with --no-index"));
11591159

1160+
if (untracked && cached)
1161+
die(_("--untracked cannot be used with --cached"));
1162+
11601163
if (!use_index || untracked) {
11611164
int use_exclude = (opt_exclude < 0) ? use_index : !!opt_exclude;
11621165
hit = grep_directory(&opt, &pathspec, use_exclude, use_index);

0 commit comments

Comments
 (0)