Repository navigation
gitignore: dirOnly re-include patterns must not cascade to descendants - #2310
Closed
thesahibnanda-max wants to merge 1 commit into
Closed
thesahibnanda-max wants to merge 1 commit into
thesahibnanda-max wants to merge 1 commit into
Conversation
…descendants. Fixes go-git#2112 A pattern like !dir/ only restores the directory entry itself; it does not implicitly re-include everything nested inside it. simpleNameMatch let a dirOnly inclusion pattern matching an ancestor path component stand in for a match on the full descendant path, so a .gitignore like: * !my-dir/ wrongly reported files under my-dir/ as untracked instead of ignored. Signed-off-by: Sahib Nanda <[email protected]>
thesahibnanda-max
force-pushed
the
fix/gitignore-dir-reinclude-cascade
branch
from
August 11, 2026 11:10
b1e8c5a to
9d8d8d3
Compare
Author
|
Closing in favor of #2311 — same change, rebased onto a fresh branch with a corrected commit message (package-prefixed per CONTRIBUTING.md) and DCO sign-off, which this PR's CI checks were failing on. |
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 #2112
Bug
A
.gitignorere-include pattern like!dir/is meant to restore only the directory entry itself, not everything nested inside it.simpleNameMatchlet adirOnlyinclusion pattern that matched an ancestor path component stand in as a match for the full descendant path, so:wrongly reported files under
my-dir/(e.g.my-dir/sub/file.txt) as untracked inWorktree.Status()instead of ignored, even though realgitkeeps them ignored.Fix
In
plumbing/format/gitignore/pattern.go,simpleNameMatchnow skips (rather than matches) when adirOnlyinclusion pattern hits a non-final path component — it only applies at the exact matched entry, not its descendants. Exclusion patterns are unaffected.Testing
pattern_test.gocovering the pattern in isolation.conformance_test.go, cross-checked against the realgitbinary via the existing oracle harness.worktree_status_test.goreproducing the original report viaWorktree.Status().go test ./plumbing/format/gitignore/...andgo test .pass (aside from one pre-existing, unrelated oracle mismatch confirmed present on unmodifiedmaintoo).