ignore

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package ignore provides pattern matching for file exclusion.

Index

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

func GlobToRegex(glob string) string

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

func LoadDotignoreFile(ctx context.Context, fs domain.FS, path string) ([]string, error)

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:

  1. /packages/vim/colors/.dotignore (highest priority)
  2. /packages/vim/.dotignore
  3. /packages/.dotignore (lowest priority, assuming rootPath=/packages)

func NewPattern

func NewPattern(glob string) domain.Result[*Pattern]

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.

func NewPatternFromRegex

func NewPatternFromRegex(regex string) domain.Result[*Pattern]

NewPatternFromRegex creates a pattern from a regex string.

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 NewIgnoreSet

func NewIgnoreSet() *IgnoreSet

NewIgnoreSet creates a new empty ignore set.

func (*IgnoreSet) Add

func (s *IgnoreSet) Add(glob string) error

Add adds a glob pattern to the ignore set.

func (*IgnoreSet) AddPattern

func (s *IgnoreSet) AddPattern(pattern *Pattern)

AddPattern adds a compiled pattern to the ignore set.

func (*IgnoreSet) Patterns

func (s *IgnoreSet) Patterns() []*Pattern

Patterns returns the list of patterns in the set. Used for merging pattern sets.

func (*IgnoreSet) ShouldIgnore

func (s *IgnoreSet) ShouldIgnore(path string) bool

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.

func (*IgnoreSet) Size

func (s *IgnoreSet) Size() int

Size returns the number of patterns in the set.

type Pattern

type Pattern struct {
	// contains filtered or unexported fields
}

Pattern represents a compiled pattern for matching paths.

func (*Pattern) IsNegation

func (p *Pattern) IsNegation() bool

IsNegation returns true if this is a negation pattern.

func (*Pattern) Match

func (p *Pattern) Match(path string) bool

Match checks if the path matches the pattern.

func (*Pattern) MatchBasename

func (p *Pattern) MatchBasename(path string) bool

MatchBasename checks if the basename of the path matches the pattern. Useful for patterns like ".DS_Store" that should match anywhere in tree.

func (*Pattern) String

func (p *Pattern) String() string

String returns the original pattern string.

func (*Pattern) Type

func (p *Pattern) Type() PatternType

Type returns the pattern type.

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL