Documentation ¶
Overview ¶
Package gitignore provides functionality to parse .gitignore files and match paths against the rules defined in those files.
The package tries to implement the gitignore specification as defined in the git documentation. It supports all standard gitignore features including pattern negation, directory-specific patterns, and wildcards.
Basic usage:
matcher, err := gitignore.New("/givePath/to/.gitignore") if err != nil { // Handle error } if matcher.Match("givePath/to/file.txt") { // Path is ignored }
The package provides two ways to create a matcher:
- From a file using New().
- From a slice of pattern strings using NewFromLines().
Index ¶
Constants ¶
const ErrRegexCompile xerrors.Error = "failed to compile regex"
ErrRegexCompile is returned when an error occurs while compiling regular expressions when parsing a .gitignore file.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents a .gitignore file and provides the functionality to match paths against its rules.
func NewFromLines ¶
NewFromLines creates a new File instance from a list of strings. Useful when patterns are available in memory rather than in a file or for testing.