gitignore

package
v0.1.0-dev.20260314201016 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gitignore provides gitignore-aware file filtering using go-git's gitignore package. It implements a native Go stack-based tracker that supports the full Git ignore hierarchy: global gitignore, .git/info/exclude, and per-directory .gitignore.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PatternSource

type PatternSource struct {
	Path     string
	Patterns []gitignore.Pattern
}

PatternSource pairs gitignore patterns with the file they were loaded from.

type Tracker

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

Tracker manages a stack of gitignore pattern sources and provides path matching.

The stack is ordered from the least specific (global ignore) to the most specific (deepest subdirectory .gitignore). The deepest matching rule wins.

func NewTracker

func NewTracker(root string) (*Tracker, error)

NewTracker creates a Tracker rooted at the given directory.

The Tracker created loads three base layers: global gitignore (core.excludesfile), .git/info/exclude, and the root .gitignore.

Parameters:

  • root: Absolute path to the root directory of the git repository

Returns:

  • *Tracker: The initialized Tracker

func (*Tracker) IsIgnored

func (t *Tracker) IsIgnored(path string, isDir bool) (ignored bool, source string)

IsIgnored checks whether a relative path (from root) should be ignored.

The most specific (deepest) matching rule wins. Within each layer, the last matching pattern takes precedence.

Parameters:

  • path: Relative path to check (e.g. "src/main.cpp")
  • isDir: True if the path is a directory (e.g. "src/main.cpp" is a directory, not a file)

Returns: true if the path is ignored, false if the path is not ignored.

func (*Tracker) Push

func (t *Tracker) Push(dir string)

Push loads the .gitignore from the given directory (relative to root) onto the stack.

It automatically pops entries from sibling or cousin directories that are no longer ancestors of dir.

Parameters:

  • dir: Relative path to the directory containing the .gitignore file (e.g. "src/main.cpp")

func (*Tracker) Root

func (t *Tracker) Root() string

Root returns the absolute root directory of this tracker.

Jump to

Keyboard shortcuts

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