git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* git grep -F (fixed string) requires matching parenthesis?
@ 2019-08-13  6:01 nanaya
  2019-08-13 12:17 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: nanaya @ 2019-08-13  6:01 UTC (permalink / raw)
  To: git

Hi,

I observed this today:

$ git grep -F '('
fatal: unmatched parenthesis

Which doesn't make sense and I believe shouldn't happen.

$ git --version
git version 2.22.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git grep -F (fixed string) requires matching parenthesis?
  2019-08-13  6:01 git grep -F (fixed string) requires matching parenthesis? nanaya
@ 2019-08-13 12:17 ` Jeff King
  2019-08-13 12:33   ` nanaya
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2019-08-13 12:17 UTC (permalink / raw)
  To: nanaya; +Cc: git

On Tue, Aug 13, 2019 at 03:01:04PM +0900, nanaya wrote:

> I observed this today:
> 
> $ git grep -F '('
> fatal: unmatched parenthesis
> 
> Which doesn't make sense and I believe shouldn't happen.

At first glance this looks like we're feeding a fixed-string pattern to
the regex compiler, which would indeed be a bug.

But I think it's actually happening at a level above that. git-grep
supports multiple patterns, which can be joined with --and, --or, --not,
etc. And they can be grouped with parentheses.

What you're seeing is the argument parser thinking your '(' is part of
the construction of a boolean match formula, and complaining about the
lack of closing ')'. You can use "-e" to make it clear that it's a
pattern (just as you'd need to for a pattern that starts with "-"):

  git grep -F -e '('

So I think everything is working as designed, though I admit the
implication was slightly surprising to me (and note that it only happens
with that _specific_ pattern; something like "(foo" would not be matched
by the option parser).

-Peff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git grep -F (fixed string) requires matching parenthesis?
  2019-08-13 12:17 ` Jeff King
@ 2019-08-13 12:33   ` nanaya
  0 siblings, 0 replies; 3+ messages in thread
From: nanaya @ 2019-08-13 12:33 UTC (permalink / raw)
  To: Jeff King; +Cc: git



On Tue, Aug 13, 2019, at 21:17, Jeff King wrote:
> But I think it's actually happening at a level above that. git-grep
> supports multiple patterns, which can be joined with --and, --or, --not,
> etc. And they can be grouped with parentheses.
> 
> What you're seeing is the argument parser thinking your '(' is part of
> the construction of a boolean match formula, and complaining about the
> lack of closing ')'. You can use "-e" to make it clear that it's a
> pattern (just as you'd need to for a pattern that starts with "-"):
> 
>   git grep -F -e '('
> 
> So I think everything is working as designed, though I admit the
> implication was slightly surprising to me (and note that it only happens
> with that _specific_ pattern; something like "(foo" would not be matched
> by the option parser).
> 

Thanks. That was confusing (and the error message didn't help). I've always assumed the grep is similar to posix grep so it was weird the same syntax work for fgrep but not git-grep -F.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-13  6:01 git grep -F (fixed string) requires matching parenthesis? nanaya
2019-08-13 12:17 ` Jeff King
2019-08-13 12:33   ` nanaya

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox