Documentation
¶
Overview ¶
Package branches lists a repository's branches with what git knows of each for the session deck's Branches view (owner, 2026-10-12, translated: "seeing branches with statistics would also be interesting"): how far each is ahead of and behind the default branch, its last commit's time and author. Everything here is local git — `for-each-ref`, no network — read only while the view is shown, and kept a few seconds so a burst of reads runs git once.
Index ¶
Constants ¶
const StaleAfter = 30 * 24 * time.Hour
StaleAfter is how long without a commit makes a branch stale, when it also has no open pull request.
Variables ¶
This section is empty.
Functions ¶
func Commits ¶ added in v0.138.0
Commits lists the commits sha has that base lacks, the newest limit.
func IsStale ¶
IsStale is the deck's stale mark: no commit in StaleAfter and no open pull request. The default branch is never stale; a branch with no known commit time is not called stale.
func Landed ¶ added in v0.133.0
Landed says whether the commit sha's changes are already on base by content. Three checks, cheapest first, any one enough:
- every commit base lacks has a patch-equivalent on base (`git cherry`): a rebase or a cherry-pick;
- merging it into base changes nothing (`git merge-tree --write-tree`, git 2.38+, gives base's own tree): a plain squash merge;
- file by file, the branch's own diff (merge-base..sha) is already in that file — on base's tip, or in one of base's commits since the merge-base that touched it: every hunk's new side (its context and added lines, in order) stands in the file, as `git apply -R --check` would want; an added file was there, a deleted one gone. This finds a branch shipped inside a batch PR whose files base has edited since, or whose changelog fragment a release has consumed.
An error (an older git, an unknown commit) is "not known", never "landed". Kept per pair of commits.
func ParseAheadBehind ¶
ParseAheadBehind reads "A B" — commits ahead of and behind the base, as %(ahead-behind:) and `rev-list --left-right --count base...ref` (behind first there, see countOne) print it; nil, nil when it is not two counts.
Types ¶
type Branch ¶
type Branch struct {
Name string `json:"name"`
Current bool `json:"current,omitempty"`
Default bool `json:"default,omitempty"`
Local bool `json:"local"`
// Remote is true when origin has it.
Remote bool `json:"remote"`
// Ahead and Behind count commits against the default branch (origin's
// copy when there is one); nil when not counted.
Ahead *int `json:"ahead,omitempty"`
Behind *int `json:"behind,omitempty"`
CommittedMS int64 `json:"committed_ms"`
Author string `json:"author,omitempty"`
SHA string `json:"sha,omitempty"`
// Subject is its last commit's subject line (the release plan's row
// title for a pushed branch with no pull request).
Subject string `json:"subject,omitempty"`
}
Branch is one branch: local, on origin, or both, under its short name.
type Listing ¶
type Listing struct {
// Default is the default branch's name; Base the ref counted against
// ("origin/main", else "main"); both empty when neither is known.
Default string `json:"default,omitempty"`
Base string `json:"base,omitempty"`
Current string `json:"current,omitempty"`
Branches []Branch `json:"branches"`
}
Listing is a repository's branches and what they were compared with.