landing

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 23 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 landing is the landing of a branch whose preflight passed: the gate (a preflight receipt naming the branch's head), a plain push of the branch to origin, and the merge the repository's own rules allow. `abcd land` is its front door for any branch; the implement loop's land stage (internal/core/implement/loop) shares its lane-free primitives, so the receipt lookup, the bounded runner, the forge client's invocation and the ruleset mirror's reading are spelled once.

The package is transport-agnostic: it never writes to stdout. What a step did comes back as a Result for the front door to render.

Index

Constants

View Source
const (
	KeyPush    = "land.push"
	KeyEnqueue = "land.enqueue"
)

The landing's configuration keys, in .abcd/config.json and ~/.abcd.noindex/config.json, each a bool whose bundled default is true.

View Source
const (
	// StatusDone: the step did its act.
	StatusDone = "done"
	// StatusSkipped: the step's act was already done (a receipt names HEAD).
	StatusSkipped = "skipped"
	// StatusOff: a configuration key or a flag turned the act off.
	StatusOff = "off"
	// StatusStopped: the step cannot act yet; its note says what to do, and
	// running abcd land again resumes it.
	StatusStopped = "stopped"
	// StatusLeft: the act is a person's, and land leaves it to them.
	StatusLeft = "left"
	// StatusLanded: the branch's head is already on the default branch.
	StatusLanded = "landed"
)

The statuses a step reports.

View Source
const (
	// ForgeTimeout is the longest one forge client call may run.
	ForgeTimeout = 2 * time.Minute
	// MaxOutput bounds what a forge client call may write to stdout.
	MaxOutput = 1 << 20
)

Bounds on what the landing runs.

View Source
const PRStateQuery = `` /* 501-byte string literal not displayed */

PRStateQuery is the forge's GraphQL query for a pull request's way to the merge: `gh pr view --json` has no merge-queue field (gh 2.100.0 refuses isInMergeQueue), so the state is read through the forge's API instead.

It also reads the viewer's login (whose arming is land's own), the review decision, when and by whom the arming was made, and the head's checks with whether this pull request requires each (isRequired takes the pull request's number; with neither it nor an id the forge refuses the field). Every field is pinned in ghcontract, and testdata/ holds the forge's answers to this query.

The checks are read a page at the forge's maximum (it refuses first:101, "exceeds the `first` limit of 100 records"), with whether more follow, and each with the time it finished (completedAt; a status's createdAt), which times the toggle's grace.

View Source
const ReceiptsRelDir = TierRelDir + "/preflight-receipts"

ReceiptsRelDir is where the preflight mints its receipts, one file named by the full commit id, in any worktree of the repository (scripts/preflight-receipt.sh). A receipt is a convenience check, not a security boundary: CI re-runs every gate on the pushed commit and is the authority, and the receipt says only that a preflight passed on a tree that matched the commit.

View Source
const Remote = "origin"

Remote is the one remote a branch lands through.

View Source
const RulesetsRelDir = ".abcd/work/rulesets"

RulesetsRelDir is the committed mirror of the default branch's rulesets.

View Source
const TierRelDir = ".abcd/.work.local"

TierRelDir is the local-ephemeral tier of a checkout, repo-relative and slash-separated: gitignored, per worktree.

Variables

View Source
var ErrNoForgeClient = errors.New("the forge client `gh` is not installed")

ErrNoForgeClient is GH's answer when the forge client is not installed.

View Source
var MergeMethods = map[string]string{"MERGE": "--merge", "SQUASH": "--squash", "REBASE": "--rebase"}

MergeMethods maps a merge queue's method to the forge client's flag.

Functions

func FetchDefault

func FetchDefault(git GitFunc, dir, def string) (string, error)

FetchDefault fetches the default branch def from origin into its remote-tracking ref through git, and returns the ref. A refused fetch is a *FetchError.

func GH

func GH(dir string, args ...string) (string, error)

GH runs the forge client the repository already uses (`gh`) with args from dir, bounded by ForgeTimeout and MaxOutput, with no prompt and no update notice. Its environment is scrubbed as the networked git runner's is (gitutil.ScrubbedEnv): an inherited GIT_DIR or an injected GIT_CONFIG_* cannot aim the client's own git reads at another repository. Every value that comes from a record or a branch rides in its flag's own argument (--flag=value) at the caller, so none can be read as a flag of its own.

func Landed

func Landed(git GitFunc, dir, def, sha string) (tracking string, on bool, err error)

Landed fetches the default branch def and reports whether sha is on it as origin holds it (an ancestor of, or equal to, its tip): the one ancestry check by which a landing proves a head merged, the implement loop's and `abcd land`'s. A squash or rebase merge leaves no such ancestry; mergedAt is the forge's half of the proof for it. A refused fetch is a *FetchError; any other error is git unable to answer, which is not a no.

func Receipt

func Receipt(repoRoot, sha string) (string, error)

