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

git-grep's "-z" option misbehaves in subdirectory

From
Greg Hurrell <greg@hurrell.net>
Date
Apr 13, 2020, 21:55 UTC
Message-ID
<CAOyLvt9=wRfpvGGJqLMi7=wLWu881pOur8c9qNEg+Xqhf8W2ww@mail.gmail.com>
Hi,

It seems that `git-grep -lz` behaves differently depending on whether it is inside a subdirectory:

$ mkdir demo $ cd demo $ git init $ echo content > 'an "example".txt' $ mkdir nested $ echo content > 'nested/other "example".txt' $ git add . $ git commit -m Initial $ git grep -lz content an "example".txt^@nested/other "example".txt^@

Note that, as expected, the files are NUL-terminated and not wrapped in quotes. ("^@" represents NUL byte.)

$ cd nested $ git grep -lz content "other \"example\".txt"^@

As soon as we move into a subdirectory, files are wrapped in quotes and contain escapes, despite the "-z" switch. git-ls-files doesn't exhibit this behavior:

$ git ls-files -z other "example".txt

And git-grep doesn't either, if you pass "--full-name":

$ git grep -lz --full-name content nested/other "example".txt^@

Seeing this on Git v2.25.0 on macOS (10.13.6).
Does this seem like a bug, or expected behavior?

Cheers, Greg

Next: Junio C Hamano
Message 1 of 13 in “git-grep's "-z" option misbehaves in subdirectory”
  1. Greg HurrellApr 13, 2020
  2. Junio C HamanoApr 13, 2020
  3. Matheus Tavares, Apr 14, 2020
  4. Matheus Tavares BernardinoApr 16, 2020
  5. Junio C HamanoApr 16, 2020
  6. grep: follow conventions for printing paths w/ unusual charsMatheus Tavares, Apr 17, 2020
  7. Junio C HamanoApr 17, 2020
  8. Matheus Tavares BernardinoApr 17, 2020
  9. Junio C HamanoApr 17, 2020
  10. Johannes SchindelinApr 18, 2020
  11. Johannes SchindelinApr 18, 2020
  12. Matheus Tavares BernardinoApr 19, 2020
  13. grep: follow conventions for printing paths w/ unusual charsMatheus Tavares, Apr 19, 2020

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.