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

[PATCH 1/1] add: fix handling literal filenames and wildcards

From
K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Date
Apr 12, 2025, 09:46 UTC
Message-ID
<20250412094607.236382-2-jayatheerthkulkarni2005@gmail.com>
In-Reply-To
<20250412094607.236382-1-jayatheerthkulkarni2005@gmail.com>

When `git add` is given a wildcard pathspec (e.g., 'f*'), and a file with that *exact* name ('f*') also exists, Git incorrectly adds only the literal file on the first invocation, ignoring other wildcard matches like 'foo'. On subsequent invocations, the wildcard expands as expected.

This occurs because the pathspec matching logic short-circuits when an exact match is found, skipping wildcard evaluation.

With this fix, wildcard expansion is always performed, ensuring consistent behavior even when a literal filename matches the wildcard.

To explicitly add the literal file named 'f*', users should use:
    git add 'f\*'
reported-by: piotrsiupa <piotrsiupa@gmail.com>
Mentored-by: Jeff King <peff@peff.net>
Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
---
 dir.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/dir.c b/dir.c
index cbd82be6c9..0546c00952 100644
--- a/dir.c
+++ b/dir.c
@@ -519,7 +519,8 @@ static int do_match_pathspec(struct index_state *istate,
 		    ( exclude && !(ps->items[i].magic & PATHSPEC_EXCLUDE)))
 			continue;
 
-		if (seen && seen[i] == MATCHED_EXACTLY)
+		if (seen && seen[i] == MATCHED_EXACTLY &&
+			ps->items[i].nowildcard_len == ps->items[i].len)
 			continue;
 		/*
 		 * Make exclude patterns optional and never report
-- 
2.49.0
Previous: K JayatheerthNext: K Jayatheerth
Message 2 of 19 in “add: fix pathspec handling when literal filenames match wildcard”
  1. 0/1 add: fix pathspec handling when literal filenames match wildcardK Jayatheerth, Apr 12, 2025
  2. 1/1 add: fix handling literal filenames and wildcardsK Jayatheerth, Apr 12, 2025
  3. t3706: Add test for wildcard vs literal pathspecK Jayatheerth, Apr 12, 2025
  4. Lucas Seiki OshiroApr 14, 2025
  5. JAYATHEERTH KApr 14, 2025
  6. Junio C HamanoApr 14, 2025
  7. brian m. carlsonApr 15, 2025
  8. JAYATHEERTH KApr 16, 2025
  9. Junio C HamanoApr 16, 2025
  10. JAYATHEERTH KApr 16, 2025
  11. Lucas Seiki OshiroApr 16, 2025
  12. Junio C HamanoApr 16, 2025
  13. JAYATHEERTH KApr 19, 2025
  14. Lucas Seiki OshiroApr 19, 2025
  15. JAYATHEERTH KApr 22, 2025
  16. JAYATHEERTH KApr 16, 2025
  17. JAYATHEERTH KApr 16, 2025
  18. Lucas Seiki OshiroApr 12, 2025
  19. 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.