branchrules

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package branchrules holds the user's rules for deleting local branches: which branches go with a worktree the app removes or cleans up, whether a branch whose pull request merged starts checked in the cleanup of a clone's merged branches, and which branches are never deleted.

The rules are only defaults: every deletion the user starts is confirmed in a list of checkboxes that start from them. Settings writes them, under the keys declared here, and the worktrees package follows them. Whatever the rules say, a branch is deleted only when every commit on it is on GitHub, so nothing is ever lost.

Index

Constants

View Source
const (
	// PrefOwn is whether a worktree's own worktree-<name> branch goes with it.
	PrefOwn = "branches.own"

	// PrefPullRequest is whether a pull request's own branch, checked out in its worktree,
	// goes with the worktree.
	PrefPullRequest = "branches.pullRequest"

	// PrefMerged is whether a branch whose pull request merged starts checked in the
	// cleanup of a clone's merged branches.
	PrefMerged = "branches.merged"

	// PrefProtected is the patterns of the branches never deleted, a JSON list.
	PrefProtected = "branches.protected"
)

The preferences the rules are stored under.

Variables

View Source
var (
	// ErrInvalidPattern is returned for a protected pattern that cannot match a branch.
	ErrInvalidPattern = errors.New("not a branch pattern")

	// ErrTooManyPatterns is returned for a protected list over 100 patterns.
	ErrTooManyPatterns = errors.New("too many protected branch patterns")
)

Functions

func DefaultProtected

func DefaultProtected() []string

DefaultProtected is the protected list before the user changes it.

func Keys

func Keys() []string

Keys are every preference the rules are stored under.

func Matches

func Matches(branch string, patterns []string) bool

Matches reports a branch one of patterns protects. A pattern is matched against the whole branch name as a path: * matches within one part ("release/*" protects release/1.2 but not release/1.2/fix), ? matches one character, and [a-z] one of a set. A pattern without a wildcard protects that one branch.

func Normalize

func Normalize(patterns []string) ([]string, error)

Normalize returns patterns trimmed, without empty ones or repeats, in order. It refuses a pattern that cannot match a branch name, and a list over 100 patterns.

Types

type Rules

type Rules struct {
	// Own deletes a worktree's own worktree-<name> branch with it.
	Own bool `json:"own"`

	// PullRequest deletes a pull request's own branch, checked out in its worktree (as
	// `gh pr checkout` does), with the worktree.
	PullRequest bool `json:"pullRequest"`

	// Merged starts each branch whose pull request merged checked in the cleanup of a
	// clone's merged branches.
	Merged bool `json:"merged"`

	// Protected are the patterns of the branches never deleted, such as "main" or
	// "release/*" (see Matches).
	Protected []string `json:"protected"`
}

Rules are the user's defaults for deleting local branches.

func Decode

func Decode(stored map[string]string) Rules

Decode reads the rules from stored preferences. A rule never stored, or one that cannot be read, keeps its default; a protected list stored empty stays empty.

func Defaults

func Defaults() Rules

Defaults are the rules before the user changes any: every kind of branch goes, and main and master are protected.

func (Rules) Encode

func (r Rules) Encode() (map[string]string, error)

Encode returns the rules as preferences, the protected list normalized. It fails as Normalize does.

func (Rules) Validate

func (r Rules) Validate() error

Validate refuses rules whose protected list Normalize would refuse.

Jump to

Keyboard shortcuts

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