gitignore

package module
v0.0.0-...-345609f Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 5 Imported by: 0

README

go-gitignore

A go library to parse .gitignore patterns and match pattern lists against a path.

The code aims to be a close translation of the original implementation in the git codebase starting at is_excluded_from_list and add_excludes

Prior Art

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InRed

func InRed(txt string) string

func IsGlobSpecial

func IsGlobSpecial(char rune) bool

IsGlobSpecial taken from https://github.com/git/git/blob/v2.22.0/t/helper/test-ctype.c#L38

func MatchBasename

func MatchBasename(dirent Dirent, exclude *Exclude) bool

MatchBasename https://github.com/git/git/blob/v2.22.0/dir.c#L935-L957

func MatchPathname

func MatchPathname(dirent Dirent, exclude *Exclude) bool

MatchPathname https://github.com/git/git/blob/v2.22.0/dir.c#L959-L1016

func SimpleLength

func SimpleLength(pattern string) int

Types

type Dirent

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

Dirent stores the name and file system mode type of discovered file system entries.

type Exclude

type Exclude struct {
	Pattern   string
	Base      string
	Flags     ExcludeFlags
	SourcePos int
}

func CreateExclude

func CreateExclude(pattern string, base string, srcpos int) *Exclude

CreateExclude https://github.com/git/git/blob/v2.22.0/dir.c#L610-L622

func LastExcludeMatchingFromList

func LastExcludeMatchingFromList(dirent Dirent, el *ExcludeList) *Exclude

LastExcludeMatchingFromList Scan the given exclude list in reverse to see whether pathname should be ignored. The first match (i.e. the last on the list), if any, determines the fate. Returns the exclude_list element which matched, or NULL for undecided.

func (Exclude) String

func (e Exclude) String() string

type ExcludeFlags

type ExcludeFlags uint

ExcludeFlags stores flags for a single exclude pattern

const (
	// ExcFlagNodir The pattern contains a '/', not including a possible final '/' that sets ExecFlagMustbedir
	ExcFlagNodir ExcludeFlags = 1 << iota // 1

	// ExcFlagEndswith The pattern is an "ends-with" pattern
	ExcFlagEndswith // 4
	// ExcFlagMustbedir The pattern should only match for directories (ends with `/`)
	ExcFlagMustbedir // 8
	// ExcFlagNegative The pattern is negated (`!` prefixed)
	ExcFlagNegative // 16
)

func ParseExcludePattern

func ParseExcludePattern(pattern string) (string, ExcludeFlags)

ParseExcludePattern https://github.com/git/git/blob/v2.22.0/dir.c#L564-L600

func (ExcludeFlags) String

func (f ExcludeFlags) String() string

type ExcludeList

type ExcludeList struct {
	Excludes []*Exclude
}

ExcludeList holds a list of Exclude elements It can be used in the future to hold additional metadata such as where these Exclude patterns came from (filename, cmd line flags, ...)

func CreateExcludeList

func CreateExcludeList() *ExcludeList

CreateExcludeList creates an empty ExcludeList

func (*ExcludeList) AddExclude

func (list *ExcludeList) AddExclude(pattern string, base string, srcpos int)

AddExclude https://github.com/git/git/blob/v2.22.0/dir.c#L602-L626

type IsExcluded

type IsExcluded int
const (
	Excluded           IsExcluded = 1
	NotExcluded        IsExcluded = 0
	ExclusionUndecided IsExcluded = -1
)

func IsExcludedFromList

func IsExcludedFromList(dirent Dirent, el *ExcludeList) IsExcluded

IsExcludedFromList Scan the list and let the last match determine the fate. Return 1 for exclude, 0 for include and -1 for undecided. https://github.com/git/git/blob/v2.22.0/dir.c#L1071-L1085

func (IsExcluded) String

func (val IsExcluded) String() string

Jump to

Keyboard shortcuts

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