package gitignore
import "git.sr.ht/~jamesponddotco/gitignore-go"
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 ¶
ErrRegexCompile is returned when an error occurs while compiling regular expressions when parsing a .gitignore file.
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 New ¶
New creates a new File instance from a given .gitignore file.
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.
func (*File) Match ¶
Match checks if the given path matches any of the .gitignore rules, and return true if the path should be ignored according to the rules.
The path is normalized to use forward slashes (/) regardless of the operating system.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal |
- Version
- v1.0.0 (latest)
- Published
- Dec 14, 2024
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 4 months ago –
Tools for package owners.