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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
Mentored-by: Jeff King <peff@xxxxxxxx>
Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@xxxxxxxxx>
---
 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





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux