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 catalog, <common-dir>/gh-stack (schema version 1), shared by every worktree since gh-stack 0.3. The file is written only by Update, under gh stack's lock; every other mutation still goes through `gh stack` commands.
Index ¶
- Constants
- func LegacyFiles(repo git.Repo) []string
- func MigrationPending(repo git.Repo) bool
- func TooOld(v string) bool
- type Backend
- func (b *Backend) AddTop(ctx context.Context, repo git.Repo, name string) error
- func (b *Backend) Checks(repo *git.Repo) []doctor.Check
- func (b *Backend) Extension(ctx context.Context) (string, error)
- func (b *Backend) ImportStack(ctx context.Context, repo git.Repo, target 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) Migrate(ctx context.Context, repo git.Repo) ([]string, 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 BackupSuffix = ".pre-worktree-migration"
BackupSuffix names the copy of a per-worktree file kept when it is moved into the shared catalog, the same name gh stack uses.
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 catalog.
const MinVersion = "v0.3.0"
MinVersion is the oldest gh-stack this adapter works with: 0.3.0 keeps one catalog for every worktree in the common git dir, which is the only layout we read and write.
const OperationLockName = "gh-stack-operation.lock"
OperationLockName is the file gh stack flocks for the whole of a command that changes stacks. We take it only while moving per-worktree files into the shared catalog, which gh stack does under it too.
const SchemaVersion = 1
SchemaVersion is the only version this adapter understands.
Variables ¶
This section is empty.
Functions ¶
func LegacyFiles ¶ added in v0.5.0
LegacyFiles lists the per-worktree files gh stack 0.2 and older kept in each linked worktree's git dir (and git-stack wrote there too), the current worktree's first. gh stack 0.3 moved to one shared catalog; these are merged into it by the next Update.
func MigrationPending ¶ added in v0.5.0
MigrationPending reports whether gh stack itself is part way through moving per-worktree files into the shared catalog.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend implements the stack ports via gh-stack.
func (*Backend) Checks ¶ added in v0.5.0
Checks implements doctor.Provider: gh, its login, the gh-stack extension and its version, and in a repository gh stack's stack file. repo is nil outside a repository.
func (*Backend) Extension ¶ added in v0.5.0
Extension reports the installed gh-stack's version as `gh extension list` shows it ("v0.3.0", or a commit for a local build; "" when it shows none). It is a KindNotInstalled error when gh or the extension is missing.
func (*Backend) ImportStack ¶ added in v0.5.0
ImportStack runs `gh stack checkout <target>`. It only ever gets a target git-stack doesn't already track, so gh stack's own local lookups miss and it asks GitHub for the stack.
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. It reads gh stack's shared catalog (<common-dir>/gh-stack) and merges in any per-worktree file left from gh stack 0.2 (see readCatalog), so stacks show up the same before and after they are moved. A missing file means no stacks. It never writes and never runs gh.
func (*Backend) Migrate ¶ added in v0.5.0
Migrate merges any per-worktree file left from gh stack 0.2 into the shared catalog and moves each aside to <file>.pre-worktree-migration (numbered when gh stack already left a backup by that name, so a stale one never blocks it), and reports the files it moved. gh stack 0.3 does the same on its next command but refuses when a backup it made earlier differs from the file, which git-stack's own writes to these files used to cause. It is a no-op when there is nothing to move.
func (*Backend) Preflight ¶
Preflight verifies gh and the gh-stack extension are installed and that gh-stack is new enough. 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 snapshot taken by an older git-stack may name per-worktree files too; they are put back as they were and moved into the shared catalog again by the next command. A file whose git dir has gone since (a removed worktree) is skipped.
func (*Backend) Snapshot ¶ added in v0.4.0
Snapshot implements stack.Metadata. It moves any per-worktree file into the shared catalog first (see Migrate), so a snapshot is always the one file, then reads it under the lock, recording a missing file as empty so Restore can remove it 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.
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, re-reads the catalog, runs fn on the graph and writes the catalog back, editing the JSON in place so members we don't model, PR records and ordering survive. Nothing is written when nothing changed. fn may also append stacks (each with a trunk and at least one branch) 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.
Any per-worktree file left from gh stack 0.2 is merged into the catalog and then moved aside (see Migrate), under gh stack's operation lock too.
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.