ghstack

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const FileName = "gh-stack"

FileName is the gh-stack metadata file inside the git directory.

View Source
const LockName = "gh-stack.lock"

LockName is the file gh stack flocks while it edits its catalog.

View Source
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.

View Source
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.

View Source
const SchemaVersion = 1

SchemaVersion is the only version this adapter understands.

Variables

This section is empty.

Functions

func LegacyFiles added in v0.5.0

func LegacyFiles(repo git.Repo) []string

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

func MigrationPending(repo git.Repo) bool

MigrationPending reports whether gh stack itself is part way through moving per-worktree files into the shared catalog.

func TooOld added in v0.5.0

func TooOld(v string) bool

TooOld reports whether an installed gh-stack version is older than MinVersion. Anything that isn't a release (a local build) is let through.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend implements the stack ports via gh-stack.

func New

func New(r exec.Runner, g *git.Client, opts ...Option) *Backend

New returns a Backend that runs gh through r.

func (*Backend) AddTop

func (b *Backend) AddTop(ctx context.Context, repo git.Repo, name string) error

AddTop runs `gh stack add <name>` without committing (we commit natively).

func (*Backend) Checks added in v0.5.0

func (b *Backend) Checks(repo *git.Repo) []doctor.Check

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

func (b *Backend) Extension(ctx context.Context) (string, error)

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

func (b *Backend) ImportStack(ctx context.Context, repo git.Repo, target string) error

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...>`.

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

func (b *Backend) Load(_ context.Context, repo git.Repo) (*stack.Graph, error)

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

func (b *Backend) Migrate(ctx context.Context, repo git.Repo) ([]string, error)

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

func (b *Backend) Preflight(ctx context.Context) error

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

func (b *Backend) Restore(ctx context.Context, repo git.Repo, s stack.Snapshot) error

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

func (b *Backend) Snapshot(ctx context.Context, repo git.Repo) (stack.Snapshot, error)

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

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

func (b *Backend) Unstack(ctx context.Context, repo git.Repo, number int) error

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

func (b *Backend) Update(ctx context.Context, repo git.Repo, fn func(*stack.Graph) error) error

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

func WithOutput(w io.Writer) Option

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL