branches

package
v0.185.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 13 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 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

View Source
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

func Commits(ctx context.Context, dir, base, sha string, limit int) ([]string, error)

Commits lists the commits sha has that base lacks, the newest limit.

func IsStale

func IsStale(b Branch, openPR bool, now time.Time) bool

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

func Landed(ctx context.Context, dir, base, sha string) (bool, error)

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

func ParseAheadBehind(s string) (*int, *int)

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.

func List

func List(ctx context.Context, dir, def string) (Listing, error)

List reads dir's branches: local ones and origin's, compared with the default branch (def, else origin's HEAD, else main or master). Kept for a few seconds per directory.

Jump to

Keyboard shortcuts

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