Documentation
¶
Overview ¶
Package app holds the use cases. Both the cobra commands and the MCP tools call into it, so no behaviour lives anywhere else.
Index ¶
- Constants
- Variables
- func FindPRTemplate(topLevel string) (string, bool)
- func PRsFor(prs []forge.PullRequest) map[string]forge.PullRequest
- func Slug(s string) string
- type AbsorbHunk
- type AbsorbOptions
- type AbsorbPlan
- type AbsorbResult
- type AbsorbSkipped
- type AbsorbTarget
- type App
- func (a *App) Absorb(ctx context.Context, repo git.Repo, o AbsorbOptions) (AbsorbResult, error)
- func (a *App) BranchPR(ctx context.Context, repo git.Repo, branch string) (forge.PullRequest, error)
- func (a *App) CachedPRs(repo git.Repo) ([]forge.PullRequest, cache.State, time.Time)
- func (a *App) Checkout(ctx context.Context, repo git.Repo, name string) error
- func (a *App) Create(ctx context.Context, repo git.Repo, o CreateOptions) (CreateResult, error)
- func (a *App) Doctor(ctx context.Context, repo *git.Repo, o DoctorOptions) (DoctorResult, error)
- func (a *App) Fold(ctx context.Context, repo git.Repo, o FoldOptions) (FoldResult, error)
- func (a *App) Get(ctx context.Context, repo git.Repo, o GetOptions) (GetResult, error)
- func (a *App) Init(ctx context.Context, repo git.Repo, o InitOptions) (InitResult, error)
- func (a *App) Merge(ctx context.Context, repo git.Repo, o MergeOptions) (MergeResult, error)
- func (a *App) Modify(ctx context.Context, repo git.Repo, o ModifyOptions) (ModifyResult, error)
- func (a *App) Move(ctx context.Context, repo git.Repo, o MoveOptions) (MoveResult, error)
- func (a *App) MoveDestinations(graph *stack.Graph, source string) []MoveDestination
- func (a *App) Navigate(ctx context.Context, repo git.Repo, req stack.NavRequest) (stack.NavResult, error)
- func (a *App) PRURLs(ctx context.Context, repo git.Repo) func(number int) string
- func (a *App) Pop(ctx context.Context, repo git.Repo) (PopResult, error)
- func (a *App) RefreshPRs(ctx context.Context, repo git.Repo) ([]forge.PullRequest, error)
- func (a *App) Rename(ctx context.Context, repo git.Repo, o RenameOptions) (RenameResult, error)
- func (a *App) Reorder(ctx context.Context, repo git.Repo, o ReorderOptions) (ReorderResult, error)
- func (a *App) Restack(ctx context.Context, repo git.Repo, o RestackOptions) (RestackResult, error)
- func (a *App) Submit(ctx context.Context, repo git.Repo, o SubmitOptions) (SubmitResult, error)
- func (a *App) Sync(ctx context.Context, repo git.Repo, o SyncOptions) (SyncResult, error)
- func (a *App) Trunk(ctx context.Context, repo git.Repo) (string, error)
- func (a *App) Undo(ctx context.Context, repo git.Repo, o UndoOptions) (UndoResult, error)
- func (a *App) Untrack(ctx context.Context, repo git.Repo, o UntrackOptions) (UntrackResult, error)
- func (a *App) View(ctx context.Context, repo git.Repo, o ViewOptions) (*View, error)
- type BranchMove
- type ClosedPR
- type Commit
- type CommitInfo
- type Conflict
- type CreateOptions
- type CreateResult
- type DeletedBranch
- type Deps
- type DoctorOptions
- type DoctorResult
- type FoldOptions
- type FoldResult
- type GetOptions
- type GetResult
- type InitOptions
- type InitResult
- type KeptBranch
- type MergeOptions
- type MergeResult
- type MergedPR
- type ModifyOptions
- type ModifyResult
- type MoveDestination
- type MoveOptions
- type MoveResult
- type NotUpdated
- type PRMode
- type PRSnapshot
- type PRText
- type Phase
- type PopResult
- type Prompter
- type RemoteAhead
- type RenameOptions
- type RenameResult
- type ReorderOptions
- type ReorderResult
- type RestackOptions
- type RestackResult
- type Row
- type StagingMode
- type SubmitOptions
- type SubmitResult
- type SubmittedPR
- type SyncOptions
- type SyncResult
- type TrunkSync
- type UndoEntryView
- type UndoOptions
- type UndoResult
- type UntrackOptions
- type UntrackResult
- type View
- type ViewOptions
Constants ¶
const ( // GetLocal: the stack was already tracked here; it was only brought up // to date with the remote. GetLocal = "local" // GetStack: the stack was pulled down from GitHub's stacks. GetStack = "stack" // GetPRs: the pull request is in no stack on GitHub, so it and the // open pull requests it is based on were tracked as a new stack. GetPRs = "prs" )
Where Get found its target.
const ( TrunkUpToDate = "up-to-date" TrunkAhead = "ahead" // local commits the remote doesn't have; left alone TrunkFastForwarded = "fast-forwarded" TrunkReset = "reset" // diverged and reset to the remote with consent TrunkDiverged = "diverged" TrunkDirty = "dirty" TrunkNoRemote = "no-remote" // TrunkNotUpdated: the trunk should have moved but its checkout could // not be updated; NotUpdated says why. TrunkNotUpdated = "not-updated" )
Trunk statuses.
const ( // NotUpdatedDirty: uncommitted changes in its checkout would be // overwritten (Changed, and Untracked if there are those too). The // user's own work is in the way, so this is a warning, not a failure. NotUpdatedDirty = "dirty" // NotUpdatedUntracked: untracked files in its checkout are where the // update would write (Untracked). Also a warning. NotUpdatedUntracked = "untracked" // NotUpdatedLocked: another git process held a lock the update needed: // the checkout's index lock for longer than the retry budget (LockKind // "index"), or the branch's ref lock (LockKind "ref", never retried in a // checkout and possible for a branch with no checkout). Lock is the file. // Sync fails so it gets run again. NotUpdatedLocked = "locked" // NotUpdatedRefused: git would not move the checkout for any reason // other than the user's files being in the way (those are dirty and // untracked) or a held lock, e.g. a merge in progress there. Sync fails. NotUpdatedRefused = "refused" )
Reasons a branch sync meant to move was left where it was.
const ( ReasonMerged = "merged" ReasonClosed = "closed" ReasonInTrunk = "in-trunk" ReasonGone = "gone" // already deleted locally; only the metadata changed )
Why a branch was deleted.
const ( KeptPolicy = "policy" KeptOtherWorktree = "other-worktree" KeptDirty = "dirty" KeptNotInTrunk = "not-in-trunk" KeptNoTrunk = "no-trunk" KeptUnpushed = "unpushed" )
Why a candidate was kept.
const MaxCommits = 10
MaxCommits is how many of a branch's own commits a Row carries; the rest are only counted, in Row.MoreCommits.
Variables ¶
var ErrNoForge = stack.New(stack.KindUnsupported, "no forge configured for pull requests")
ErrNoForge is returned when no forge adapter is configured.
Functions ¶
func FindPRTemplate ¶
FindPRTemplate returns the repository's pull request template, if any, with YAML front matter removed. The lookup mirrors gh: a regular file named pull_request_template.* in .github/, the root, or docs/.
func PRsFor ¶
func PRsFor(prs []forge.PullRequest) map[string]forge.PullRequest
PRsFor picks the pull request to show for each branch: an open or draft PR wins over merged, which wins over closed; ties go to the most recent.
Types ¶
type AbsorbHunk ¶ added in v0.3.0
type AbsorbHunk struct {
Path string `json:"path"`
// OldStart and OldCount locate the lines in HEAD; an insertion has
// OldCount 0 and goes after line OldStart.
OldStart int `json:"old_start"`
OldCount int `json:"old_count"`
NewCount int `json:"new_count"`
// Target is nil when no commit in the stack changed those lines; the
// hunk stays staged.
Target *AbsorbTarget `json:"target,omitempty"`
}
AbsorbHunk is one staged run of changed lines and where it goes.
type AbsorbOptions ¶ added in v0.3.0
type AbsorbOptions struct {
Staging StagingMode
// DryRun plans and shows where everything would go, changing no commit.
DryRun bool
// Force skips the confirmation on a terminal.
Force bool
// Preview, when set, is shown the plan before anything is asked or
// changed. The CLI renders it; the MCP tool reads it off the result.
Preview func(*AbsorbPlan)
}
AbsorbOptions mirrors `gt absorb`.
type AbsorbPlan ¶ added in v0.3.0
type AbsorbPlan struct {
Hunks []AbsorbHunk `json:"hunks"`
Skipped []AbsorbSkipped `json:"skipped,omitempty"`
// Absorbed and Unabsorbed count hunks; Commits counts the distinct
// destination commits.
Absorbed int `json:"absorbed"`
Unabsorbed int `json:"unabsorbed"`
Commits int `json:"commits"`
}
AbsorbPlan is where every staged change goes.
type AbsorbResult ¶ added in v0.3.0
type AbsorbResult struct {
Branch string `json:"branch"`
Plan AbsorbPlan `json:"plan"`
DryRun bool `json:"dry_run"`
// Applied is false on a dry run, when there was nothing to absorb or
// when the user said no.
Applied bool `json:"applied"`
// Rewritten lists the branches that moved, bottom to top.
Rewritten []BranchMove `json:"rewritten,omitempty"`
// Restacked lists the branches above that were rebased afterwards.
Restacked []string `json:"restacked,omitempty"`
Notices []string `json:"notices,omitempty"`
}
AbsorbResult reports what absorb did.
type AbsorbSkipped ¶ added in v0.3.0
AbsorbSkipped is a staged file absorb never plans, and why.
type AbsorbTarget ¶ added in v0.3.0
type AbsorbTarget struct {
SHA string `json:"sha"`
Subject string `json:"subject"`
Branch string `json:"branch"`
}
AbsorbTarget is the commit a hunk goes into.
type App ¶
type App struct {
// contains filtered or unexported fields
}
App exposes the use cases.
func (*App) Absorb ¶ added in v0.3.0
func (a *App) Absorb(ctx context.Context, repo git.Repo, o AbsorbOptions) (AbsorbResult, error)
Absorb folds each staged hunk into the commit of the current stack that last changed those lines, rewrites that commit and everything above it up to the current branch, and restacks the branches above.
func (*App) BranchPR ¶ added in v0.4.0
func (a *App) BranchPR(ctx context.Context, repo git.Repo, branch string) (forge.PullRequest, error)
BranchPR finds the pull request of a stacked branch (the current one when branch is ""). Local state answers first, the PR cache then gh stack's metadata, the same order View applies them in; the forge is only asked when neither knows the branch's PR, i.e. one opened outside git-stack or since the cache was last filled. The result always has a URL.
func (*App) Create ¶
func (a *App) Create(ctx context.Context, repo git.Repo, o CreateOptions) (CreateResult, error)
Create stages, creates a branch on top of the current one, commits and registers the branch with the backend. With Insert on a branch that is not the top of its stack, the branch goes in right above the current one and the branches above are restacked onto it afterwards.
func (*App) Doctor ¶ added in v0.5.0
func (a *App) Doctor(ctx context.Context, repo *git.Repo, o DoctorOptions) (DoctorResult, error)
Doctor checks that git-stack has what it needs (git, gh, gh-stack and its version) and, inside a repository, that its stacks are in good shape. With Fix it tries to put right what it can and checks again. repo is nil outside a repository. Problems are in the result, not the error; the error is only for being interrupted.
func (*App) Fold ¶ added in v0.4.0
func (a *App) Fold(ctx context.Context, repo git.Repo, o FoldOptions) (FoldResult, error)
Fold merges the current branch and its parent into one branch, the parent's (or with Keep the current one's), and queues the other's pull request to be closed at the next submit. The current branch must sit on its parent, so nothing needs restacking: the branches above already have every commit involved and only their recorded parent changes.
func (*App) Get ¶ added in v0.5.0
Get pulls a pull request's stack down from the remote and checks out its branch: every branch below it in the stack (and above it, when the stack is on GitHub) is created locally if it isn't already, tracked, and fast forwarded where the remote is ahead. A stack tracked here already is only brought up to date. Nothing is rebased or pushed.
func (*App) Init ¶ added in v0.3.0
func (a *App) Init(ctx context.Context, repo git.Repo, o InitOptions) (InitResult, error)
Init records a new stack from branches that already exist. It changes no ref and checks nothing out.
func (*App) Merge ¶ added in v0.1.5
func (a *App) Merge(ctx context.Context, repo git.Repo, o MergeOptions) (MergeResult, error)
Merge lands the pull requests of the current stack up to and including a branch, in one all or nothing operation on the forge, then syncs so the merged branches go and whatever is left above is restacked onto trunk. Nothing is merged while any pull request in the way is missing, a draft or closed, or (unless Force) has a check that failed or is still running; the forge's own rules (required checks, reviews) apply on top.
func (*App) Modify ¶
func (a *App) Modify(ctx context.Context, repo git.Repo, o ModifyOptions) (ModifyResult, error)
Modify amends (or adds to) the current branch and restacks its descendants.
func (*App) Move ¶ added in v0.3.0
func (a *App) Move(ctx context.Context, repo git.Repo, o MoveOptions) (MoveResult, error)
Move puts a branch (and, unless Only, everything above it) on top of another stack or on a trunk as a new stack, then restacks what moved and what was left behind. Nothing is checked out.
func (*App) MoveDestinations ¶ added in v0.3.0
func (a *App) MoveDestinations(graph *stack.Graph, source string) []MoveDestination
MoveDestinations lists where source could go: every trunk, then the top of every stack other than source's own, in graph order.
func (*App) Navigate ¶
func (a *App) Navigate(ctx context.Context, repo git.Repo, req stack.NavRequest) (stack.NavResult, error)
Navigate moves along the current stack (up/down/top/bottom) and checks out the destination. The pure computation lives in stack.Navigate.
func (*App) PRURLs ¶ added in v0.2.0
PRURLs returns a lookup from pull request number to web URL for decorating output. It only uses local state: the URLs recorded in the stack metadata and the PR cache, then the forge's own URL scheme for a number neither knows (a PR gh stack has only just created). It never touches the network, and answers "" for a number it can't place.
func (*App) Pop ¶ added in v0.4.0
Pop deletes the current branch and takes it out of its stack, leaving its changes staged on its parent. The branches above are restacked onto the parent first, while the popped branch is still checked out, and its pull request is queued to close at the next submit.
func (*App) RefreshPRs ¶
RefreshPRs fetches pull requests from the forge and updates the cache.
func (*App) Rename ¶ added in v0.4.0
func (a *App) Rename(ctx context.Context, repo git.Repo, o RenameOptions) (RenameResult, error)
Rename gives the current branch a new name, keeping its place in the stack, its commits and its recorded base; nothing is restacked. A branch that has been pushed is renamed on the forge first, which keeps its pull request attached and retargets the ones based on it, so a refusal there leaves everything here as it was. With Local only this repository changes.
func (*App) Reorder ¶ added in v0.3.0
func (a *App) Reorder(ctx context.Context, repo git.Repo, o ReorderOptions) (ReorderResult, error)
Reorder changes the order of the branches in the current stack and restacks it. Nothing is checked out.
func (*App) Restack ¶
func (a *App) Restack(ctx context.Context, repo git.Repo, o RestackOptions) (RestackResult, error)
Restack rebases part of the current stack onto its parents, locally and without checking anything out, the way gt restack does. The bottom branch goes onto the local trunk. A conflict stops at that branch.
func (*App) Submit ¶
func (a *App) Submit(ctx context.Context, repo git.Repo, o SubmitOptions) (SubmitResult, error)
Submit pushes the current stack and creates or updates its pull requests. With Down or Branch it stops at a branch; when branches above it are left out, submitPart does the work instead of gh stack submit.
func (*App) Sync ¶
func (a *App) Sync(ctx context.Context, repo git.Repo, o SyncOptions) (SyncResult, error)
Sync fetches, moves trunk, deletes merged branches, pulls in branches the remote advanced and restacks every stack, the way gt sync does. Nothing is pushed; submit does that.
func (*App) Trunk ¶
Trunk returns the trunk to use from the current position: the trunk of the current stack, the current branch if it is a trunk, or the only trunk.
func (*App) Undo ¶ added in v0.4.0
func (a *App) Undo(ctx context.Context, repo git.Repo, o UndoOptions) (UndoResult, error)
Undo reverses the newest command recorded in this worktree: every branch it covered goes back to its tip from before, the metadata and the GitHub queue are put back byte for byte, and checked out branches follow, softly (changes come back staged) or keeping local changes, by the command's mode. Nothing moves when anything would refuse.
func (*App) Untrack ¶ added in v0.4.0
func (a *App) Untrack(ctx context.Context, repo git.Repo, o UntrackOptions) (UntrackResult, error)
Untrack takes a branch, and unless Only everything above it, out of its stack without touching the branches themselves: a stack is a single line, so it can't keep a gap. With Only the branches above close the gap and are restacked onto the untracked branch's parent, dropping its commits. A stack GitHub knows is queued to be dissolved at the next submit; no pull request is closed.
type BranchMove ¶ added in v0.1.4
type BranchMove struct {
Name string `json:"name"`
Stack string `json:"stack,omitempty"` // the stack's bottom branch
From string `json:"from"`
To string `json:"to"`
}
BranchMove is a branch whose tip moved.
type ClosedPR ¶ added in v0.4.0
type ClosedPR struct {
Number int `json:"number"`
Branch string `json:"branch"`
// BranchDeleted is false when the remote branch had to stay because an
// open pull request is still based on it.
BranchDeleted bool `json:"branchDeleted"`
}
ClosedPR is a queued pull request a submit closed.
type CommitInfo ¶
CommitInfo identifies a commit for output.
type Conflict ¶ added in v0.1.4
type Conflict struct {
Stack string `json:"stack"`
Branch string `json:"branch"`
Onto string `json:"onto"`
Files []string `json:"files,omitempty"`
}
Conflict is a branch that could not be restacked.
type CreateOptions ¶
type CreateOptions struct {
// Name is the explicit branch name (used as-is, no prefix).
Name string
// Message paragraphs for the commit; empty opens the editor when
// something is staged.
Message []string
Staging StagingMode
// UseAI drafts the branch name (and the message when none is given).
UseAI bool
NoVerify bool
// Insert puts the branch directly above the current one, in the middle
// of its stack, and restacks the branches that were above onto it.
Insert bool
}
CreateOptions mirrors `gt create`.
type CreateResult ¶
type CreateResult struct {
Branch string `json:"branch"`
Parent string `json:"parent"`
Commit *CommitInfo `json:"commit,omitempty"`
// NewStack is true when the branch started a new stack on trunk.
NewStack bool `json:"newStack"`
// Inserted is true when the branch went in below other branches of the
// stack; Restacked lists the ones moved onto it, bottom to top.
Inserted bool `json:"inserted,omitempty"`
Restacked []string `json:"restacked,omitempty"`
}
CreateResult reports what happened.
type DeletedBranch ¶ added in v0.1.4
type DeletedBranch struct {
Name string `json:"name"`
Head string `json:"head,omitempty"`
Reason string `json:"reason"`
}
DeletedBranch is a branch sync deleted and why.
type Deps ¶
type Deps struct {
Git *git.Client
Meta stack.Metadata
Tracker stack.Tracker
Submit stack.Submitter
Forge forge.Forge
AI ai.Drafter
Cache *cache.Store
Config *config.Config
Log *slog.Logger
Prompter Prompter
// Doctors contribute checks to Doctor beyond the ones the use cases
// make themselves (the backend checks gh and gh-stack).
Doctors []doctor.Provider
// Progress, when set, wraps slow operations (backend calls, AI calls) so
// the CLI can show a headline and spinner. It must run fn and return its
// error. The phase says what kind of work it is; the message is the
// headline without decoration ("Submitting stack").
Progress func(ctx context.Context, phase Phase, message string, fn func(ctx context.Context) error) error
}
Deps are the ports an App needs. Optional ports may be nil; the use cases that need them return KindUnsupported / KindNotInstalled errors.
type DoctorOptions ¶ added in v0.5.0
type DoctorOptions struct {
// Fix runs the fix of every check that failed or warned and has one,
// then checks again.
Fix bool
// Extra are checks this run adds to the ones from Deps.Doctors (the
// CLI adds git-stack's own aliases and release).
Extra []doctor.Provider
}
DoctorOptions controls Doctor.
type DoctorResult ¶ added in v0.5.0
type DoctorResult struct {
// Checks is the tree, for rendering; List is the same checks flat,
// each naming its parent, for JSON.
Checks []doctor.Result `json:"-"`
List []doctor.Result `json:"checks"`
// Failed and Warned count the checks left failing or warning; Fixed
// those --fix put right.
Failed int `json:"failed"`
Warned int `json:"warned"`
Fixed int `json:"fixed"`
// Fixable counts the checks still failing or warning that --fix could
// try (zero after a --fix run unless a fix failed).
Fixable int `json:"fixable"`
}
DoctorResult is every check, in the order they ran, each with the checks that hang off it.
type FoldOptions ¶ added in v0.4.0
type FoldOptions struct {
// Keep keeps the current branch's name and pull request instead of
// the parent's.
Keep bool
}
FoldOptions is one fold of the current branch into its parent.
type FoldResult ¶ added in v0.4.0
type FoldResult struct {
// Into is the branch that survives, Folded the one that's gone.
Into string `json:"into"`
Folded string `json:"folded"`
// Closing is the pull request queued to close at the next submit, 0 if
// none.
Closing int `json:"closing,omitempty"`
Notices []string `json:"notices,omitempty"`
}
FoldResult reports what happened.
type GetOptions ¶ added in v0.5.0
type GetOptions struct {
// Target is a pull request number (123 or #123), a pull request URL or
// a branch name.
Target string
}
GetOptions names what to pull down.
type GetResult ¶ added in v0.5.0
type GetResult struct {
// Branch is the pull request's branch.
Branch string `json:"branch"`
// CheckedOut is set once Branch is checked out; when it isn't, the
// error says why.
CheckedOut bool `json:"checkedOut"`
Trunk string `json:"trunk"`
// Branches is the stack, bottom to top.
Branches []string `json:"branches"`
Source string `json:"source"`
// Created lists the branches that only existed on the remote before.
Created []string `json:"created,omitempty"`
// Updated lists branches fast forwarded to the remote.
Updated []BranchMove `json:"updated,omitempty"`
// Behind lists branches that have diverged from the remote, with the
// number of commits there that aren't here; they were left alone.
Behind []RemoteAhead `json:"behind,omitempty"`
// NotUpdated lists branches the remote is ahead of that couldn't be
// moved.
NotUpdated []NotUpdated `json:"notUpdated,omitempty"`
// NeedsRestack lists branches not on the tip of the one below them.
NeedsRestack []string `json:"needsRestack,omitempty"`
Notices []string `json:"notices,omitempty"`
}
GetResult reports what Get did.
type InitOptions ¶ added in v0.3.0
type InitOptions struct {
// Branches run bottom to top; the current branch when empty.
Branches []string
// Base is the trunk; when empty the graph's only trunk, else the
// repository's default branch.
Base string
}
InitOptions adopts existing branches into a new stack.
type InitResult ¶ added in v0.3.0
type InitResult struct {
Trunk string `json:"trunk"`
Branches []string `json:"branches"`
// NeedsRestack lists the branches whose parent's tip is not in their
// history; init records them as they are and leaves the rebase to
// git stack restack.
NeedsRestack []string `json:"needsRestack,omitempty"`
}
InitResult reports the stack that was recorded.
type KeptBranch ¶ added in v0.1.4
KeptBranch is a deletion candidate that was kept and why.
type MergeOptions ¶ added in v0.1.5
type MergeOptions struct {
// Branch is the highest branch to merge; every branch below it in the
// stack goes with it. Empty means the current branch.
Branch string
// Method overrides stack.merge.method; empty leaves it to the config,
// and an empty config leaves it to the repository's settings.
Method forge.MergeMethod
// NoSync skips the sync that normally follows a merge.
NoSync bool
// Force merges without first checking that the pull requests' checks
// have all finished and none failed. The forge's own rules (required
// checks among them) still apply.
Force bool
}
MergeOptions controls Merge.
type MergeResult ¶ added in v0.1.5
type MergeResult struct {
Trunk string `json:"trunk"`
// PullRequests that were merged, bottom to top.
PullRequests []MergedPR `json:"pullRequests"`
Status forge.MergeStatus `json:"status"`
// SHA is the merge commit on trunk; empty when enqueued.
SHA string `json:"sha,omitempty"`
// Sync is what the sync afterwards did, when it ran.
Sync *SyncResult `json:"sync,omitempty"`
Notices []string `json:"notices,omitempty"`
}
MergeResult reports what landed.
type MergedPR ¶ added in v0.1.5
type MergedPR struct {
Branch string `json:"branch"`
Number int `json:"number"`
URL string `json:"url,omitempty"`
}
MergedPR is one pull request that landed.
type ModifyOptions ¶
type ModifyOptions struct {
// NewCommit creates a commit instead of amending (-c).
NewCommit bool
Staging StagingMode
Message []string
// Edit opens the editor when amending (-e); ignored with NewCommit.
Edit bool
ResetAuthor bool
NoVerify bool
// Continue / Abort resume or abandon an interrupted restack.
Continue bool
Abort bool
}
ModifyOptions mirrors `gt modify`.
type ModifyResult ¶
type ModifyResult struct {
Branch string `json:"branch"`
Commit CommitInfo `json:"commit"`
// Amended is false when a new commit was created.
Amended bool `json:"amended"`
// ForcedNewCommit is true when the branch had no commits of its own, so
// amending would have rewritten the parent's commit.
ForcedNewCommit bool `json:"forcedNewCommit"`
// Restacked lists the branches above that were rebased.
Restacked []string `json:"restacked"`
}
ModifyResult reports what happened.
type MoveDestination ¶ added in v0.3.0
type MoveDestination struct {
Name string `json:"name"`
Trunk string `json:"trunk"`
IsTrunk bool `json:"isTrunk"`
// Stack is the bottom branch of the stack Name tops (empty for a trunk).
Stack string `json:"stack,omitempty"`
}
MoveDestination is a place a branch can be moved to.
type MoveOptions ¶ added in v0.3.0
type MoveOptions struct {
// Source is the branch to move; the current branch when empty.
Source string
// Onto is the new parent: a trunk or the top of another stack. Empty
// asks Pick.
Onto string
// Only moves Source alone, leaving the branches above it where they
// are (on Source's old parent).
Only bool
// Pick, when set and Onto is empty, chooses the destination from the
// valid ones. It returns "" when the user cancelled.
Pick func(dests []MoveDestination) (string, error)
}
MoveOptions is one move of a branch to a new parent.
type MoveResult ¶ added in v0.3.0
type MoveResult struct {
Branch string `json:"branch"`
// From is the parent the branch was on, Onto the one it is on now.
From string `json:"from"`
Onto string `json:"onto"`
// Moved are the branches that went, bottom to top (Branch first).
Moved []string `json:"moved"`
// LeftBehind are the branches above Branch that stayed, with --only.
LeftBehind []string `json:"leftBehind,omitempty"`
// NewStack is true when Onto is a trunk and the branches started a new stack.
NewStack bool `json:"newStack"`
Cancelled bool `json:"cancelled,omitempty"`
Restacked []string `json:"restacked,omitempty"`
Notices []string `json:"notices,omitempty"`
}
MoveResult reports what happened.
type NotUpdated ¶ added in v0.2.0
type NotUpdated struct {
Name string `json:"name"`
Worktree string `json:"worktree,omitempty"`
Reason string `json:"reason"`
// Detail is git's one line explanation, for refused.
Detail string `json:"detail,omitempty"`
// Changed and Untracked are the files in the way, relative to the
// checkout, for dirty and untracked; at most maxListedFiles each, with
// MoreChanged / MoreUntracked counting the rest.
Changed []string `json:"changed,omitempty"`
MoreChanged int `json:"moreChanged,omitempty"`
Untracked []string `json:"untracked,omitempty"`
MoreUntracked int `json:"moreUntracked,omitempty"`
// Lock is the lock file that was held, for locked, and LockKind says
// whose it is: "index" (the checkout's index) or "ref" (a branch's).
Lock string `json:"lock,omitempty"`
LockKind string `json:"lockKind,omitempty"`
}
NotUpdated is a branch sync meant to move (a trunk or a branch the remote advanced) that is still where it was.
func (NotUpdated) Failed ¶ added in v0.2.0
func (n NotUpdated) Failed() bool
Failed reports whether the branch not moving makes the sync fail (as opposed to a notice about the user's own uncommitted changes).
type PRSnapshot ¶
type PRSnapshot struct {
PRs []forge.PullRequest `json:"prs"`
}
PRSnapshot is the cached forge state.
type Phase ¶
type Phase string
Phase names a kind of long running work. The CLI decorates each phase the same way every time (see docs/style.md); use cases only pick the phase.
const ( PhaseCreate Phase = "create" PhaseModify Phase = "modify" PhaseRestack Phase = "restack" PhaseSubmit Phase = "submit" PhaseSync Phase = "sync" PhaseAI Phase = "ai" PhaseUpdate Phase = "update" PhaseInstall Phase = "install" PhaseMerge Phase = "merge" // PhaseAbsorb: rewriting the stack's commits with the staged changes. PhaseAbsorb Phase = "absorb" // PhaseRename: renaming a branch on the forge. PhaseRename Phase = "rename" // PhaseRefresh: fetching pull request state from the forge for a command // that only reads it (log, submit's look at which PRs exist). PhaseRefresh Phase = "refresh" // PhaseDoctor: checking (and fixing) git-stack's setup. PhaseDoctor Phase = "doctor" )
Phases.
type PopResult ¶ added in v0.4.0
type PopResult struct {
Branch string `json:"branch"`
Parent string `json:"parent"`
// StackGone is true when the popped branch was the only one.
StackGone bool `json:"stackGone,omitempty"`
Restacked []string `json:"restacked,omitempty"`
// Closing is the popped branch's pull request, queued to close at the
// next submit.
Closing int `json:"closing,omitempty"`
Notices []string `json:"notices,omitempty"`
}
PopResult reports what a pop did.
type Prompter ¶
type Prompter interface {
Confirm(question string, defaultYes bool) (bool, error)
Select(question string, options []string) (int, error)
}
Prompter asks the user a question. It is nil under --no-interactive and in the MCP server, in which case use cases must fall back to a default or return KindInteractionRequired.
type RemoteAhead ¶ added in v0.1.4
RemoteAhead is a branch with commits on the remote we don't have.
type RenameOptions ¶ added in v0.4.0
type RenameOptions struct {
// Name is the branch's new name, used as given (no prefix).
Name string
// Local renames the branch in this repository only, leaving the remote
// branch and its pull request under the old name.
Local bool
}
RenameOptions is one rename of the current branch.
type RenameResult ¶ added in v0.4.0
type RenameResult struct {
From string `json:"from"`
To string `json:"to"`
// Remote is the remote the branch was renamed on as well, "" when only
// the local branch was renamed.
Remote string `json:"remote,omitempty"`
Notices []string `json:"notices,omitempty"`
}
RenameResult reports what happened.
type ReorderOptions ¶ added in v0.3.0
type ReorderOptions struct {
// Order is the new order, bottom to top; every branch of the stack
// exactly once. Empty asks Pick.
Order []string
// Pick, when set and Order is empty, chooses the order (the CLI's
// list). It returns nil when the user cancelled.
Pick func(trunk string, branches []string, current string) ([]string, error)
}
ReorderOptions is one reorder of the current stack.
type ReorderResult ¶ added in v0.3.0
type ReorderResult struct {
// Stack is the stack's bottom branch before the reorder.
Stack string `json:"stack"`
Before []string `json:"before"`
After []string `json:"after"`
// Changed is false when the order was already the one asked for.
Changed bool `json:"changed"`
// Cancelled is true when Pick returned nothing.
Cancelled bool `json:"cancelled,omitempty"`
// Restacked lists the branches that were rebased, bottom to top.
Restacked []string `json:"restacked,omitempty"`
Notices []string `json:"notices,omitempty"`
}
ReorderResult reports what happened.
type RestackOptions ¶
type RestackOptions struct {
Scope stack.Scope
// Branch is where the scope is worked out from; the current branch when
// empty. Nothing is checked out.
Branch string
// Continue resumes an interrupted restack after the conflicts were
// staged; Abort gives it up and puts every moved branch back.
Continue bool
Abort bool
// StageAll runs git add -A before continuing.
StageAll bool
}
RestackOptions mirrors `gt restack`.
type RestackResult ¶
type RestackResult struct {
Scope stack.Scope `json:"scope"`
// Branches is the scope, bottom to top.
Branches []string `json:"branches"`
// Moved are the branches that were rebased, bottom to top.
Moved []BranchMove `json:"moved,omitempty"`
// InPlace were already on their parent.
InPlace []string `json:"in_place,omitempty"`
// Restored are the branches an abort put back.
Restored []string `json:"restored,omitempty"`
// OrderRestored is true when an abort also put a reorder or move's
// stack shape back.
OrderRestored bool `json:"order_restored,omitempty"`
// Popped is the branch a continue finished popping, and PoppedOnto
// the parent its changes are now staged on.
Popped string `json:"popped,omitempty"`
PoppedOnto string `json:"popped_onto,omitempty"`
Notices []string `json:"notices,omitempty"`
}
RestackResult reports what a restack did.
type Row ¶
type Row struct {
Name string
// Depth is 0 for a trunk, 1 for a bottom branch, and so on.
Depth int
// Parent is the branch below (empty for trunks and untracked branches).
Parent string
IsTrunk bool
IsCurrent bool
// Tracked is false for branches that are in no stack.
Tracked bool
// NeedsRestack is true when the parent's tip is not in the branch's
// history.
NeedsRestack bool
// NeedsPush is true when the branch is on the remote but the local
// branch has moved on from it (new commits, a restack, an amend), so
// its PR is behind until the next submit.
NeedsPush bool
Head string
LastCommit time.Time
// Worktree is the path of another worktree the branch is checked out in.
Worktree string
// PR is the known pull request, if any. State is StateUnknown until the
// forge has been consulted.
PR *forge.PullRequest
// StackIndex identifies the stack within View.Graph (-1 for trunks and
// untracked branches).
StackIndex int
// Commits are the branch's own commits, newest first: those on it but
// not on its parent (trunk for the bottom branch), nor on the parent
// tip it was last restacked onto. At most MaxCommits, and only filled
// when ViewOptions.Commits asks for them.
Commits []Commit
// MoreCommits counts the branch's commits beyond Commits.
MoreCommits int
}
Row is one line of the stack tree, in display order.
type StagingMode ¶
type StagingMode int
StagingMode mirrors Graphite's -a / -u / -p flags.
const ( StageNone StagingMode = iota StageAll StageUpdate StagePatch )
type SubmitOptions ¶
type SubmitOptions struct {
// Draft / Publish force the state of new PRs. With neither, the
// configured default applies: ready for review unless stack.submit.default
// says draft, or ask (which prompts on a terminal and publishes otherwise).
Draft bool
Publish bool
// NoEdit skips the backend's interactive PR editor.
NoEdit bool
// DryRun reports what would happen without pushing.
DryRun bool
// UseAI drafts title and body for every new PR.
UseAI bool
// Texts supplies title/body per branch (the MCP path). Branches without
// a PR need an entry unless UseAI is set or the editor can open.
Texts map[string]PRText
// Force pushes even when a branch has commits on the remote that aren't
// in the local branch, overwriting them.
Force bool
// Down submits only the current branch and the ones below it, leaving
// the ones above alone.
Down bool
// Branch submits that branch and the ones below it instead of the
// current branch; it implies Down.
Branch string
}
SubmitOptions mirrors `gt submit`.
type SubmitResult ¶
type SubmitResult struct {
Stack []string `json:"stack"`
PullRequests []SubmittedPR `json:"pullRequests"`
Draft bool `json:"draft"`
DryRun bool `json:"dryRun"`
// Output is the backend's own output (captured runs only).
Output string `json:"output,omitempty"`
// Closed are the pull requests a pop or fold left behind that this
// submit closed.
Closed []ClosedPR `json:"closed,omitempty"`
// Merged names the branches of the stack whose pull requests had merged
// before this submit. Pushing over them would put their commits into
// the next PR up, so submit synced first (Sync says what that did): they
// went and the branches above were restacked onto trunk. A dry run only
// names them and leaves them out of the plan.
Merged []string `json:"merged,omitempty"`
// Sync is what the sync before the submit did, when one ran. It is set
// even when that sync failed, so what it did manage is still known.
Sync *SyncResult `json:"sync,omitempty"`
Notices []string `json:"notices,omitempty"`
}
SubmitResult reports the outcome.
type SubmittedPR ¶
type SubmittedPR struct {
Branch string `json:"branch"`
Number int `json:"number,omitempty"`
URL string `json:"url,omitempty"`
State forge.State `json:"state,omitempty"`
Created bool `json:"created"`
// WouldCreate is set in dry runs for branches without a PR.
WouldCreate bool `json:"wouldCreate,omitempty"`
// TextUpdated is true when a supplied or drafted title/body was applied.
TextUpdated bool `json:"textUpdated,omitempty"`
// BaseFixed is true when the PR's base was moved back onto its parent
// branch after gh stack had pointed it elsewhere (see fixBases).
BaseFixed bool `json:"baseFixed,omitempty"`
}
SubmittedPR is one line of the result.
type SyncOptions ¶
type SyncOptions struct {
// Force approves resetting a diverged trunk to the remote and deleting
// merged or closed branches without asking.
Force bool
// DeleteAll approves deleting merged or closed branches without asking.
DeleteAll bool
// NoRestack skips the restack phase.
NoRestack bool
}
SyncOptions mirrors gt sync's flags.
type SyncResult ¶
type SyncResult struct {
Remote string `json:"remote"`
Trunks []TrunkSync `json:"trunks"`
Deleted []DeletedBranch `json:"deleted,omitempty"`
Kept []KeptBranch `json:"kept,omitempty"`
Updated []BranchMove `json:"updated,omitempty"`
Restacked []BranchMove `json:"restacked,omitempty"`
Conflicts []Conflict `json:"conflicts,omitempty"`
Behind []RemoteAhead `json:"behind,omitempty"`
// NotUpdated lists branches sync meant to move but couldn't.
NotUpdated []NotUpdated `json:"notUpdated,omitempty"`
Notices []string `json:"notices,omitempty"`
}
SyncResult reports everything sync did.
type TrunkSync ¶ added in v0.1.4
type TrunkSync struct {
Name string `json:"name"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
Status string `json:"status"`
}
TrunkSync is what happened to one trunk.
type UndoEntryView ¶ added in v0.4.0
type UndoEntryView struct {
Command string `json:"command"`
At time.Time `json:"at"`
// Restores lists what undoing it puts back, one short line each.
Restores []string `json:"restores"`
}
UndoEntryView is one command undo can take back.
type UndoOptions ¶ added in v0.4.0
type UndoOptions struct {
// List shows this worktree's history without changing anything.
List bool
// Force undoes even when branches moved since the command, throwing
// away what happened on them. Working tree changes are never thrown
// away.
Force bool
}
UndoOptions controls Undo.
type UndoResult ¶ added in v0.4.0
type UndoResult struct {
Undone *UndoEntryView `json:"undone,omitempty"`
// Entries is the history, newest first (List only).
Entries []UndoEntryView `json:"entries,omitempty"`
// Staged is true when the undone command's changes are back as staged
// changes (create, modify, absorb).
Staged bool `json:"staged,omitempty"`
Notices []string `json:"notices,omitempty"`
}
UndoResult reports what Undo did, or with List what it could do.
type UntrackOptions ¶ added in v0.4.0
type UntrackOptions struct {
// Branch is the branch to untrack; the current branch when empty.
Branch string
// Only untracks Branch alone: the branches above it stay in the stack,
// now on Branch's parent, and are restacked there.
Only bool
}
UntrackOptions stops tracking a branch.
type UntrackResult ¶ added in v0.4.0
type UntrackResult struct {
Branch string `json:"branch"`
// Untracked are the branches no longer in a stack, bottom to top
// (Branch first).
Untracked []string `json:"untracked"`
// Parent is where the branches above Branch sit now, with Only and
// branches above it.
Parent string `json:"parent,omitempty"`
Restacked []string `json:"restacked,omitempty"`
// NextSteps say how to track the branches again.
NextSteps []string `json:"nextSteps,omitempty"`
Notices []string `json:"notices,omitempty"`
}
UntrackResult reports what happened.
type View ¶
type View struct {
Repo git.Repo
Current string
Graph *stack.Graph
// Rows lists trunks and their stacks in display order, then untracked
// branches when requested.
Rows []Row
}
View is the rendered state of the repository's stacks.
func (*View) ApplyPRs ¶
func (v *View) ApplyPRs(prs []forge.PullRequest)
ApplyPRs decorates rows with forge state. Rows whose branch has no PR in prs keep the backend snapshot, if any.
type ViewOptions ¶
type ViewOptions struct {
// CurrentStackOnly limits rows to the stack of the current branch (and
// its trunk).
CurrentStackOnly bool
// IncludeUntracked adds local branches that are in no stack.
IncludeUntracked bool
// SkipRestackCheck avoids the per-branch ancestry check (completion).
SkipRestackCheck bool
// PRs selects how pull-request state is obtained (default: none).
PRs PRMode
// Commits fills each stacked branch's Row.Commits (one local git read
// per branch, run concurrently).
Commits bool
}
ViewOptions controls View.
Source Files
¶
- absorb.go
- app.go
- branchname.go
- create.go
- doctor.go
- fold.go
- get.go
- init.go
- merge.go
- modify.go
- move.go
- navigate.go
- pop.go
- pr.go
- prs.go
- prtemplate.go
- remote.go
- remote_stacks.go
- rename.go
- reorder.go
- reshape.go
- restack.go
- restack_plan.go
- restack_state.go
- staging.go
- submit.go
- sync.go
- sync_cleanup.go
- sync_remote.go
- sync_restack.go
- sync_trunk.go
- sync_worktrees.go
- undo.go
- undo_lock_unix.go
- undo_log.go
- undo_record.go
- untrack.go
- view.go