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

Re: Bug: Git sometimes disregards wildcards in pathspecs if a file name matches exactly

From
JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com>
Date
Apr 12, 2025, 03:00 UTC
Message-ID
<CA+rGoLd-bSbaqfswD+qVrCv1fvG69QX+3BO1htbPJtinFkEQAA@mail.gmail.com>
In-Reply-To
<20250412015748.7177-1-jayatheerthkulkarni2005@gmail.com>

Upon a much closer look into the Git source code, specifically init_pathspec_item within pathspec.c, my previous hypothesis regarding the optimization check in do_match_pathspec appears to be incorrect, or at least not the root cause.

The debugging output confirmed that the core issue seems to originate earlier, during the pathspec parsing phase. It revealed that when processing the input string 'f*' (without any explicit magic like :(glob)), the resulting pathspec_item.magic field does not have the , even though the string clearly contains the * glob metacharacter. (To clarify I did multiple fprintf checks in the do_match_pathspec fun)

Looking at the logic in init_pathspec_item, it seems the PATHSPEC_GLOB flag is generally only added to item->magic if: a) The user explicitly uses a magic prefix like :(glob)f*. b) A global setting like GIT_GLOB_PATHSPECS_ENVIRONMENT is active.

The code does not appear to automatically set PATHSPEC_GLOB on item->magic simply based on scanning the content of the path string for unescaped *, ?, or [ characters if no explicit magic prefix is present.

This explains why the fix attempted in do_match_pathspec (which relied on checking the PATHSPEC_GLOB flag) was ineffective – the flag wasn't set in the first place for the 'f*' input. It also explains the original inconsistent behavior: because the pathspec lacks the PATHSPEC_GLOB magic flag, parts of Git relying on these flags treat it as literal by default, even if lower-level matching functions might still perform some wildcard expansion based on the string content itself.

So, this seems less like a bug in a specific conditional check and more like a consequence of the current design where the magic flags indicating glob behavior are opt-in (via prefixes or environment variables) rather than implicitly inferred from the pathspec string's content.

-Jayatheerth
Previous: K JayatheerthNext: Jeff King
Message 3 of 5 in “Bug: Git sometimes disregards wildcards in pathspecs if a file name matches exactly”
  1. Piotr SiupaApr 11, 2025
  2. K JayatheerthApr 12, 2025
  3. JAYATHEERTH KApr 12, 2025
  4. Jeff KingApr 12, 2025
  5. JAYATHEERTH KApr 12, 2025

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.