Repository navigation
plumbing: format/gitignore, Backtrack non-trailing ** expansions. Fixes #2317 - #2318
codeAnqiang-ma wants to merge 1 commit into
Conversation
go-git#2317 A non-trailing `**` locked onto the first path component matching the segment after it; when a later segment then failed, the whole match was rejected without retrying the remaining candidates. `**/a/b` therefore did not match a/x/a/b even though `git check-ignore` ignores it. Recurse over every candidate expansion so later starting points are retried, mirroring the backtracking git's wildmatch performs for `**`. Assisted-by: Claude Fable 5 <[email protected]> Signed-off-by: codeAnqiang-ma <[email protected]>
|
I measured this PR against an outside bench before saying anything about it. This isn't a code review — I read the diff, I did not audit it. It's the behaviour, against Setup. One Go helper (
I checked the drift rather than assuming it: against The corpus is 33 real repositories' full The result, compared as sets rather than counts:
Zero fixed, zero broken, zero moved. The two that stay are the And it does fix what it claims. Both repros from #2317, verbatim, with
Why a real fix moves nothing in 4,463 queries — worth stating, because "no change" could equally mean the bench never exercised it. It did: 78 of the corpus's 3,427 rule lines carry a non-trailing The bench, the corpus and the go-git adapter are public if you want to re-run any of it: https://github.com/KaizenShogun/gitignore-conformance |
Fixes #2317
What
In
plumbing/format/gitignore,globMatchhandled a non-trailing**by locking onto the first path component that matched the following segment. When a later segment then failed, the whole match was rejected without retrying the remaining candidates, so patterns like**/a/bdid not matcha/x/a/b(or**/node_modules/lodashvsweb/node_modules/x/node_modules/lodash) even thoughgit check-ignoreignores them.This PR threads the segment slice through
globMatchand, at a non-trailing**, recurses over every candidate expansion instead of committing to the first one. All other behaviour is preserved line-for-line: empty segments still reset traversal, a trailing**still requires a remaining component or a directory endpoint (#2278), the "files matching dir globs don't match" rule and the finaldirOnlycheck are untouched.Why this shape
**is documented as matching zero or more directories (gitignore(5)), i.e. an existential choice — a correct matcher must be able to retry longer expansions when a shorter one dead-ends. Canonical git implements this with recursion inwildmatch.c(the**branch ofdowildtries the remainder at every position). Recursing on the existing segment matcher is the minimal equivalent here and keeps the subtle semantics that previous fixes (#2278, #154) encoded in this function.The new conformance cases run against the
git check-ignoreoracle like the rest of the suite. These patterns keep**in the documented positions, so they are unaffected by the pre-2.52 wildmatch corner case the suite already guards against.Verification against real git
go-git on
mainreturns no match for the same input; with this fix it matches.Tests
Regression tests fail on
mainbefore the fix and pass with it:Full run:
go test -short ./...passes on darwin/arm64 with Go 1.26.5, except three tests that need network access togithub.com/git-fixturesand hit a transient TLS timeout; all three passed on a re-run (TestFetchByHashThenResolveRevision,TestWorktreeSuite/TestCheckoutRelativePathSubmoduleInitialized,TestRepositorySuite/TestCloneMirror). Not run:plumbing/transport/git(requires a localgit daemon, per AGENTS.md).go vetandgofmtare clean. The full (non--short) gitignore conformance suite passes against the git 2.52+ oracle expectations; on this machine's older git the pre-existingTestIgnoreDoubleStarPrefixoracle note applies, unrelated to this change.Disclosure
This contribution was produced with AI assistance (Claude Fable 5, via Cursor); the commit carries an
Assisted-by:trailer per AI_POLICY.md. I reproduced the bug locally, verified the behaviour against the reference git implementation, and reviewed every line.