Skip to content

Commit

Permalink
git-grep: Bail out when -P is used with -F or -E
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michał Kiedrowicz authored and Junio C Hamano committed May 9, 2011
1 parent 8f852ce commit 258a618
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,9 +925,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)

if (!opt.pattern_list)
die(_("no pattern given."));
if (opt.regflags != REG_NEWLINE && opt.pcre)
die(_("cannot mix --extended-regexp and --perl-regexp"));
if (!opt.fixed && opt.ignore_case)
opt.regflags |= REG_ICASE;
if ((opt.regflags != REG_NEWLINE) && opt.fixed)
if ((opt.regflags != REG_NEWLINE || opt.pcre) && opt.fixed)
die(_("cannot mix --fixed-strings and regexp"));

#ifndef NO_PTHREADS
Expand Down
16 changes: 16 additions & 0 deletions t/t7810-grep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -637,4 +637,20 @@ test_expect_success LIBPCRE 'grep -P -w pattern' '
test_cmp expected actual
'

test_expect_success LIBPCRE 'grep -P -F returns error' '
test_expect_code 128 git grep -P -F main
'

test_expect_success LIBPCRE 'grep -P -E returns error' '
test_expect_code 128 git grep -P -E main
'

test_expect_failure LIBPCRE 'grep -P -G returns error' '
test_expect_code 128 git grep -P -G main
'

test_expect_failure LIBPCRE 'grep -P -E -G returns error' '
test_expect_code 128 git grep -P -E -G main
'

test_done

0 comments on commit 258a618

Please sign in to comment.