fsmatch

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package fsmatch matches slash-separated paths against glob patterns and .gitignore rules. It is shared by the built-in search tools and the rag file loader.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchSegments

func MatchSegments(pat, name []string) bool

MatchSegments matches path segments against pattern segments, where a "**" pattern segment matches any number of path segments and others follow path.Match.

func Wildcard

func Wildcard(pattern, s string) bool

Wildcard matches s against a pattern in which "*" matches any text, including none, and every other character matches itself, as in the tool rules of Claude Code's permissions.

Types

type Glob

type Glob [][]string

Glob matches slash-separated paths against patterns in which "**" matches any number of path segments, other segments follow path.Match and "{a,b}" expands to alternatives.

func CompileGlob

func CompileGlob(pattern string) (Glob, error)

CompileGlob compiles pattern.

func (Glob) Match

func (g Glob) Match(name string) bool

Match reports whether name, a slash-separated path, matches the glob.

type Ignorer

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

Ignorer evaluates the .gitignore files of a file tree. Files are loaded lazily and cached per directory. It is not safe for concurrent use.

func NewIgnorer

func NewIgnorer(fsys fs.FS, outer ...OuterRules) *Ignorer

NewIgnorer returns an Ignorer for the tree fsys. outer are rules from outside the tree, such as a repository's info/exclude file, lowest precedence first.

func (*Ignorer) Ignored

func (ig *Ignorer) Ignored(name string, isDir bool) bool

Ignored reports whether name, a slash-separated path relative to the tree root, is excluded by the ignore files of its ancestors. As in git, the last matching pattern wins, deeper files override shallower ones and outer rules have the lowest precedence.

Like git, it does not check whether a parent directory is excluded; callers walking the tree skip excluded directories instead.

type OuterRules

type OuterRules struct {
	// Prefix is the slash-separated path of the tree root relative to the
	// ignore file's directory, or "" for the same directory.
	Prefix string
	Rules  []Rule
}

OuterRules are the rules of an ignore file above the root of a tree, which apply to paths relative to that file's directory.

type Rule

type Rule struct {

	// Negate re-includes a path ("!pattern").
	Negate bool
	// contains filtered or unexported fields
}

Rule is one pattern of a .gitignore file.

func ParseIgnore

func ParseIgnore(content string) []Rule

ParseIgnore parses .gitignore content. It supports comments, negation, directory-only and anchored patterns, "**" and escaped "#", "!" and trailing spaces.

func (*Rule) Match

func (r *Rule) Match(rel string, isDir bool) bool

Match reports whether the rule matches rel, a slash-separated path relative to the directory of the rule's .gitignore file.

Jump to

Keyboard shortcuts

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