{"modulePath":"github.com/DomBlack/git-stack","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package stack\n\nPackage stack is the domain model: stacks of branches rooted at a trunk, pure navigation over them, and the ports a backend must implement.\n\n## Constants\n\n```go\nconst (\n\tMsgAlreadyTop    = \"Already at the top of the stack.\"\n\tMsgAlreadyBottom = \"Already at the bottom most branch in the stack.\"\n)\n```\nGraphite's clamp messages.\n\n## Types\n\n```go\ntype Branch struct {\n\tName string\n\t// Head is the tip commit id known to the backend (may be empty).\n\tHead string\n\t// Base is the parent's tip at the last restack (may be empty).\n\tBase string\n\tPR   *PRRef\n\t// RenamedFrom is the branch's old name when an Update renames it, so\n\t// the backend carries its record (pull request included) over to the\n\t// new name. Leaving it empty while changing Name records a new branch.\n\tRenamedFrom string\n}\n```\nBranch is one layer of a stack.\n\n```go\nfunc (b Branch) Merged() bool\n```\nMerged reports whether the branch's PR has been merged.\n\n```go\ntype Direction int\n```\nDirection of a navigation request.\n\n```go\nconst (\n\tUp Direction = iota\n\tDown\n\tTop\n\tBottom\n)\n```\n\n```go\nfunc (d Direction) String() string\n```\n\n```go\ntype Error struct {\n\tKind Kind\n\t// Msg is a one-line description.\n\tMsg string\n\t// NextSteps are concrete actions, rendered as a list.\n\tNextSteps []string\n\t// Files lists conflicted paths for KindConflict.\n\tFiles []string\n\t// Branch names the branch involved (e.g. the one being rebased).\n\tBranch string\n\t// Checks lists the pull requests whose checks stopped a merge, for\n\t// KindChecksFailing and KindChecksPending.\n\tChecks []PRChecks\n\t// Detail carries captured diagnostic output (stderr tail); never stdout.\n\tDetail string\n\t// Cause is the underlying error, if any.\n\tCause error\n}\n```\nError is the user-facing error type shared by every port and use case.\n\n```go\nfunc New(kind Kind, msg string) *Error\n```\nNew creates an Error.\n\n```go\nfunc Newf(kind Kind, format string, args ...any) *Error\n```\nNewf creates an Error with a formatted message.\n\n```go\nfunc (e *Error) Error() string\n```\n\n```go\nfunc (e *Error) Is(target error) bool\n```\nIs lets errors.Is match on kind: errors.Is(err, \u0026stack.Error{Kind: stack.KindConflict}).\n\n```go\nfunc (e *Error) Unwrap() error\n```\n\n```go\nfunc (e *Error) WithCause(err error) *Error\n```\nWithCause records the underlying error.\n\n```go\nfunc (e *Error) WithDetail(detail string) *Error\n```\nWithDetail records diagnostic output.\n\n```go\nfunc (e *Error) WithSteps(steps ...string) *Error\n```\nWithSteps appends next steps.\n\n```go\ntype Graph struct {\n\tStacks []Stack\n\t// Trunks are the distinct trunk branches in first-seen order.\n\tTrunks []string\n}\n```\nGraph holds every stack in a repository.\n\n```go\nfunc NewGraph(stacks []Stack) *Graph\n```\nNewGraph builds a Graph and derives Trunks.\n\n```go\nfunc (g *Graph) Branches() []string\n```\nBranches returns every stacked (non-trunk) branch name.\n\n```go\nfunc (g *Graph) Children(name string) []string\n```\nChildren 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.\n\n```go\nfunc (g *Graph) IsTrunk(name string) bool\n```\nIsTrunk reports whether name is the trunk of any stack.\n\n```go\nfunc (g *Graph) Parent(name string) (string, bool)\n```\nParent returns the branch below name: the previous branch in its stack, or the trunk for the bottom branch. Trunks and untracked branches have none.\n\n```go\nfunc (g *Graph) StackOf(name string) (*Stack, int, bool)\n```\nStackOf returns the stack containing the (non-trunk) branch and its index.\n\n```go\nfunc (g *Graph) StacksOn(trunk string) []*Stack\n```\nStacksOn returns the stacks rooted at trunk.\n\n```go\nfunc (g *Graph) Tracked(name string) bool\n```\nTracked reports whether name is a trunk or a stacked branch.\n\n```go\ntype Kind int\n```\nKind 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.\n\n```go\nconst (\n\tKindUnknown Kind = iota\n\t// KindNotRepo: the directory is not inside a git repository.\n\tKindNotRepo\n\t// KindNotInStack: the current branch is not tracked in any stack.\n\tKindNotInStack\n\t// KindConflict: a rebase stopped on conflicts; Files and Branch are set.\n\tKindConflict\n\t// KindAPIFailure: the forge API call failed.\n\tKindAPIFailure\n\t// KindInvalidArgs: the request is invalid for the current state.\n\tKindInvalidArgs\n\t// KindDisambiguate: the branch belongs to several stacks.\n\tKindDisambiguate\n\t// KindRebaseActive: a git rebase is already in progress.\n\tKindRebaseActive\n\t// KindLocked: the backend's stack metadata is locked or stale.\n\tKindLocked\n\t// KindStacksUnavailable: stacked PRs are not available for the repository.\n\tKindStacksUnavailable\n\t// KindModifyRecovery: the backend has an interrupted modify to recover.\n\tKindModifyRecovery\n\t// KindUnsupported: the operation is not possible with the current backend.\n\tKindUnsupported\n\t// KindNotInstalled: a required tool is missing.\n\tKindNotInstalled\n\t// KindAuthRequired: the user must log in.\n\tKindAuthRequired\n\t// KindNotAtTop: the operation needs the top of the stack.\n\tKindNotAtTop\n\t// KindInteractionRequired: a prompt, editor or TUI is needed but not available.\n\tKindInteractionRequired\n\t// KindPartial: the command did everything it could, but some of it\n\t// could not be done (the result says what); running it again after\n\t// following the next steps finishes the job.\n\tKindPartial\n\t// KindChecksFailing: a merge was refused because checks failed on\n\t// pull requests it would land; Checks says which.\n\tKindChecksFailing\n\t// KindChecksPending: a merge was refused because checks are still\n\t// running on pull requests it would land; Checks says which.\n\tKindChecksPending\n\t// KindSigningFailed: git could not sign a commit (a locked SSH key, a\n\t// gpg agent that can't prompt); nothing was committed.\n\tKindSigningFailed\n\t// KindStateMigration: the backend's stack metadata is in an older or\n\t// half converted layout that has to be sorted out first.\n\tKindStateMigration\n)\n```\n\n```go\nfunc (k Kind) Code() string\n```\nCode is the stable machine-readable name of the kind.\n\n```go\nfunc (k Kind) String() string\n```\n\n```go\ntype LinkOptions struct {\n\t// Stack is the remote stack to add the pull requests to; 0 starts a new\n\t// one, which needs at least two pull requests.\n\tStack int\n\t// Trunk is the base of the bottom pull request of a new stack.\n\tTrunk string\n\t// PRs are pull request numbers, bottom to top.\n\tPRs []int\n}\n```\nLinkOptions controls Submitter.Link.\n\n```go\ntype Metadata interface {\n\tLoad(ctx context.Context, repo git.Repo) (*Graph, error)\n\t// Update loads the graph fresh under the backend's lock, lets fn edit it\n\t// and writes the result back. fn may edit each stack's Branches (remove\n\t// entries, change Head and Base, rename one by setting Name and\n\t// RenamedFrom) and may also append stacks (each with a\n\t// trunk and at least one branch) and may set or clear a stack's ID and Number (clearing\n\t// removes them from the record). It must not remove or reorder existing\n\t// stacks; a stack left with no branches is removed. When fn returns an\n\t// error nothing is written and the error is returned.\n\tUpdate(ctx context.Context, repo git.Repo, fn func(*Graph) error) error\n\t// Snapshot reads the metadata exactly as stored, under the backend's\n\t// lock.\n\tSnapshot(ctx context.Context, repo git.Repo) (Snapshot, error)\n\t// Restore writes a snapshot back byte for byte under the lock, removing\n\t// the files that did not exist when it was taken.\n\tRestore(ctx context.Context, repo git.Repo, s Snapshot) error\n}\n```\nMetadata reads and edits the stack graph. Load must be fast and offline: shell completion depends on it.\n\n```go\ntype NavRequest struct {\n\tFrom string\n\tDir  Direction\n\t// Steps for Up/Down; 0 means 1.\n\tSteps int\n\t// To optionally names a branch that must lie in the chosen direction. It\n\t// selects between several children today only where the graph branches\n\t// (a trunk with several stacks); stacks themselves are linear.\n\tTo string\n}\n```\nNavRequest asks to move from a branch along the stack.\n\n```go\ntype NavResult struct {\n\tTarget string\n\t// Moved is the number of levels actually traversed.\n\tMoved int\n\t// Clamped is true when the request hit the end of the stack.\n\tClamped bool\n\t// Message explains a clamp in Graphite's words.\n\tMessage string\n}\n```\nNavResult is the computed destination.\n\n```go\nfunc Navigate(g *Graph, req NavRequest) (NavResult, error)\n```\nNavigate 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.\n\n```go\ntype PRChecks struct {\n\tNumber int    `json:\"number\"`\n\tBranch string `json:\"branch\"`\n\t// Failing checks finished without passing.\n\tFailing []string `json:\"failing,omitempty\"`\n\t// Pending checks are queued or still running.\n\tPending []string `json:\"pending,omitempty\"`\n}\n```\nPRChecks names the checks holding up one pull request.\n\n```go\ntype PRRef struct {\n\tNumber int\n\tURL    string\n\tMerged bool\n}\n```\nPRRef is the backend's snapshot of a branch's pull request.\n\n```go\ntype Scope int\n```\nScope selects which part of the current stack an operation covers.\n\n```go\nconst (\n\tScopeAll Scope = iota\n\tScopeUpstack\n\tScopeDownstack\n\tScopeOnly\n)\n```\n\n```go\nfunc (s Scope) String() string\n```\n\n```go\ntype Snapshot struct {\n\t// Files maps each metadata file's path to its contents; an empty value\n\t// records that the file did not exist.\n\tFiles map[string][]byte `json:\"files\"`\n}\n```\nSnapshot is the backend's metadata exactly as stored, opaque to everything but the backend that made it.\n\n```go\ntype Stack struct {\n\t// ID is the backend's remote identifier, if any.\n\tID string\n\t// Number is the backend's repo-scoped stack number, if any.\n\tNumber int\n\tTrunk  string\n\t// Branches run bottom (closest to trunk) to top.\n\tBranches []Branch\n}\n```\nStack is an ordered, linear list of branches on top of a trunk.\n\n```go\nfunc (s *Stack) Bottom() string\n```\nBottom is the branch directly above trunk (\"\" for an empty stack).\n\n```go\nfunc (s *Stack) Index(name string) int\n```\nIndex returns the position of name in the stack, or -1.\n\n```go\nfunc (s *Stack) Names() []string\n```\nNames returns the branch names bottom to top.\n\n```go\nfunc (s *Stack) Top() string\n```\nTop is the branch furthest from trunk (\"\" for an empty stack).\n\n```go\ntype SubmitOptions struct {\n\t// Publish creates PRs ready for review instead of drafts.\n\tPublish bool\n\t// Interactive lets the backend open its own editor on the terminal.\n\tInteractive bool\n}\n```\nSubmitOptions controls Submitter.Submit.\n\n```go\ntype SubmitResult struct {\n\tOutput string\n\t// Streamed is true when Output was already written to the user's\n\t// terminal as it was produced, so callers must not print it again.\n\tStreamed bool\n}\n```\nSubmitResult carries the backend's human-readable output for relaying.\n\n```go\ntype Submitter interface {\n\tSubmit(ctx context.Context, repo git.Repo, o SubmitOptions) (SubmitResult, error)\n\t// Link joins pull requests that already exist into a stack on the\n\t// remote, without pushing any branch.\n\tLink(ctx context.Context, repo git.Repo, o LinkOptions) (SubmitResult, error)\n\n\t// Unstack dissolves the stack with the given number on the forge,\n\t// leaving its pull requests open and unstacked, so the next Submit\n\t// creates it again from the local order. A stack the forge no longer\n\t// has is not an error. The number must not be tracked locally any\n\t// more, or gh stack would remove the local record too.\n\tUnstack(ctx context.Context, repo git.Repo, number int) error\n}\n```\nSubmitter pushes the current stack and creates or updates its PRs.\n\n```go\ntype Tracker interface {\n\t// InitStack creates a new stack on trunk from the given branch names.\n\t// Existing branches are adopted, missing ones are created from the\n\t// previous branch, and the last one is checked out.\n\tInitStack(ctx context.Context, repo git.Repo, trunk string, branches []string) error\n\t// AddTop creates (or adopts) name on top of the current stack and checks\n\t// it out. The current branch must be the top of its stack.\n\tAddTop(ctx context.Context, repo git.Repo, name string) error\n\t// ImportStack pulls down the forge stack holding target, a pull\n\t// request number or a branch name: it creates the local branches it\n\t// is missing (leaving ones that exist alone), records the stack and\n\t// checks out target's branch. A target in no stack on the forge is a\n\t// *Error of KindNotInStack.\n\tImportStack(ctx context.Context, repo git.Repo, target string) error\n}\n```\nTracker registers branches with the backend.\n\n","path":"github.com/DomBlack/git-stack/pkg/stack","name":"stack","synopsis":"Package stack is the domain model: stacks of branches rooted at a trunk, pure navigation over them, and the ports a backend must implement.","isRedistributable":true}
