Skip to content

Remote unstack by stack number#180

Merged
skarim merged 3 commits into
skarim/checkout-improvementsfrom
skarim/unstack-remote-only
Jul 15, 2026
Merged

Remote unstack by stack number#180
skarim merged 3 commits into
skarim/checkout-improvementsfrom
skarim/unstack-remote-only

Conversation

@skarim

@skarim skarim commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

gh stack unstack previously required the target stack to be tracked locally — running it on a stack number that wasn't checked out locally failed with stack #N is not tracked locally and never reached the API. This PR makes unstack <number> a remote-first operation (like gh stack link): the stack is unstacked directly through the GitHub API by its number, from anywhere in the repository, whether or not it's tracked locally. When the stack is also tracked locally, its local tracking is removed as well.

Behavior

  • No argument (unchanged) — targets the active stack (the one containing the current branch), unstacking it on GitHub and removing local tracking; fails if you're not on a stack.
  • <stack-number> tracked locally (unchanged) — unstacks on GitHub and removes local tracking.
  • <stack-number> not tracked locally (new) — unstacks on GitHub by number, no local checkout required. A number that doesn't exist on GitHub reports stack #N not found on GitHub (exit 2).
  • --local (unchanged) — only removes local tracking and never contacts GitHub; combining it with a number that isn't tracked locally is an error.

Changes

  • cmd/utils.go — replace loadStackByNumber with a quiet lookupStackByNumber that reports "not tracked locally" without erroring, so the caller can fall back to the API (legacy-id backfill preserved).
  • cmd/unstack.go — split runUnstack into a locally-tracked path and a remote-only path (runRemoteUnstack), sharing one Unstack API call and error mapping. A 404 is an idempotent success when there's local tracking to clean up, but a hard error in remote-only mode.
  • DocsREADME.md (which never documented the <stack-number> argument), docs/src/content/docs/reference/cli.md, faq.md, and skills/gh-stack/SKILL.md.

Testing

  • Reworked cmd/unstack_test.go: replaced the old "not tracked → fail" test with remote-only cases for dissolved, 404, partial (200), 422, and --local on an untracked number; the local-path tests are unchanged.
  • go test -race -count=1 ./... and go vet ./... are clean, and the changed files pass gofmt.

Stack created with GitHub Stacks CLIGive Feedback 💬

Copilot AI review requested due to automatic review settings July 14, 2026 23:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds remote-first unstacking by stack number while reconciling local tracking when available.

Changes:

  • Adds remote-only unstack handling and API error mapping.
  • Refactors local stack-number lookup and legacy backfilling.
  • Updates tests and user/agent documentation.
Show a summary per file
File Description
cmd/unstack.go Implements tracked and remote-only paths.
cmd/utils.go Adds quiet local stack lookup.
cmd/unstack_test.go Covers remote-only outcomes.
README.md Documents numbered unstacking.
docs/src/content/docs/reference/cli.md Updates CLI reference.
docs/src/content/docs/faq.md Updates unstack guidance.
skills/gh-stack/SKILL.md Updates agent instructions.

Review details

  • Files reviewed: 7/7 changed files
  • Comments generated: 5
  • Review effort level: Medium

Comment thread cmd/utils.go Outdated
Comment thread docs/src/content/docs/reference/cli.md Outdated
Comment thread docs/src/content/docs/faq.md
Comment thread cmd/unstack.go Outdated
Comment thread docs/src/content/docs/reference/cli.md

@talum talum left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 LGTM

@skarim skarim merged commit e0b2104 into main Jul 15, 2026
7 checks passed
@skarim skarim deleted the skarim/unstack-remote-only branch July 15, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants