ignore

package
v0.69.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ignore provides a small, graith-owned interface over a Git-compatible gitignore matcher. It wraps github.com/go-git/go-git/v5/plumbing/format/gitignore (a maintained implementation whose behaviour tracks Git) behind a narrow Matcher interface so the rest of graith never depends on a concrete gitignore library.

The interface is deliberately minimal: everything graith needs is "does this repo-relative path match the compiled patterns, given whether it is a directory". Callers pass slash-separated paths relative to the matcher root; the isDir flag lets directory-only patterns (a trailing "/") be honoured exactly as Git does, rather than the string-suffix guessing an older matcher required.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

type Matcher interface {
	// Match reports whether rel matches the patterns. rel is slash-separated
	// and relative to the matcher's root; isDir reports whether it names a
	// directory (which governs directory-only "foo/" patterns).
	Match(rel string, isDir bool) bool
}

Matcher reports whether a repo-relative, slash-separated path is matched (excluded) by a set of gitignore patterns. A nil-pattern matcher never matches.

func Dir

func Dir(dir string) Matcher

Dir builds a Matcher from the Git ignore sources rooted at dir, in Git's priority order: .git/info/exclude, then the root .gitignore, then any nested .gitignore files further down the tree (each scoped to its subdirectory). Missing files are not an error — an empty matcher never matches.

In a linked worktree, where .git is a "gitdir:" pointer file rather than a directory, the shared info/exclude lives in the common git directory rather than under the worktree root; Dir resolves it via the worktree's commondir so it is honoured exactly as `git check-ignore` does inside a worktree.

func Lines

func Lines(lines ...string) Matcher

Lines builds a Matcher from raw .gitignore pattern lines (as they would appear inside a .gitignore file). Blank lines and comment lines ("# ...") are skipped, matching Git's parser. Patterns are applied in order, so a later negation ("!foo") can re-include a path excluded by an earlier line.

Jump to

Keyboard shortcuts

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