Repository navigation
files: match directory-only gitignore rules in ShouldExclude - #1228
Open
amalsaidov wants to merge 1 commit into
Open
amalsaidov wants to merge 1 commit into
amalsaidov wants to merge 1 commit into
Conversation
A .gitignore pattern that ends in a slash, like "bar/", only matches directories. The go-gitignore matcher tells directories apart by a trailing slash on the path it is given, but ShouldExclude always passed the bare file name, so these patterns matched nothing and the directory was included anyway. NewFilter documents "bar/" as a supported rule. Append a trailing slash to the path when the entry is a directory. Patterns without a trailing slash already match the slashed form, so files and non-directory rules behave exactly as before. Fixes the directory-pattern case of ipfs#648.
amalsaidov
force-pushed
the
fix/filter-directory-gitignore-rules
branch
from
November 13, 2026 07:26
8128523 to
5c00e5d
Compare
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.
Problem
files.Filter.ShouldExcludedoes not apply.gitignorerules that end in aslash. Those patterns ("
bar/", "node_modules/", ...) match directoriesonly, and gitignore semantics are the
documented behavior:
NewFilterlistsbar/as a supported rule.The underlying matcher (
crackcomm/go-gitignore) tells a directory apart from afile by a trailing slash on the path it is handed.
ShouldExcludealways passedthe bare
fileInfo.Name(), soMatchesPath("bar")never matched abar/ruleand the directory was added anyway. This is the first point of #648.
Quick confirmation against the dependency as pinned in
go.mod:Fix
When the entry is a directory, append
/to the path before matching. Apattern without a trailing slash already matches the slashed form
(
rule="bar",rule="*.app"→ both match"bar/"/"foo.app/"), so filesand non-directory rules are unchanged; only directory-only patterns flip from
"matches nothing" to "matches the directory". No exported API changes.
This is scoped to the directory-pattern case. The second part of #648, matching
rules that contain a path (for example
a/b) against the entry's path relativeto the filter root, needs
ShouldExcludeto receive that relative path and isleft out of this change.
Testing
TestFileFilterDirectoryRulesinfiles/filter_test.go, coveringdir-only rules on directories vs files, plain rules, and glob rules. It fails
before this change (
ShouldExclude("bar") = false, want true) and passesafter.
go test ./files/...,go vet ./files/...,gofmt -lall clean.Companion kubo PR: this touches non-test code in
files, so it is not exemptfrom the companion-kubo requirement. The change keeps the
ShouldExcludesignature and all exported APIs identical, so kubo builds against it unchanged.
I have not opened the kubo PR or run the full kubo build here; happy to open the
pin-and-CI companion if you'd like, or to defer to a maintainer. Flagging it
honestly rather than claiming an exemption.
AI-assisted; directed, reviewed and tested by the author (amalsaidov).