branchfilter

package
v0.138.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package branchfilter matches branch names against glob patterns.

Patterns follow path.Match semantics. Notably, `*` matches any run of non-separator characters and therefore never crosses `/` — on every OS (branch names are `/`-layered and OS-independent, so the matcher is the path-flavored primitive, not filepath.Match whose separator is `\` on Windows; issue #134):

"release/*"  matches "release/v1"   but not "release/a/b"
"release-*"  matches "release-1.0"  but not "release/1.0"

There is no `**`; to match additional path levels, spell them out (e.g. "feature/*/*"). Malformed patterns (such as an unclosed "[") are rejected by both constructors with an error wrapping path.ErrBadPattern — a bad pattern never silently matches nothing. The pre-flight covers patterns malformed AFTER a star too (e.g. "release/*["): the matcher validates the whole pattern, not just the chunks a failing name happens to reach.

Pattern lists come in two shapes:

  • NewPatterns([]string): each element IS one glob pattern, verbatim — commas are ordinary pattern characters. This is the only way to name a branch whose ref name contains a comma ("release,1.0" is a valid git ref name; git check-ref-format accepts it).
  • New("main,release-*"): the convenience string form splits on commas, trims whitespace, and skips empty items (stringx.SplitCSVNonEmpty: RFC 4180 quoting, so an item opened with a double quote keeps its commas and loses the quotes). Outside quotes the comma is ALWAYS a separator; for a literal comma use NewPatterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchFilter

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

BranchFilter matches branch names against a set of comma-separated glob patterns. An empty filter matches all branches.

func New

func New(filterStr string) (*BranchFilter, error)

New creates a BranchFilter from a comma-separated list of glob patterns (e.g. "main,release-*,feature/*"). An empty string matches everything.

The comma is a separator in this form (whitespace around each pattern is trimmed, empty items skipped; splitting is stringx.SplitCSVNonEmpty, so a double-quoted item keeps its commas and drops the quotes — RFC 4180). For a literal comma in a pattern, use NewPatterns (issue #54).

Each pattern is validated up front with path.Match; a malformed pattern yields an error wrapping path.ErrBadPattern instead of a filter that silently never matches.

func NewPatterns added in v0.125.0

func NewPatterns(patterns []string) (*BranchFilter, error)

NewPatterns creates a BranchFilter from explicit patterns: each element IS one glob pattern, verbatim — no comma splitting, no trimming, no escaping rules to remember (issue #54: "release,1.0" is a valid git ref name and is matched literally here). An empty slice matches everything.

Each pattern is validated up front with path.Match; a malformed pattern yields an error wrapping path.ErrBadPattern instead of a filter that silently never matches.

func (*BranchFilter) FilterBranches

func (f *BranchFilter) FilterBranches(branches []string) []string

FilterBranches returns only the branches that match the filter.

func (*BranchFilter) IsEmpty

func (f *BranchFilter) IsEmpty() bool

IsEmpty reports whether the filter has no patterns (matches everything).

func (*BranchFilter) Match

func (f *BranchFilter) Match(branchName string) bool

Match reports whether branchName matches any of the filter's patterns. Returns true (matches everything) when the filter has no patterns.

func (*BranchFilter) Patterns

func (f *BranchFilter) Patterns() []string

Patterns returns the raw glob patterns that were used to create this filter.

Jump to

Keyboard shortcuts

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