Documentation
¶
Overview ¶
Package stack implements plain-git stacked branch helpers. Parents resolve from PR base → local config → dot-depth name → trunk.
Index ¶
- func DotBranchDepth(b string) int
- func FormatList(root string, infos []BranchInfo) string
- func PRLabel(n int) string
- type BranchInfo
- type BranchStatus
- type ConflictMode
- type CreateOpts
- type DeleteOpts
- type Engine
- func (e *Engine) AbortOnConflict() bool
- func (e *Engine) Adopt(root string) error
- func (e *Engine) AncestorChainTo(branch string) ([]string, error)
- func (e *Engine) BranchDepth(branch string) int
- func (e *Engine) BranchNeedsRestack(branch, parent, parentRefOverride string) bool
- func (e *Engine) Create(opts CreateOpts) error
- func (e *Engine) DeleteLocal(opts DeleteOpts) error
- func (e *Engine) DescendantsOf(root string) ([]string, error)
- func (e *Engine) DivergePlaybook(branch string) string
- func (e *Engine) EnsureRemoteReady(branch string) error
- func (e *Engine) FetchIfNeeded(noFetch bool) error
- func (e *Engine) InvalidateParentCache()
- func (e *Engine) IsTrunk(name string) bool
- func (e *Engine) List(root string) ([]BranchInfo, error)
- func (e *Engine) LoadParents(opts LoadParentsOpts) error
- func (e *Engine) MaybePush(branch string, doPush bool) error
- func (e *Engine) PRNumber(branch string) int
- func (e *Engine) PRStackBranches(branch string) []string
- func (e *Engine) Parent(branch string) (string, error)
- func (e *Engine) ParentOf(branch string) string
- func (e *Engine) ParentOfWithSource(branch string) (string, ParentSource)
- func (e *Engine) Pull(branch string) error
- func (e *Engine) Reparent(opts ReparentOpts) error
- func (e *Engine) Restack(opts RestackOpts) error
- func (e *Engine) RestackBranch(branch, parent, parentRefOverride string) error
- func (e *Engine) RestackUpstream(parentRef, branchRef string) (string, error)
- func (e *Engine) SetParentLocal(branch, parent string) error
- func (e *Engine) SlashRefConflict(name string) (string, bool)
- func (e *Engine) SortByDepth(branches []string) []string
- func (e *Engine) Sync(opts SyncOpts) (*SyncResult, error)
- func (e *Engine) Track(branch, parent string) error
- func (e *Engine) TrunkRef() (string, error)
- func (e *Engine) Untrack(branch string) error
- type LoadParentsOpts
- type ParentSource
- type PlanRow
- type ReparentOpts
- type RestackOpts
- type SyncOpts
- type SyncResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DotBranchDepth ¶
DotBranchDepth is number of '.' + 1 (legacy name helper for display fallback).
func FormatList ¶
func FormatList(root string, infos []BranchInfo) string
FormatList prints ls-style lines with ASCII tree connectors and aligned columns.
Types ¶
type BranchInfo ¶
type BranchInfo struct {
Name string
Parent string
ShortSHA string
OwnCommits string
Status BranchStatus
Depth int
Remote git.RemoteRelation
// PRNumber is the open PR for this branch head, or 0 if none/unknown.
PRNumber int
// TreePrefix is ASCII connectors, e.g. "│ ├─ " (set by OrderAsTree).
TreePrefix string
}
BranchInfo is one row in the stack tree.
func OrderAsTree ¶
func OrderAsTree(infos []BranchInfo) []BranchInfo
OrderAsTree reorders infos into DFS tree order and sets TreePrefix (├─ └─ │) based on parent relationships among the listed branches.
Each branch name appears at most once. If infos contains duplicates (same Name), the entry with the higher PRNumber wins; ties keep the later entry. Parent/children edges are also de-duplicated.
type BranchStatus ¶
type BranchStatus string
BranchStatus is status for ls / TUI.
const ( StatusOK BranchStatus = "ok" StatusNeedsRestack BranchStatus = "needs-restack" StatusMissingParent BranchStatus = "missing-parent" )
type ConflictMode ¶ added in v0.1.6
type ConflictMode int
ConflictMode controls rebase failure handling.
const ( // ConflictRollback aborts a failed rebase and leaves the worktree clean. ConflictRollback ConflictMode = iota // ConflictResolve leaves the rebase in progress so conflicts can be fixed. ConflictResolve )
type CreateOpts ¶
CreateOpts for Create.
type DeleteOpts ¶
DeleteOpts for DeleteLocal.
type Engine ¶
type Engine struct {
Repo *git.Repo
Out io.Writer // info messages (stderr-like); defaults to os.Stderr
Quiet bool // suppress interactive rebase attach (use quiet rebase)
NoPush bool // ignored; push is per-call
// ConflictMode is rollback (default) or resolve. See ConflictMode.
ConflictMode ConflictMode
// contains filtered or unexported fields
}
Engine runs stack operations against a git repo.
func (*Engine) AbortOnConflict ¶ added in v0.1.6
AbortOnConflict is true when failed rebases should be aborted (rollback mode).
func (*Engine) Adopt ¶
Adopt writes local parent config from current resolution for branch and descendants.
func (*Engine) AncestorChainTo ¶
AncestorChainTo returns local stack chain from base (child of trunk) → branch, shallow first. Does not include trunk.
func (*Engine) BranchDepth ¶
BranchDepth is graph distance from trunk (0 = trunk), cycle-safe.
func (*Engine) BranchNeedsRestack ¶
BranchNeedsRestack reports whether branch is not based on parent tip.
func (*Engine) Create ¶
func (e *Engine) Create(opts CreateOpts) error
Create makes a new branch from inferred or explicit parent.
func (*Engine) DeleteLocal ¶
func (e *Engine) DeleteLocal(opts DeleteOpts) error
DeleteLocal deletes a local branch (-d or -D). Refuses trunk. If the branch is checked out, switches to its parent (or trunk) first. Clears local stack parent metadata for the deleted branch.
func (*Engine) DescendantsOf ¶
DescendantsOf returns local branches that have root as an ancestor in the parent graph (not name prefix).
func (*Engine) DivergePlaybook ¶
DivergePlaybook returns recovery help for a diverged branch (multiline).
func (*Engine) EnsureRemoteReady ¶
EnsureRemoteReady FFs if behind; returns error (with playbook) if diverged.
func (*Engine) FetchIfNeeded ¶
FetchIfNeeded fetches origin unless noFetch.
func (*Engine) InvalidateParentCache ¶
func (e *Engine) InvalidateParentCache()
InvalidateParentCache drops in-memory and on-disk PR parent cache.
func (*Engine) List ¶
func (e *Engine) List(root string) ([]BranchInfo, error)
List returns stack tree info under root (or all stacks if root empty). When root is empty, trunk is first, then every branch in a stack graph (PR parent, local parent, dots, or ancestor of such).
func (*Engine) LoadParents ¶
func (e *Engine) LoadParents(opts LoadParentsOpts) error
LoadParents populates the PR parent map (bulk gh pr list + disk cache).
func (*Engine) PRNumber ¶ added in v0.1.8
PRNumber returns the open PR number for branch, or 0 if unknown.
func (*Engine) PRStackBranches ¶
PRStackBranches returns the stack lineage for PR body display: trunk, ancestors of branch (shallow first), branch, then descendants (by depth). Used to render linked stack sections in PR descriptions.
func (*Engine) ParentOf ¶
ParentOf resolves stack parent: PR base → local gitstack-parent config → dot-depth inference → trunk.
func (*Engine) ParentOfWithSource ¶
func (e *Engine) ParentOfWithSource(branch string) (string, ParentSource)
ParentOfWithSource is ParentOf plus how it was resolved.
func (*Engine) Pull ¶
Pull runs `git pull` on branch (checks it out first if needed). Uses the branch's configured upstream and the user's pull.* settings — same as running git pull in the terminal. No custom ff/rebase logic.
func (*Engine) Reparent ¶
func (e *Engine) Reparent(opts ReparentOpts) error
Reparent moves branch onto a different parent via rebase --onto.
func (*Engine) Restack ¶
func (e *Engine) Restack(opts RestackOpts) error
Restack replays branch onto parent (or ancestor chain with OntoTrunk).
func (*Engine) RestackBranch ¶
RestackBranch restacks local branch onto parent tip. parentRefOverride is optional (e.g. refs/remotes/origin/main for --onto-trunk).
func (*Engine) RestackUpstream ¶
RestackUpstream returns the cutoff SHA: only commits after this are replayed. Prefers fork-point so rewritten parents do not pull old parent commits.
func (*Engine) SetParentLocal ¶
SetParentLocal records an explicit parent in local config. If parent is trunk or empty, unsets the key. Rejects cycles.
func (*Engine) SlashRefConflict ¶
SlashRefConflict returns an existing ancestor path segment if name uses / under an existing branch (git forbids nesting).
func (*Engine) SortByDepth ¶
SortByDepth sorts branch names by graph depth ascending, then name.
func (*Engine) Sync ¶
func (e *Engine) Sync(opts SyncOpts) (*SyncResult, error)
Sync plan-then-apply: FF, restack root, restack descendants.
func (*Engine) Track ¶
Track sets local parent metadata without rebasing. Also retargets an open PR base when possible, because PR base wins over local config in ParentOf resolution (shared team source of truth).
type LoadParentsOpts ¶
type LoadParentsOpts struct {
Offline bool // skip gh; use cache/local/dots only
Refresh bool // force gh refresh even if cache is fresh
}
LoadParentsOpts controls bulk parent loading from GitHub.
type ParentSource ¶
type ParentSource string
ParentSource explains how ParentOf resolved a parent.
const ( SourceTrunk ParentSource = "trunk" SourcePR ParentSource = "pr" SourceLocal ParentSource = "local" SourceDots ParentSource = "name" )
type PlanRow ¶
type PlanRow struct {
Branch string
Remote git.RemoteRelation
Action string
}
PlanRow is one line of a sync plan.
type ReparentOpts ¶
type ReparentOpts struct {
Branch string
NewParent string
OldParent string // optional
Push bool
NoFetch bool
}
ReparentOpts for Reparent.
type RestackOpts ¶
RestackOpts for Restack.
type SyncResult ¶
SyncResult is the planned/applied sync outcome.