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

Re: [bug] git-ls-files sometimes does not list files with pathspec magic ":(exclude)"

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 14, 2021, 02:07 UTC
Message-ID
<xmqqa6tc1dab.fsf@gitster.c.googlers.com>
In-Reply-To
<e2dbe996f6a7285fe0487e34d65eccf712867547.camel@redhat.com>
Thomas Haller <thaller@redhat.com> writes:
>       git ls-files -- src/platform/ ":(exclude)shared/n-acd"
This does look interesting.

$ git ls-files -- src/platform/ ":(exclude)shared/n-acd" $ git ls-files -- src/platform/ ":(exclude)??????/?????" $ git ls-files -- src/platform/ ":(exclude)??????/????" $ git ls-files -- src/platform/ ":(exclude)??????/???" $ git ls-files -- src/platform/ ":(exclude)??????/??" $ git ls-files -- src/platform/ ":(exclude)??????/?"

None of the above gives any output. And the '/' seems to be a red herring. None of the below (where the '/' in the exclude pathspec is replaced with a single '?') gives any output, either.

$ git ls-files -- src/platform/ ":(exclude)????????????" $ git ls-files -- src/platform/ ":(exclude)???????????" $ git ls-files -- src/platform/ ":(exclude)??????????" $ git ls-files -- src/platform/ ":(exclude)?????????" $ git ls-files -- src/platform/ ":(exclude)????????"

But if we add one more "?" to the longuest ones, i.e.

$ git ls-files -- src/platform/ ":(exclude)?????????????" $ git ls-files -- src/platform/ ":(exclude)shared/n-acd?"

we start seeing output.

What is curious is that the longest problematic negative pathspec, "shared/n-acd" or "????????????", have the same length as "src/platform" without the trailing slash.

    "shared/n-acd"
    "src/platform/"
    "????????????"

The rule IIUC is that a path must match one of the positive pathspec and none of the negative pathspec, but it looks as if there is some bogus optimization based on string length.

An experiment.  These ought to do the same as the first exacmple:

$ git ls-files -- src/platform/ ":(exclude)shared/n-ac[d]" $ git ls-files -- src/platform/ ":(exclude)shared/n-[acd][acd][acd]"

but probably because of the character class [d], it seems to defeat/bypass the broken "optimization" and gives what we expect back.

I'll have to go back to the desk where I have a development environment (not an end user enviornment) to dig deeper, but this is intriguing. I'll look more later unless somebody else beats me to it.

Thanks for a report.
Previous: Thomas HallerNext: Jeff King
Message 2 of 3 in “[bug] git-ls-files sometimes does not list files with pathspec magic ":(exclude)"”
  1. Thomas HallerJan 13, 2021
  2. Junio C HamanoJan 14, 2021
  3. Jeff KingJan 14, 2021

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.