Repository navigation
plumbing: format/gitignore, fix trailing ** matching unrelated paths - #2279
Merged
pjbgf merged 1 commit intoJul 26, 2026
Merged
Conversation
…ixes go-git#2278 globMatch treated its matched flag as write-once-true, so a trailing `**` could report a match that the preceding segments had already ruled out. A `**/<segment>` traversal that exhausted the path left matched false and fell through to the trailing `**`, which set it back to true for any directory candidate. `**/node_modules/**` therefore excluded every directory in the repository, and because Worktree.Status stops descending into an excluded directory, every untracked file below the root vanished from the reported status. Separately, a trailing `**` reached with the path already consumed kept the preceding segment's result, so `a/**/*/**` matched `a/f.txt`. A `**` that never finds the segment following it now returns a definitive non-match, and the trailing `**` assigns its own result rather than only raising it. gitignore(5) documents the trailing `/**` form as matching everything inside the directory it follows; the new conformance cases are cross-checked against `git check-ignore`. Assisted-by: Claude Opus 5 <[email protected]> Signed-off-by: glitch-ux <[email protected]>
pjbgf
approved these changes
Jul 26, 2026
pjbgf
left a comment
Member
There was a problem hiding this comment.
@glitch-ux thanks for working on this. 🙇
Contributor
Author
|
@pjbgf My pleasure! :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2278
Why
A
.gitignorecontaining**/node_modules/**makes go-git report everydirectory in the repository as ignored — including directories with no
node_modulescomponent in their path, and even when nonode_modulesexists.That hides files rather than just mislabelling them:
Worktree.Statusstopsdescending into a directory the matcher excludes, so untracked work below the
repository root never shows up.
Status()looks clean when it isn't.The cause is in
globMatch, which treatsmatchedas a flag that only evermoves to
true. When the earlier segments of a pattern rule a path out, thetrailing
**runs afterwards and flips it back on. A second symptom shares thecause: a trailing
**reached with the path already consumed inherits theprevious segment's answer, so
a/**/*/**matchesa/f.txt.gitignore(5) defines the trailing
/**form as matching everything inside the directory it follows — not paths that
never contained the preceding segment. Confirmed against
git check-ignore(git 2.47.3).
What changed
Eight lines in
plumbing/format/gitignore/pattern.go: a**that never findsthe segment following it now returns a definitive non-match, and the trailing
**assigns its own result instead of only raising the flag.Verification
ConformanceSuite, so every expectation iscross-checked against the real
gitbinary. All fail onmain, pass here.git check-ignore(296 patterns × 66paths): five over-matching pattern families on
main, zero after the fix,no new divergence.
golangci-lint(v2.11.4,make validate-lint): 0 issues.go test ./...shows the same failures before and after.