{"modulePath":"github.com/DomBlack/git-stack","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package ghstack\n\nPackage ghstack implements the stack ports on top of GitHub's gh-stack extension. Stack metadata is read directly from the extension's catalog, \\\u003ccommon-dir\u003e/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.\n\n## Constants\n\n```go\nconst BackupSuffix = \".pre-worktree-migration\"\n```\nBackupSuffix names the copy of a per-worktree file kept when it is moved into the shared catalog, the same name gh stack uses.\n\n```go\nconst FileName = \"gh-stack\"\n```\nFileName is the gh-stack metadata file inside the git directory.\n\n```go\nconst LockName = \"gh-stack.lock\"\n```\nLockName is the file gh stack flocks while it edits its catalog.\n\n```go\nconst MinVersion = \"v0.3.0\"\n```\nMinVersion 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.\n\n```go\nconst OperationLockName = \"gh-stack-operation.lock\"\n```\nOperationLockName 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.\n\n```go\nconst SchemaVersion = 1\n```\nSchemaVersion is the only version this adapter understands.\n\n## Functions\n\n```go\nfunc LegacyFiles(repo git.Repo) []string\n```\nLegacyFiles 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.\n\n```go\nfunc MigrationPending(repo git.Repo) bool\n```\nMigrationPending reports whether gh stack itself is part way through moving per-worktree files into the shared catalog.\n\n```go\nfunc TooOld(v string) bool\n```\nTooOld reports whether an installed gh-stack version is older than MinVersion. Anything that isn't a release (a local build) is let through.\n\n## Types\n\n```go\ntype Backend struct {\n\t// contains filtered or unexported fields\n}\n```\nBackend implements the stack ports via gh-stack.\n\n```go\nfunc New(r exec.Runner, g *git.Client, opts ...Option) *Backend\n```\nNew returns a Backend that runs gh through r.\n\n```go\nfunc (b *Backend) AddTop(ctx context.Context, repo git.Repo, name string) error\n```\nAddTop runs \\`gh stack add \\\u003cname\u003e\\` without committing (we commit natively).\n\n```go\nfunc (b *Backend) Checks(repo *git.Repo) []doctor.Check\n```\nChecks 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.\n\n```go\nfunc (b *Backend) Extension(ctx context.Context) (string, error)\n```\nExtension 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.\n\n```go\nfunc (b *Backend) ImportStack(ctx context.Context, repo git.Repo, target string) error\n```\nImportStack runs \\`gh stack checkout \\\u003ctarget\u003e\\`. 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.\n\n```go\nfunc (b *Backend) InitStack(ctx context.Context, repo git.Repo, trunk string, branches []string) error\n```\nInitStack runs \\`gh stack init --base \\\u003ctrunk\u003e \\\u003cbranches...\u003e\\`.\n\n```go\nfunc (b *Backend) Link(ctx context.Context, repo git.Repo, o stack.LinkOptions) (stack.SubmitResult, error)\n```\nLink runs \\`gh stack link\\` with pull request numbers. Numbers resolve to pull requests rather than branches, so gh stack pushes nothing.\n\n```go\nfunc (b *Backend) Load(_ context.Context, repo git.Repo) (*stack.Graph, error)\n```\nLoad implements stack.Metadata. It reads gh stack's shared catalog (\\\u003ccommon-dir\u003e/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.\n\n```go\nfunc (b *Backend) Migrate(ctx context.Context, repo git.Repo) ([]string, error)\n```\nMigrate merges any per-worktree file left from gh stack 0.2 into the shared catalog and moves each aside to \\\u003cfile\u003e.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.\n\n```go\nfunc (b *Backend) Preflight(ctx context.Context) error\n```\nPreflight 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.\n\n```go\nfunc (b *Backend) Restore(ctx context.Context, repo git.Repo, s stack.Snapshot) error\n```\nRestore 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.\n\n```go\nfunc (b *Backend) Snapshot(ctx context.Context, repo git.Repo) (stack.Snapshot, error)\n```\nSnapshot 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.\n\n```go\nfunc (b *Backend) Submit(ctx context.Context, repo git.Repo, o stack.SubmitOptions) (stack.SubmitResult, error)\n```\nSubmit 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.\n\n```go\nfunc (b *Backend) Unstack(ctx context.Context, repo git.Repo, number int) error\n```\nUnstack runs \\`gh stack unstack \\\u003cnumber\u003e\\`. With the number untracked locally gh stack only talks to GitHub.\n\n```go\nfunc (b *Backend) Update(ctx context.Context, repo git.Repo, fn func(*stack.Graph) error) error\n```\nUpdate 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.\n\nAny 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.\n\n```go\ntype Option func(*Backend)\n```\nOption configures a Backend.\n\n```go\nfunc WithOutput(w io.Writer) Option\n```\nWithOutput 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.\n\n","path":"github.com/DomBlack/git-stack/pkg/backend/ghstack","name":"ghstack","synopsis":"Package ghstack implements the stack ports on top of GitHub's gh-stack extension.","isRedistributable":true}
