Help us shape the future of Go! Take the 2026 Go Developer Survey

engine

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package engine implements multi-branch operations over a stack.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Block

func Block(c *forge.Forge, urls map[int]string) forge.Block

Block returns c's block renderer; urls gives CR web URLs, for hosts without a short reference syntax.

func DefaultTitleBody

func DefaultTitleBody(g *git.Repo, parent, branch string) (string, string)

DefaultTitleBody derives an PR title and description from a layer's commits: a single commit gives its subject and body, otherwise the humanized branch name.

func MarkMergedByAncestry

func MarkMergedByAncestry(g *git.Repo, s *stack.Stack, trunkSHA string) []string

MarkMergedByAncestry marks layers merged when there is no host to ask: a layer with commits of its own whose tip is contained in trunkSHA. Squash merges rewrite the commits and cannot be told apart from unmerged work. Layers are marked from the bottom up and the walk stops at the first one that is not merged. It returns the names of the layers it marked.

func Push

func Push(g *git.Repo, remote string, branches []string) error

Push pushes branches to remote in one `git push`. Each branch carries an explicit --force-with-lease on the remote-tracking value, and is only pushed if that value was integrated locally (git.Repo.Includes): a commit someone else pushed, such as an applied review suggestion, is refused rather than overwritten, even right after a fetch has refreshed the tracking refs.

func RemoteStack

func RemoteStack(s *stack.Stack, known map[string]*forge.CR) *forge.StackInfo

RemoteStack returns the stack block from the first open PR of s.

func SetBody

func SetBody(c *forge.Forge, blk forge.Block, info forge.StackInfo, body string, self int) (string, error)

SetBody returns body with the stack block for CR self, checking the host's description size limit.

func StackInfo

func StackInfo(s *stack.Stack) forge.StackInfo

StackInfo builds the description-block data for s from the layers that have PRs.

func SyncMRs

func SyncMRs(c *forge.Forge, g *git.Repo, s *stack.Stack) (map[string]*forge.CR, error)

SyncMRs refreshes each unmerged layer's PR from the host and marks merged layers. It returns the PRs found, keyed by branch. Merged layers are not fetched again: merged is final on the host.

An PR found by branch name alone (no PR recorded, or the recorded one was closed) is only taken if it is open, or if it merged exactly what the local branch holds: an old merged PR whose source branch merely had the same name must not make a new layer count as merged.

func UpdateBlocks

func UpdateBlocks(c *forge.Forge, s *stack.Stack, known map[string]*forge.CR) error

UpdateBlocks rewrites the stack block in every open CR of s that needs it, and syncs the host's native stack where there is one.

Types

type Layer

type Layer struct {
	Name    string   `json:"name"`
	Orig    string   `json:"orig,omitempty"`
	Sources []string `json:"sources,omitempty"`
}

Layer is one layer of the stack after a modify: Name holds the commits of the original layers listed in Sources, in order. Orig is the layer's original name ("" for an inserted layer).

type Modifier

type Modifier struct {
	Repo  *git.Repo
	Store stack.Store
	Log   func(format string, args ...any)
	// Ref formats a CR number for messages, e.g. "!12"; nil writes "#12".
	Ref func(n int) string
	// CR names a change request in messages, e.g. "MR"; "" is "PR".
	CR string
}

Modifier applies a restructured layer list to a stack.

func (*Modifier) Abort

func (m *Modifier) Abort() error

Abort cancels a paused modify. Branches were not moved yet, so only the cherry-pick and the checkout need undoing.

func (*Modifier) Apply

func (m *Modifier) Apply(s *stack.Stack, layers []Layer) error

Apply rebuilds the stack as layers (bottom first). On success it updates s and returns nil; on a conflict it pauses with a journal (exit 3).

func (*Modifier) CheckLinear

func (m *Modifier) CheckLinear(ranges map[string]commitRange) error

CheckLinear fails if any layer contains merge commits.

func (*Modifier) Continue

func (m *Modifier) Continue(f *stack.File) error

Continue resumes after the user resolved a cherry-pick conflict, in the worktree the modify started in, whichever worktree it is run from.

func (*Modifier) Ranges

func (m *Modifier) Ranges(s *stack.Stack) (map[string]commitRange, error)

Ranges returns each active layer's own commits, keyed by branch.

type RebaseOptions

type RebaseOptions struct {
	Anchor        string // branch that --downstack/--upstack are relative to
	Downstack     bool   // trunk up to and including Anchor
	Upstack       bool   // Anchor up to the top
	NoTrunk       bool   // skip the fetch and leave the bottom layer where it is
	Remote        string // defaults to the stack's remote
	PreserveDates bool   // --committer-date-is-author-date
	// AbortOnConflict restores every branch instead of pausing on a conflict.
	AbortOnConflict bool
	// TrunkSHA, when set, is the commit to rebase the bottom layer onto: the
	// caller has already fetched and fast-forwarded (FastForwardFromRemote).
	TrunkSHA string
}

RebaseOptions selects which layers to rebase and how.

type Rebaser

type Rebaser struct {
	Repo  *git.Repo
	Store stack.Store
	Log   func(format string, args ...any)
}

Rebaser runs cascade rebases. Repo is the worktree the command was run from.

func (*Rebaser) Abort

func (r *Rebaser) Abort() error

Abort restores every layer to where it was before the rebase started.

func (*Rebaser) Continue

func (r *Rebaser) Continue(f *stack.File) error

Continue resumes a paused rebase after the user resolved conflicts.

func (*Rebaser) FastForwardFromRemote

func (r *Rebaser) FastForwardFromRemote(s *stack.Stack, remote string) (string, error)

FastForwardFromRemote is UpdateFromRemote for a caller that has just fetched.

func (*Rebaser) InProgress

func (r *Rebaser) InProgress() bool

InProgress reports whether a cascade rebase is paused.

func (*Rebaser) Preflight

func (r *Rebaser) Preflight(order []string) error

Preflight checks that the worktrees a rebase of order would touch are clean and idle.

func (*Rebaser) Start

func (r *Rebaser) Start(s *stack.Stack, o RebaseOptions) error

Start rebases the selected layers of s, bottom up, each onto the layer below it. On success it updates the recorded bases in s; the caller saves the file.

func (*Rebaser) UpdateFromRemote

func (r *Rebaser) UpdateFromRemote(s *stack.Stack, remote string) (string, error)

UpdateFromRemote fetches, fast-forwards the trunk and any layer that is behind its remote branch, and returns the SHA to rebase the bottom layer onto.

type Relation

type Relation int

Relation describes how the stack on the host compares to the local stack.

const (
	NoRemoteStack Relation = iota // no PR carries a stack block
	InSync                        // same layers
	LocalAhead                    // local has extra layers on top (submit will add them)
	RemoteAhead                   // the host has extra layers on top
	Diverged                      // anything else
)

func Compare

func Compare(s *stack.Stack, remote *forge.StackInfo) Relation

Compare relates the local stack to the remote one. Only local layers with an PR are compared: layers without one are local additions that submit will publish, unless the host has extra layers that would have to go above them.

func (Relation) String

func (r Relation) String() string

Jump to

Keyboard shortcuts

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