Documentation
¶
Overview ¶
Package stack is the domain model: stacks of branches rooted at a trunk, pure navigation over them, and the ports a backend must implement.
Index ¶
- Constants
- type Branch
- type Direction
- type Error
- type Graph
- func (g *Graph) Branches() []string
- func (g *Graph) Children(name string) []string
- func (g *Graph) IsTrunk(name string) bool
- func (g *Graph) Parent(name string) (string, bool)
- func (g *Graph) StackOf(name string) (*Stack, int, bool)
- func (g *Graph) StacksOn(trunk string) []*Stack
- func (g *Graph) Tracked(name string) bool
- type Kind
- type Metadata
- type NavRequest
- type NavResult
- type PRRef
- type Scope
- type Stack
- type SubmitOptions
- type SubmitResult
- type Submitter
- type Tracker
Constants ¶
const ( MsgAlreadyTop = "Already at the top of the stack." MsgAlreadyBottom = "Already at the bottom most branch in the stack." )
Graphite's clamp messages.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Branch ¶
type Branch struct {
Name string
// Head is the tip commit id known to the backend (may be empty).
Head string
// Base is the parent's tip at the last restack (may be empty).
Base string
PR *PRRef
}
Branch is one layer of a stack.
type Error ¶
type Error struct {
Kind Kind
// Msg is a one-line description.
Msg string
// NextSteps are concrete actions, rendered as a list.
NextSteps []string
// Files lists conflicted paths for KindConflict.
Files []string
// Branch names the branch involved (e.g. the one being rebased).
Branch string
// Detail carries captured diagnostic output (stderr tail); never stdout.
Detail string
// Cause is the underlying error, if any.
Cause error
}
Error is the user-facing error type shared by every port and use case.
func (*Error) Is ¶
Is lets errors.Is match on kind: errors.Is(err, &stack.Error{Kind: stack.KindConflict}).
func (*Error) WithDetail ¶
WithDetail records diagnostic output.
type Graph ¶
type Graph struct {
Stacks []Stack
// Trunks are the distinct trunk branches in first-seen order.
Trunks []string
}
Graph holds every stack in a repository.
func (*Graph) Children ¶
Children returns the branches directly above name. For a stacked branch that is at most one branch today (stacks are linear); for a trunk it is the bottom branch of every stack rooted there.
func (*Graph) Parent ¶
Parent returns the branch below name: the previous branch in its stack, or the trunk for the bottom branch. Trunks and untracked branches have none.
type Kind ¶
type Kind int
Kind classifies an Error so that the CLI can pick an exit code and message style and the MCP server can return a machine-readable code.
const ( KindUnknown Kind = iota // KindNotRepo: the directory is not inside a git repository. KindNotRepo // KindNotInStack: the current branch is not tracked in any stack. KindNotInStack // KindConflict: a rebase stopped on conflicts; Files and Branch are set. KindConflict // KindAPIFailure: the forge API call failed. KindAPIFailure // KindInvalidArgs: the request is invalid for the current state. KindInvalidArgs // KindDisambiguate: the branch belongs to several stacks. KindDisambiguate // KindRebaseActive: a git rebase is already in progress. KindRebaseActive // KindLocked: the backend's stack metadata is locked or stale. KindLocked KindStacksUnavailable // KindModifyRecovery: the backend has an interrupted modify to recover. KindModifyRecovery // KindUnsupported: the operation is not possible with the current backend. KindUnsupported // KindNotInstalled: a required tool is missing. KindNotInstalled // KindAuthRequired: the user must log in. KindAuthRequired // KindNotAtTop: the operation needs the top of the stack. KindNotAtTop // KindInteractionRequired: a prompt, editor or TUI is needed but not available. KindInteractionRequired )
type Metadata ¶
type Metadata interface {
Load(ctx context.Context, repo git.Repo) (*Graph, error)
// Update loads the graph fresh under the backend's lock, lets fn edit it
// and writes the result back. fn may edit each stack's Branches (remove
// entries, change Head and Base) but must not add, remove or reorder
// stacks; a stack left with no branches is removed. When fn returns an
// error nothing is written and the error is returned.
Update(ctx context.Context, repo git.Repo, fn func(*Graph) error) error
}
Metadata reads and edits the stack graph. Load must be fast and offline: shell completion depends on it.
type NavRequest ¶
type NavRequest struct {
Steps int
// selects between several children today only where the graph branches
// (a trunk with several stacks); stacks themselves are linear.
To string
}
NavRequest asks to move from a branch along the stack.
type NavResult ¶
NavResult is the computed destination.
func Navigate ¶
func Navigate(g *Graph, req NavRequest) (NavResult, error)
Navigate computes the destination of req without touching git. Merged branches are skipped as destinations (they are no longer real layers) unless the request starts on one. Moving down from the bottom branch lands on the trunk, as in Graphite.
type Stack ¶
type Stack struct {
// ID is the backend's remote identifier, if any.
ID string
// Number is the backend's repo-scoped stack number, if any.
Number int
Trunk string
// Branches run bottom (closest to trunk) to top.
Branches []Branch
// Worktree is the working tree whose metadata holds this stack (gh stack
// keeps stacks per worktree), or empty when unknown. Sync runs there.
Worktree string
}
Stack is an ordered, linear list of branches on top of a trunk.
type SubmitOptions ¶
type SubmitOptions struct {
// Publish creates PRs ready for review instead of drafts.
Publish bool
// Interactive lets the backend open its own editor on the terminal.
Interactive bool
}
SubmitOptions controls Submitter.Submit.
type SubmitResult ¶
type SubmitResult struct {
Output string
// Streamed is true when Output was already written to the user's
// terminal as it was produced, so callers must not print it again.
Streamed bool
}
SubmitResult carries the backend's human-readable output for relaying.
type Submitter ¶
type Submitter interface {
Submit(ctx context.Context, repo git.Repo, o SubmitOptions) (SubmitResult, error)
}
Submitter pushes the current stack and creates or updates its PRs.
type Tracker ¶
type Tracker interface {
// InitStack creates a new stack on trunk from the given branch names.
// Existing branches are adopted, missing ones are created from the
// previous branch, and the last one is checked out.
InitStack(ctx context.Context, repo git.Repo, trunk string, branches []string) error
// AddTop creates (or adopts) name on top of the current stack and checks
// it out. The current branch must be the top of its stack.
AddTop(ctx context.Context, repo git.Repo, name string) error
}
Tracker registers branches with the backend.