Re: [PATCH] grep: error out if --untracked is used with --cached
From: Elijah Newren <hidden>
Date: 2021-02-09 10:16:59
On Mon, Feb 8, 2021 at 11:47 AM Matheus Tavares [off-list ref] wrote:
quoted hunk ↗ jump to hunk
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 <redacted> --- builtin/grep.c | 3 +++ 1 file changed, 3 insertions(+)diff --git a/builtin/grep.c b/builtin/grep.c index ca259af441..392acf8cab 100644 --- a/builtin/grep.c +++ b/builtin/grep.c@@ -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); --2.29.2
Reviewed-by: Elijah Newren <redacted>