From: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
To: git@vger.kernel.org
Cc: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>,
piotrsiupa <piotrsiupa@gmail.com>, Jeff King <peff@peff.net>
Subject: [PATCH 1/1] add: fix handling literal filenames and wildcards
Date: Sat, 12 Apr 2025 15:16:07 +0530 [thread overview]
Message-ID: <20250412094607.236382-2-jayatheerthkulkarni2005@gmail.com> (raw)
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
next prev parent reply other threads:[~2025-04-12 9:46 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-12 9:46 [PATCH 0/1] add: fix pathspec handling when literal filenames match wildcard K Jayatheerth
2025-04-12 9:46 ` K Jayatheerth [this message]
2025-04-12 17:40 ` [PATCH] t3706: Add test for wildcard vs literal pathspec K Jayatheerth
2025-04-14 16:51 ` Lucas Seiki Oshiro
2025-04-14 17:08 ` JAYATHEERTH K
2025-04-14 21:42 ` Junio C Hamano
2025-04-15 22:32 ` brian m. carlson
2025-04-16 1:56 ` JAYATHEERTH K
2025-04-16 13:11 ` Junio C Hamano
2025-04-16 14:49 ` JAYATHEERTH K
2025-04-16 15:49 ` Lucas Seiki Oshiro
2025-04-16 16:00 ` Junio C Hamano
2025-04-19 4:59 ` JAYATHEERTH K
2025-04-19 17:43 ` Lucas Seiki Oshiro
2025-04-22 11:57 ` JAYATHEERTH K
2025-04-16 16:40 ` JAYATHEERTH K
2025-04-16 16:43 ` JAYATHEERTH K
2025-04-12 15:45 ` [PATCH 0/1] add: fix pathspec handling when literal filenames match wildcard Lucas Seiki Oshiro
2025-04-12 17:34 ` JAYATHEERTH K
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250412094607.236382-2-jayatheerthkulkarni2005@gmail.com \
--to=jayatheerthkulkarni2005@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=piotrsiupa@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).