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 ¶
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 ¶
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 Matches ¶
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.
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 ¶
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.