Documentation
¶
Overview ¶
Package ghstack implements the stack ports on top of GitHub's gh-stack extension. Stack metadata is read directly from the extension's <git-dir>/gh-stack file (documented, schema version 1). The file is written only by Update, under gh stack's lock; every other mutation still goes through `gh stack` commands.
Index ¶
- Constants
- type Backend
- func (b *Backend) AddTop(ctx context.Context, repo git.Repo, name string) error
- func (b *Backend) InitStack(ctx context.Context, repo git.Repo, trunk string, branches []string) error
- func (b *Backend) Link(ctx context.Context, repo git.Repo, o stack.LinkOptions) (stack.SubmitResult, error)
- func (b *Backend) Load(_ context.Context, repo git.Repo) (*stack.Graph, error)
- func (b *Backend) Preflight(ctx context.Context) error
- func (b *Backend) Restore(ctx context.Context, repo git.Repo, s stack.Snapshot) error
- func (b *Backend) Snapshot(ctx context.Context, repo git.Repo) (stack.Snapshot, error)
- func (b *Backend) Submit(ctx context.Context, repo git.Repo, o stack.SubmitOptions) (stack.SubmitResult, error)
- func (b *Backend) Unstack(ctx context.Context, repo git.Repo, number int) error
- func (b *Backend) Update(ctx context.Context, repo git.Repo, fn func(*stack.Graph) error) error
- type Option
Constants ¶
const FileName = "gh-stack"
FileName is the gh-stack metadata file inside the git directory.
const LockName = "gh-stack.lock"
LockName is the file gh stack flocks while it edits its metadata.
const SchemaVersion = 1
SchemaVersion is the only version this adapter understands.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend implements the stack ports via gh-stack.
func (*Backend) AddTop ¶
AddTop runs `gh stack add <name>` without committing (we commit natively), once the current branch's stack is in this worktree's file where gh stack will look for it.
func (*Backend) InitStack ¶
func (b *Backend) InitStack(ctx context.Context, repo git.Repo, trunk string, branches []string) error
InitStack runs `gh stack init --base <trunk> <branches...>`.
func (*Backend) Link ¶ added in v0.3.0
func (b *Backend) Link(ctx context.Context, repo git.Repo, o stack.LinkOptions) (stack.SubmitResult, error)
Link runs `gh stack link` with pull request numbers. Numbers resolve to pull requests rather than branches, so gh stack pushes nothing.
func (*Backend) Load ¶
Load implements stack.Metadata. gh stack keeps its file per worktree (<git-dir>/gh-stack), so this reads the current worktree's file first, then the main checkout's and every linked worktree's, and merges them so one view covers everything checked out on the machine. A missing file means no stacks; it never runs gh. A branch that appears in two files keeps its first stack.
func (*Backend) Preflight ¶
Preflight verifies gh and the gh-stack extension are installed. The result is cached per Backend for the life of the process.
func (*Backend) Restore ¶ added in v0.4.0
Restore implements stack.Metadata. It writes each file in the snapshot back exactly, under the lock, and removes the ones that were empty (did not exist) when it was taken. A file whose git dir has gone since (a removed worktree) is skipped, and files the snapshot doesn't know about are left alone.
func (*Backend) Snapshot ¶ added in v0.4.0
Snapshot implements stack.Metadata. It reads every metadata file Load would (the current worktree's, the main checkout's and every linked worktree's) under the lock, recording the ones that don't exist as empty so Restore can remove them again.
func (*Backend) Submit ¶
func (b *Backend) Submit(ctx context.Context, repo git.Repo, o stack.SubmitOptions) (stack.SubmitResult, error)
Submit runs `gh stack submit`. Non-interactive runs use --auto and are captured; interactive runs hand gh-stack the real terminal so its own PR editor can open. The current branch's stack is moved into this worktree's file first, as that is the only one gh stack reads here.
func (*Backend) Unstack ¶ added in v0.3.0
Unstack runs `gh stack unstack <number>`. With the number untracked locally gh stack only talks to GitHub.
func (*Backend) Update ¶ added in v0.1.4
Update implements stack.Metadata. It takes gh stack's lock in every git dir that has a metadata file, re-reads them, runs fn on the merged graph and writes each file back, editing the JSON in place so members we don't model, PR records and ordering survive. A file whose stacks fn didn't change is not rewritten. fn may also append stacks (each with a trunk and at least one branch; they are written to the current worktree's file, created if need be, since that is the only one gh stack reads there) and may set or clear a stack's ID and Number (clearing removes them from the record). It must not remove or reorder existing stacks; a stack left with no branches is removed.
type Option ¶
type Option func(*Backend)
Option configures a Backend.
func WithOutput ¶
WithOutput relays the output of long running gh stack commands (submit, sync) to w as it is produced instead of only returning it afterwards. The CLI sets this to stderr; the MCP server never does.