Documentation
¶
Overview ¶
Package gitignore matches paths against .gitignore rules.
It exists so the indexer can skip what the repository already declares as noise. A .gitignore is the one place a project has already written down which files are generated, vendored or private, and re-deriving that list as indexer excludes means maintaining the same knowledge twice — badly, since only one of the two copies is under review.
The implementation follows gitignore(5) rather than approximating it, because the approximations fail in the direction that matters: a pattern silently not matching indexes a build directory, and the person who wrote the pattern has no reason to suspect it. What is deliberately not implemented is everything outside the working tree — the global core.excludesFile, .git/info/exclude, and the index itself. A file tracked by git before it was ignored is still ignored here, because the file on disk is what this package can see and what the user pointed at.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher answers whether a path is ignored, consulting every .gitignore between the root and the path itself.
Files are read lazily and cached, so a walk pays for each .gitignore once however many paths it covers.
func (*Matcher) Match ¶
Match reports whether path is ignored. path may be absolute or relative to the root; isDir must say whether it names a directory, because a pattern ending in "/" matches only directories.
The rules of precedence are git's: within one file the last matching pattern decides, and a .gitignore deeper in the tree overrides a shallower one. So the search runs outermost-first and keeps the last verdict rather than stopping at the first — which is what lets a nested file re-include something its parent excluded.