git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git grep -F (fixed string) requires matching parenthesis?

From
Jeff King <peff@peff.net>
Date
Aug 13, 2019, 12:17 UTC
Message-ID
<20190813121733.GA10787@sigill.intra.peff.net>
In-Reply-To
<35477812-7889-4f32-85ac-d3da4e7ff902@www.fastmail.com>
On Tue, Aug 13, 2019 at 03:01:04PM +0900, nanaya wrote:
Show 6 quoted lines
> 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
Previous: nanayaNext: nanaya
Message 2 of 3 in “git grep -F (fixed string) requires matching parenthesis?”
  1. nanayaAug 13, 2019
  2. Jeff KingAug 13, 2019
  3. nanayaAug 13, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.