Receipt finds the preflight receipt for sha in any worktree git lists for the repository at repoRoot, as the pre-push hook's check does, and returns its path, or "" when none names sha. A receipt must be a regular file, never a symlink.

Types

type FetchError

type FetchError struct {
	Def string
	Err error
}

FetchError is a fetch of the default branch git refused.

func (*FetchError) Error

func (e *FetchError) Error() string

func (*FetchError) Unwrap

func (e *FetchError) Unwrap() error

type GitFunc

type GitFunc func(dir string, args ...string) (string, error)

GitFunc runs one networked git command (a fetch or a push) from dir: gitutil.Net, or a test's seam.

type ListError

type ListError struct{ Err error }

ListError is a ruleset mirror whose listing git refused.

func (*ListError) Error

func (e *ListError) Error() string

func (*ListError) Unwrap

func (e *ListError) Unwrap() error

type MergeRule

type MergeRule struct {
	Method   string
	Approval bool
	Mirrored bool
}

MergeRule is the ruleset mirror read at a commit: the merge queue's method ("" when no merge queue gates the default branch), whether an active ruleset on the default branch requires a person's approval (ruling AM1), and whether a mirror exists at all.

func ReadMergeRule

func ReadMergeRule(repoRoot, base, def, at string) (MergeRule, error)

ReadMergeRule reads the ruleset mirror at the commit base in the repository at repoRoot, for the default branch def. A missing mirror requires nothing. The base is a commit of the default branch (a lane's base, or the merge base of a branch with the default branch), so the branch's own commits cannot change the rule it lands by. at names base in a refusal ("the lane's base"). A mirror that cannot be read is a *MirrorError, a listing git refused a *ListError.

type MergedListingFullError

type MergedListingFullError struct {
	Branch string
	Listed int
}

MergedListingFullError is a listing of a branch's merged pull requests that the bound filled with none at the head: the proof may lie past the bound, so the listing cannot say the head has not merged.

func (*MergedListingFullError) Error

func (e *MergedListingFullError) Error() string

type MirrorError

type MirrorError struct {
	Reason string
	Fix    string
}

MirrorError is a ruleset mirror that cannot be read into a merge rule: Reason says what is wrong and Fix what settles it. A caller adds what to run once it is settled.

func (*MirrorError) Error

func (e *MirrorError) Error() string

type Options

type Options struct {
	// Branch is the branch to land; "" is the checkout's current branch.
	Branch string
	// NoPush and NoEnqueue are --no-push and --no-enqueue.
	NoPush    bool
	NoEnqueue bool
	// Roots are where land.push and land.enqueue are read: the working
	// directory's repository layer and the machine layer. The landed branch's
	// own checkout is read as a repository layer beside them.
	Roots layered.Roots
	// Forge runs the forge client with args from dir.
	Forge func(dir string, args ...string) (string, error)
	// Git runs one networked git command (a push or a fetch) from dir.
	Git GitFunc
	// Gate runs the preflight in the branch's checkout at dir.
	Gate func(dir string) error
	// GateOutput receives the preflight's output; nil discards it.
	GateOutput io.Writer
	// Sleep pauses between the forge readings that wait for land's own push
	// to show; nil is time.Sleep.
	Sleep func(time.Duration)
}

Options are one landing's inputs and its seams. A nil seam takes the real one: Forge is GH, Git is gitutil.Net (the networked git runner, hooks running), Gate runs `make preflight`.

type Refusal

type Refusal struct {
	Reason string
	Fix    string
}

Refusal is a landing refused: Reason says why, Fix what settles it.

func (*Refusal) Error

func (r *Refusal) Error() string

type Result

type Result struct {
	Branch   string `json:"branch"`
	Head     string `json:"head"`
	Checkout string `json:"checkout"`
	Default  string `json:"default_branch"`
	Push     Switch `json:"push"`
	Enqueue  Switch `json:"enqueue"`
	PR       int    `json:"pull_request,omitempty"`
	PRURL    string `json:"pull_request_url,omitempty"`
	// Pushed is the commit the push step sent, the head the gate checked.
	Pushed string `json:"pushed,omitempty"`
	// Landed is set when the head was already on the default branch, or the
	// forge lists PR as merged at it.
	Landed bool   `json:"landed,omitempty"`
	Steps  []Step `json:"steps"`
}

Result is the landing's report, filled as far as it got: a refused landing returns the steps it completed beside the refusal.

func Land

func Land(cwd string, o Options) (Result, error)

Land lands the branch from the checkout at cwd.

type Step

type Step struct {
	Name    string `json:"name"`
	Status  string `json:"status"`
	Note    string `json:"note"`
	Command string `json:"command,omitempty"`
}

Step is what one step of the landing did.

type Switch

type Switch struct {
	Key    string `json:"key"`
	On     bool   `json:"on"`
	Layer  string `json:"layer"`
	Origin string `json:"origin"`
}

Switch is one of the landing's two outward acts as configured: whether it is on, and the layer and origin that decided it — the bundled default when no layer turned it off, else the highest layer that did.

Jump to

Keyboard shortcuts

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