Documentation
¶
Overview ¶
Package ignore provides pattern matching for file exclusion.
Index ¶
- func DefaultIgnorePatterns() []string
- func GlobToRegex(glob string) string
- func LoadDotignoreFile(ctx context.Context, fs domain.FS, path string) ([]string, error)
- func LoadDotignoreWithInheritance(ctx context.Context, fs domain.FS, startPath, rootPath string) ([]string, error)
- func NewPattern(glob string) domain.Result[*Pattern]
- func NewPatternFromRegex(regex string) domain.Result[*Pattern]
- type IgnoreSet
- type Pattern
- type PatternType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultIgnorePatterns ¶
func DefaultIgnorePatterns() []string
DefaultIgnorePatterns returns the default set of patterns to ignore. These are common files that should not be managed.
func GlobToRegex ¶
GlobToRegex converts a glob pattern to a regex pattern.
Glob syntax:
- * matches any sequence of characters
- ? matches any single character
- [abc] matches any character in the set
- [a-z] matches any character in the range
All other characters are escaped to match literally.
func LoadDotignoreFile ¶
LoadDotignoreFile loads patterns from a .dotignore file. Returns nil patterns (no error) if the file does not exist. Empty lines and lines starting with # are treated as comments and skipped.
func LoadDotignoreWithInheritance ¶
func LoadDotignoreWithInheritance(ctx context.Context, fs domain.FS, startPath, rootPath string) ([]string, error)
LoadDotignoreWithInheritance loads .dotignore files from startPath up to rootPath. Files closer to startPath have higher priority (patterns are prepended). This implements subdirectory inheritance similar to .gitignore behavior.
Example: For path /packages/vim/colors, it checks:
- /packages/vim/colors/.dotignore (highest priority)
- /packages/vim/.dotignore
- /packages/.dotignore (lowest priority, assuming rootPath=/packages)
func NewPattern ¶
NewPattern creates a pattern from a glob pattern. Converts glob syntax to regex for matching. Patterns starting with ! are negation patterns that un-ignore files.
Types ¶
type IgnoreSet ¶
type IgnoreSet struct {
// contains filtered or unexported fields
}
IgnoreSet is a collection of patterns for ignoring files.
func NewDefaultIgnoreSet ¶
func NewDefaultIgnoreSet() *IgnoreSet
NewDefaultIgnoreSet creates an ignore set with default patterns.
func (*IgnoreSet) AddPattern ¶
AddPattern adds a compiled pattern to the ignore set.
func (*IgnoreSet) Patterns ¶
Patterns returns the list of patterns in the set. Used for merging pattern sets.
func (*IgnoreSet) ShouldIgnore ¶
ShouldIgnore checks if a path should be ignored. Returns true if the path matches any pattern and is not un-ignored by a negation pattern.
The function checks both full path match and basename match to support patterns like ".DS_Store" matching anywhere in the tree. Patterns are processed in order, with later patterns overriding earlier ones. Negation patterns (starting with !) un-ignore previously ignored files.
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern represents a compiled pattern for matching paths.
func (*Pattern) IsNegation ¶
IsNegation returns true if this is a negation pattern.
func (*Pattern) MatchBasename ¶
MatchBasename checks if the basename of the path matches the pattern. Useful for patterns like ".DS_Store" that should match anywhere in tree.
type PatternType ¶
type PatternType int
PatternType identifies whether a pattern includes or excludes files.
const ( // PatternInclude represents a normal ignore pattern. PatternInclude PatternType = iota // PatternExclude represents a negation pattern that un-ignores files. PatternExclude )