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 <matheus.bernardino@usp.br> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matheus Tavares committed Feb 8, 2021 at 16:43 UTC 0c5d83b2484c027971b793c442d147979c7e1a04
1 file changed +3
builtin/grep.c
+3
@@ -1157,6 +1157,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1157 if (!use_index && (untracked || cached))
1158 die(_("--cached or --untracked cannot be used with --no-index"));
1159
1160 + if (untracked && cached)
1161 + die(_("--untracked cannot be used with --cached"));
1162 +
1163 if (!use_index || untracked) {
1164 int use_exclude = (opt_exclude < 0) ? use_index : !!opt_exclude;
1165 hit = grep_directory(&opt, &pathspec, use_exclude, use_index);