]> git.ipfire.org Git - thirdparty/git.git/commitdiff
grep: error out if --untracked is used with --cached
authorMatheus Tavares <matheus.bernardino@usp.br>
Mon, 8 Feb 2021 19:43:28 +0000 (16:43 -0300)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Feb 2021 20:39:06 +0000 (12:39 -0800)
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>
builtin/grep.c

index ca259af44163184d409ddfaa6f5b9a2d4567d8f8..392acf8cabedd22b90a44be1a14c96f03fe4cbc7 100644 (file)
@@ -1157,6 +1157,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
        if (!use_index && (untracked || cached))
                die(_("--cached or --untracked cannot be used with --no-index"));
 
+       if (untracked && cached)
+               die(_("--untracked cannot be used with --cached"));
+
        if (!use_index || untracked) {
                int use_exclude = (opt_exclude < 0) ? use_index : !!opt_exclude;
                hit = grep_directory(&opt, &pathspec, use_exclude, use_index);