From: Junio C Hamano <gitster@pobox.com>
To: TDD Guru <tddguru@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: gitignore pattern matching issue with Windows
Date: Mon, 28 Jul 2025 15:36:10 -0700 [thread overview]
Message-ID: <xmqqa54ot02t.fsf@gitster.g> (raw)
In-Reply-To: <CAK2EJNO-FY+TzAnwtOhAgbWpnBP1d8yfjPidWSd=rVKM6rrdhQ@mail.gmail.com> (TDD Guru's message of "Mon, 28 Jul 2025 14:09:08 -0700")
TDD Guru <tddguru@gmail.com> writes:
> C:\gitbug>git check-ignore -v a
>
> C:\gitbug>git check-ignore -v b
>
> C:\gitbug>git check-ignore -v A
>
> C:\gitbug>git check-ignore -v B
I do not think this is not limited to Windows. The exclusion
patterns use the wildmatch machinery, and its ignore-case behaviour
seems iffy. The code expects that pattern characters to be
lowercase in character classes in order to match their uppercase
counterpart, which sounds like a bug.
$ cat >.gitignore <<\EOF
[ab]
[CD]
EOF
$ git -c core.ignorecase check-ignore -v A
$ git -c core.ignorecase check-ignore -v C
Here is a totally untested patch to downcase the pattern characters
to match against the text characters that are already downcased.
wildmatch.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git c/wildmatch.c w/wildmatch.c
index 69a2ae7000..1a2d86b691 100644
--- c/wildmatch.c
+++ w/wildmatch.c
@@ -189,10 +189,14 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
do {
if (!p_ch)
return WM_ABORT_ALL;
+ if ((flags & WM_CASEFOLD) && ISUPPER(p_ch))
+ p_ch = tolower(p_ch);
if (p_ch == '\\') {
p_ch = *++p;
if (!p_ch)
return WM_ABORT_ALL;
+ if ((flags & WM_CASEFOLD) && ISUPPER(p_ch))
+ p_ch = tolower(p_ch);
if (t_ch == p_ch)
matched = 1;
} else if (p_ch == '-' && prev_ch && p[1] && p[1] != ']') {
@@ -201,6 +205,8 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
p_ch = *++p;
if (!p_ch)
return WM_ABORT_ALL;
+ if ((flags & WM_CASEFOLD) && ISUPPER(p_ch))
+ p_ch = tolower(p_ch);
}
if (t_ch <= p_ch && t_ch >= prev_ch)
matched = 1;
@@ -225,6 +231,11 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
matched = 1;
goto next;
}
+
+ /*
+ * [[:alnum:]] etc. must be spelled in
+ * lowercase even under icase matching rule.
+ */
if (CC_EQ(s,i, "alnum")) {
if (ISALNUM(t_ch))
matched = 1;
prev parent reply other threads:[~2025-07-28 22:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-28 21:09 gitignore pattern matching issue with Windows TDD Guru
2025-07-28 22:36 ` Junio C Hamano [this message]
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=xmqqa54ot02t.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=tddguru@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).