public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Ben Knoble <ben.knoble@gmail•com>
To: Jeff King <peff@peff•net>
Cc: Junio C Hamano <gitster@pobox•com>,
	Sruteesh Kumar <sruteesh.oss@protonmail•com>,
	git@vger•kernel.org
Subject: Re: [PATCH] doc: document backslash in gitignore patterns
Date: Thu, 30 Oct 2025 12:05:00 -0400	[thread overview]
Message-ID: <3F5E99CD-5EE0-491C-8BFB-ABC01922073E@gmail.com> (raw)
In-Reply-To: <20251030150814.GA1275070@coredump.intra.peff.net>


> Le 30 oct. 2025 à 11:08, Jeff King <peff@peff•net> a écrit :
> 
> On Thu, Oct 30, 2025 at 09:40:36AM -0400, D. Ben Knoble wrote:
> 
>>> There's also the "pathspec" entry in gitglossary(7), which does mention
>>> fnmatch(3). Though it is even more confusing because of the literal
>>> matching that pathspecs do. I don't know if we'd want anything there
>>> (and I kind of doubt people get as exotic about patterns there as they
>>> would in gitignore).
>> 
>> I certainly wondered about the pathspec case, since the commit message
>> called out the difference in behavior. For example, at least in this
>> one corner, we can't reliably use Git commands with pathspecs to build
>> up example gitignore patterns to throw in .gitignore?
> 
> They're close enough that I suspect people do use them interchangeably,
> but there are definitely important corner cases. Like the anchoring
> stuff below.
> 
>> BTW, is the literal matching intended to be conveyed by
>> 
>>           •   any path matches itself
>> 
>> ? If so, I'm not quite sure how to interpret a pathspec like a/b given
>> a repo with a/b and dir/a/b—do both match or only the former? I expect
>> in combination with the 2 subsequent bullets that only the former
>> matches. Conversely, with a pathspec "b" in that case, I think I could
>> read the docs as suggesting both match, when IIRC none do. Hm!
> 
> I may not be the right person to ask, as I wasn't aware of the literal
> match behavior here until I tried to write that wildmatch test, and then
> walked it through the debugger. ;) Finding the documentation
> justification came later.
> 
> But yeah, I think that a pathspec "a/b" will not match "dir/a/b",
> because pathspecs are implicitly anchored to the start of the path. So
> "foo" in .gitignore will match "some/dir/foo". You'd need to "/foo" to
> anchor it to the top-level. But pathspecs always start at the top-level,
> and you'd need "**/foo" to be the equivalent of gitignore's "foo".
> 
> But even that's not entirely true. We allow "*" to match even directory
> separators in pathspecs (which is what makes "*.c" match anywhere), so
> "*/foo" is enough.
> 
>> But this is a bit of a tangent, and the pathspec entry is already, uh,
>> complicated [1]. Without a good place to leave extra notes for cases
>> like this, I'm not sure what to do. Certainly unifying the behavior
>> would be incompatible (if obscure).
> 
> It's definitely complicated, but I'm not sure which of those features
> are important for command-line ergonomics, and which are just pointless
> inconsistencies. I'd be scared to start changing things and finding out. :)
> 
> I certainly don't have any objection to improving the pathspec
> documentation if it's unclear, though I think that can be done
> separately on top of the patch in this thread (and I'm not planning to
> tackle it myself).
> 
> -Peff

Agreed, thanks. 

      reply	other threads:[~2025-10-30 16:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-10 14:57 Probable issue with code/documentation Sruteesh Kumar
2025-10-14  0:34 ` [PATCH] match_pathname(): give fnmatch one char of prefix context Jeff King
2025-10-14  3:09   ` Jeff King
2025-10-22 16:19   ` Sruteesh Kumar
2025-10-23 20:28   ` Junio C Hamano
2025-10-24 18:28     ` Sruteesh Kumar
2025-10-26 15:18     ` Jeff King
2025-10-26 15:26     ` Jeff King
2025-10-26 15:40       ` [PATCH v2 0/2] fix "foo**/bar" matching "foobar" Jeff King
2025-10-26 15:41         ` [PATCH v2 1/2] match_pathname(): reorder prefix-match check Jeff King
2025-10-26 15:42         ` [PATCH v2 2/2] match_pathname(): give fnmatch one char of prefix context Jeff King
2025-10-26 23:29       ` [PATCH] " Junio C Hamano
2025-10-27 14:29         ` Jeff King
2025-10-27 15:35           ` Junio C Hamano
2025-10-28 23:19             ` Jeff King
2025-10-29 15:32               ` [PATCH] doc: document backslash in gitignore patterns Jeff King
2025-10-29 15:55                 ` Jeff King
2025-10-30 13:40                   ` D. Ben Knoble
2025-10-30 15:08                     ` Jeff King
2025-10-30 16:05                       ` Ben Knoble [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=3F5E99CD-5EE0-491C-8BFB-ABC01922073E@gmail.com \
    --to=ben.knoble@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    --cc=peff@peff$(echo .)net \
    --cc=sruteesh.oss@protonmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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