branch

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 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 branch matches the current branch against versioning.branches and enforces the branch guards: the per-environment branch and the unlisted-branch refusal (ADR-0065).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnlistedBranch   = errors.New("branch matches no versioning.branches entry")
	ErrAmbiguousBranch  = errors.New("branch matches more than one versioning.branches entry")
	ErrUnderivableRange = errors.New("cannot derive a maintenance range from the branch name")
)

Functions

func CIBranch added in v1.0.1

func CIBranch() (branch string, ok bool)

CIBranch reads the branch a CI job runs for from the providers' variables. GitHub's ref name and Azure's source ref only count when the ref is a branch, since a tag-triggered run exposes the tag there. ok is false outside CI or on a tag build.

func CheckBranch

func CheckBranch(runner port.Runner, cfg *config.Config, env string, force bool) error

CheckBranch enforces the per-environment branch guard: when the active environment declares a branch, the current git branch must match it. This prevents operating on an environment (e.g. releasing prod) from the wrong branch. It is a no-op when env is empty or the environment has no branch set. force bypasses the check entirely. On a detached checkout the branch is the one the CI job runs for (CurrentBranch).

func CheckReleaseBranch

func CheckReleaseBranch(runner port.Runner, cfg *config.Config, force bool) error

CheckReleaseBranch refuses publishing from an unlisted/unknown branch when cfg.Versioning.Branches is set. No-op when the block is absent or force is true.

func CurrentBranch

func CurrentBranch(runner port.Runner) (branch string, ok bool, err error)

CurrentBranch reads the checked-out branch. A detached HEAD (the norm in CI checkouts) falls back to the CI providers' branch variables (CIBranch). ok is false when no source yields a branch; err is set only when git itself fails.

Types

type BranchKind

type BranchKind int
const (
	BranchRelease     BranchKind = iota // exact name, no range: today's behaviour
	BranchMaintenance                   // has a Range
	BranchUnlisted                      // no entry matches, or the branch is unknown
	BranchVersion                       // the branch name is the version (Version)
)

type BranchMatch

type BranchMatch struct {
	Branch  string // "" when unknown
	Kind    BranchKind
	Range   config.BranchRange // set when Kind == BranchMaintenance
	Version string             // bare N.N.N, set when Kind == BranchVersion
	Rule    int                // index into cfg.Versioning.Branches; -1 when unlisted
}

func MatchBranchRule

func MatchBranchRule(cfg *config.Config, branch string, known, needRange bool) (BranchMatch, error)

MatchBranchRule matches branch against cfg.Versioning.Branches. A glob match whose name ends in N.N.N is a BranchVersion and needs no range. needRange == false skips ErrUnderivableRange (the --set-version path) for names carrying neither: the match is then BranchMaintenance with a zero Range, which callers on that path never read.

type BranchMismatchError

type BranchMismatchError struct {
	Env, Want, Current string
}

BranchMismatchError is returned by CheckBranch when the current branch is not the one the environment is linked to.

func (*BranchMismatchError) Error

func (e *BranchMismatchError) Error() string

Jump to

Keyboard shortcuts

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