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

Re: bug?: git grep HEAD with exclude in pathspec not taken into account

From
CBChristophe Bliard <christophe.bliard@trux.info>
Date
Oct 24, 2018, 14:53 UTC
Message-ID
<CAGOLd-5Gbt6fQTvm+7018uX+8WF7NUWpa1sFWAg3-5bxtmOt-Q@mail.gmail.com>
In-Reply-To
<CAGOLd-7Hi+tssj4ozKPd04squ-PuFwtt6f2nhbZp-zKwy62pVQ@mail.gmail.com>
Hi,

I observed an unexpected behavior while using git grep with both git 2.19.1 and 2.14.3. Here is how to reproduce it:

> git init
Initialized empty Git repository in /private/tmp/hello/.git/
> echo foo > fileA
> echo 'foo is false+' > fileB
> git add fileA
> git commit -m fileA
[master (root-commit) f2c83e7] fileA
 1 file changed, 1 insertion(+)
 create mode 100644 fileA
> git add fileB
> git commit -m fileB
[master e35df26] fileB
 1 file changed, 1 insertion(+)
 create mode 100644 fileB
> git --no-pager grep foo HEAD -- ':!fileA'
HEAD:fileB:foo is false+
> git --no-pager grep foo HEAD -- ':!fileB'

HEAD:fileA:foo HEAD:fileB:foo is false+

In the last command, fileB appears in grep results but it should have been excluded.

If the HEAD parameter is removed, it works as expected:
> git --no-pager grep foo -- ':!fileB'
fileA:foo
If giving the revision, it does not work either
> git --no-pager grep foo e35df26 -- ':!fileB'

e35df26:fileA:foo e35df26:fileB:foo is false+

The same behavior can be seen with git archive:
> git archive --verbose master ':(top)'

fileA fileB pax_global_header00006660000000000000000000000064133641017230014512gustar00rootroot0000000000000052 comment=e35df26c65f3c0b303e78743496598b8b6a566e9 fileA000066400000000000000000000000041336410172300120130ustar00rootroot00000000000000foo fileB000066400000000000000000000000161336410172300120170ustar00rootroot00000000000000foo is false+

> /usr/local/bin/git archive --verbose master ':(top)' ':(exclude)fileA'

fileB pax_global_header00006660000000000000000000000064133641017230014512gustar00rootroot0000000000000052 comment=e35df26c65f3c0b303e78743496598b8b6a566e9 fileB000066400000000000000000000000161336410172300120170ustar00rootroot00000000000000foo is false+

> /usr/local/bin/git archive --verbose master ':(top)' ':(exclude)fileB'

fileA fileB pax_global_header00006660000000000000000000000064133641017230014512gustar00rootroot0000000000000052 comment=e35df26c65f3c0b303e78743496598b8b6a566e9 fileA000066400000000000000000000000041336410172300120130ustar00rootroot00000000000000foo fileB000066400000000000000000000000161336410172300120170ustar00rootroot00000000000000foo is false+

fileA can be excluded, but not fileB.
Is it a bug?
Thanks

-- Christophe Bliard

Next: Duy Nguyen
Message 1 of 10 in “Re: bug?: git grep HEAD with exclude in pathspec not taken into account”
  1. Christophe BliardOct 24, 2018
  2. Duy NguyenOct 24, 2018
  3. Christophe BliardOct 24, 2018
  4. Duy NguyenOct 27, 2018
  5. tree-walk.c: fix overoptimistic inclusion in :(exclude) matchingNguyễn Thái Ngọc Duy, Nov 3, 2018
  6. Eric SunshineNov 4, 2018
  7. Eric SunshineNov 4, 2018
  8. Duy NguyenNov 4, 2018
  9. tree-walk.c: fix overoptimistic inclusion in :(exclude) matchingNguyễn Thái Ngọc Duy, Nov 4, 2018
  10. Junio C HamanoNov 5, 2018

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.