git-grep: Bail out when -P is used with -F or -E
This patch makes git-grep die() when -P is used on command line together with -E/--extended-regexp or -F/--fixed-strings. This also makes it bail out when grep.extendedRegexp is enabled. But `git grep -G -P pattern` and `git grep -E -G -P pattern` still work because -G and -E set opts.regflags during parse_options() and there is no way to detect `-G` or `-E -G`. Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michał Kiedrowicz committed
May 9, 2011 at 23:52 UTC
258a6188496fe5131203905b6cd596af69312247
2 files changed
+19
-1
builtin/grep.c
+3
-1
@@ -925,9 +925,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
925
926
if (!opt.pattern_list)
927
die(_("no pattern given."));
928
+ if (opt.regflags != REG_NEWLINE && opt.pcre)
929
+ die(_("cannot mix --extended-regexp and --perl-regexp"));
930
if (!opt.fixed && opt.ignore_case)
931
opt.regflags |= REG_ICASE;
930
- if ((opt.regflags != REG_NEWLINE) && opt.fixed)
932
+ if ((opt.regflags != REG_NEWLINE || opt.pcre) && opt.fixed)
933
die(_("cannot mix --fixed-strings and regexp"));
934
935
#ifndef NO_PTHREADS
t/t7810-grep.sh
+16
@@ -637,4 +637,20 @@ test_expect_success LIBPCRE 'grep -P -w pattern' '
637
test_cmp expected actual
638
'
639
640
+test_expect_success LIBPCRE 'grep -P -F returns error' '
641
+ test_expect_code 128 git grep -P -F main
642
+'
643
+
644
+test_expect_success LIBPCRE 'grep -P -E returns error' '
645
+ test_expect_code 128 git grep -P -E main
646
+'
647
+
648
+test_expect_failure LIBPCRE 'grep -P -G returns error' '
649
+ test_expect_code 128 git grep -P -G main
650
+'
651
+
652
+test_expect_failure LIBPCRE 'grep -P -E -G returns error' '
653
+ test_expect_code 128 git grep -P -E -G main
654
+'
655
+
656
test_done