Skip to content

Commit ac6079a

Browse files
committed
Update docs and agent instructions for the new API
- cli.md: document checkout/unstack by stack number and drop the "PATs are not supported" note (any gh-authenticated user can now run stack operations). - quick-start.md: drop the PAT-not-supported note. - AGENTS.md / copilot-instructions.md: ClientOps is now 13 methods over the public Stacks REST API; remove the TokenForHostFn test hook; note the stack file's id/number identity. - SKILL.md: add checkout/unstack-by-stack-number quick references. Copilot-Session: 03673c26-a245-42da-93ed-dfcebc92a740
1 parent 531a959 commit ac6079a

5 files changed

Lines changed: 27 additions & 20 deletions

File tree

‎.github/copilot-instructions.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ No Makefile, no code generation, no external linter config. Standard Go toolchai
1717

1818
- `cmd/`: One Cobra command per file. Each exports `<Name>Cmd(cfg *config.Config)` with logic in `run<Name>()`.
1919
- `internal/git/`: `Ops` interface (52 methods) wrapping git CLI. `MockOps` for tests. Package-level functions delegate to swappable `ops` variable.
20-
- `internal/github/`: `ClientOps` interface (11 methods) for GitHub API. `MockClient` for tests.
20+
- `internal/github/`: `ClientOps` interface (13 methods) for GitHub API. `MockClient` for tests. Stack operations use the public Stacks REST API (`/repos/{owner}/{repo}/stacks`).
2121
- `internal/config/`: `Config` struct passed to all commands. Holds I/O, colors, and test hooks (`SelectFn`, `ConfirmFn`, `InputFn`, `GitHubClientOverride`).
2222
- `internal/stack/`: Stack file (`.git/gh-stack`, JSON) management with file locking.
2323
- `internal/tui/`: bubbletea views (`stackview`, `modifyview`).

‎AGENTS.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal/
3535
gitops.go # Ops interface (52 methods)
3636
mock_ops.go # MockOps. Each method has a corresponding *Fn field.
3737
github/ # github.ClientOps interface + real Client
38-
client_interface.go # ClientOps interface (11 methods)
38+
client_interface.go # ClientOps interface (13 methods)
3939
mock_client.go # MockClient. Uses function-pointer fields for testing.
4040
stack/ # stack file (.git/gh-stack) management, JSON schema, locking
4141
schema.json # JSON Schema for the stack file format
@@ -109,13 +109,14 @@ if errors.As(err, &exitErr) { ... }
109109
### Key interfaces
110110

111111
- **`git.Ops`** (`internal/git/gitops.go`): 52 methods wrapping git CLI calls. The production implementation uses `cli/go-gh`'s `client.Command()` via `run()` and `runSilent()` helpers. Package-level functions (e.g., `git.CurrentBranch()`) delegate to a swappable package-level `ops` variable.
112-
- **`github.ClientOps`** (`internal/github/client_interface.go`): 11 methods for GitHub API (PRs, stacks). Injected via `cfg.GitHubClientOverride` in tests.
113-
- **`config.Config`** (`internal/config/config.go`): Central configuration passed to all commands. Holds I/O streams, color functions, and test hook fields (`SelectFn`, `ConfirmFn`, `InputFn`, `TokenForHostFn`, `RepoOverride`).
112+
- **`github.ClientOps`** (`internal/github/client_interface.go`): 13 methods for GitHub API (PRs, stacks). Stack operations use the public Stacks REST API (`/repos/{owner}/{repo}/stacks`): `ListStacks`, `FindStackForPR`, `GetStack`, `CreateStack`, `AddToStack` (delta append), `Unstack`. Injected via `cfg.GitHubClientOverride` in tests.
113+
- **`config.Config`** (`internal/config/config.go`): Central configuration passed to all commands. Holds I/O streams, color functions, and test hook fields (`SelectFn`, `ConfirmFn`, `InputFn`, `RepoOverride`).
114114

115115
### Stack file
116116

117117
- **Location:** `.git/gh-stack` (JSON format, schema version 1).
118118
- **Schema:** `internal/stack/schema.json`.
119+
- **Identity:** each stack stores GitHub's global `id` (string) and repo-scoped `number` (int, shown in the GitHub UI and used as the primary way to reference a stack, e.g. `gh stack checkout <number>`). `number` may be `0` for stack files created before it was tracked; it is backfilled from the API on the next stack operation.
119120
- **Locking:** Exclusive file lock at `.git/gh-stack.lock` with 5-second timeout. Errors surface as `LockError`.
120121
- **Staleness:** Concurrent modifications detected via `StaleError`.
121122

‎docs/src/content/docs/getting-started/quick-start.md‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ Stacked PRs is currently in private preview. This feature will **not work** unle
1919
gh extension install github/gh-stack
2020
```
2121

22-
:::note[Authentication]
23-
The `gh stack` CLI requires OAuth authentication via `gh auth login`. Personal access tokens (PATs) are not supported.
24-
:::
25-
2622
## Set Up AI Agent Integration
2723

2824
If you use AI coding agents (like GitHub Copilot), install the gh-stack skill so they know how to work with Stacked PRs:

‎docs/src/content/docs/reference/cli.md‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ gh extension install github/gh-stack
1212
Requires the [GitHub CLI](https://cli.github.com/) (`gh`) v2.0+.
1313

1414
:::note[Authentication]
15-
The `gh stack` CLI requires OAuth authentication via `gh auth login`. Personal access tokens (PATs) are not supported.
15+
The `gh stack` CLI uses your GitHub CLI authentication — run `gh auth login` if you haven't already.
1616
:::
1717

1818
---
@@ -135,13 +135,15 @@ gh stack view --json
135135

136136
### `gh stack checkout`
137137

138-
Check out a stack from a pull request number, URL, or branch name.
138+
Check out a stack by its stack number, a pull request number, a PR URL, or a branch name.
139139

140140
```sh
141-
gh stack checkout [<pr-number> | <pr-url> | <branch>]
141+
gh stack checkout [<stack-number> | <pr-number> | <pr-url> | <branch>]
142142
```
143143

144-
When a PR number or URL is provided (e.g., `123` or `https://github.com/owner/repo/pull/123`), the command fetches the stack on GitHub, pulls the branches, and sets up the stack locally. If the stack already exists locally and matches, it switches to the branch. If the local and remote stacks have different compositions, you'll be prompted to resolve the conflict.
144+
A bare number is interpreted first as a stack or PR number (repo-scoped identifiers shown in the GitHub UI). If nothing matches the number, it is tried as a branch name.
145+
146+
When a remote stack is referenced, the command fetches the stack on GitHub, pulls the branches, and sets up the stack locally. If the stack already exists locally and matches, it switches to the branch. If the local and remote stacks have different compositions, you'll be prompted to resolve the conflict.
145147

146148
When a branch name is provided, the command resolves it against locally tracked stacks only.
147149

@@ -150,6 +152,9 @@ When run without arguments in an interactive terminal, shows a menu of all local
150152
**Examples:**
151153

152154
```sh
155+
# Check out a stack by its stack number
156+
gh stack checkout 7
157+
153158
# Check out a stack by PR number
154159
gh stack checkout 42
155160

@@ -229,28 +234,31 @@ gh stack modify --abort
229234

230235
### `gh stack unstack`
231236

232-
Remove a stack from local tracking and delete it on GitHub. Also available as `gh stack delete`.
237+
Remove a stack from local tracking and unstack it on GitHub. Also available as `gh stack delete`.
233238

234239
```sh
235-
gh stack unstack [flags]
240+
gh stack unstack [<stack-number>] [flags]
236241
```
237242

238-
You must have a branch from the stack checked out locally. The command targets the active stack — the one that contains the currently checked out branch.
243+
With no argument, the command targets the active stack — the one that contains the currently checked out branch. Provide a stack number (the identifier shown in the github.com stack UI) to target a specific locally tracked stack instead.
239244

240-
Deletes the stack on GitHub first, if it exists, then removes it from local tracking. If the remote deletion fails, the local state is left untouched so you can retry. Use `--local` to skip the remote deletion and only remove local tracking.
245+
PRs that are merged, merging, or queued for merge cannot be removed from a stack on GitHub and are left part of the stack. When every pull request is removed, the stack is dissolved and local tracking is removed; when some pull requests remain stacked, local tracking is kept. Use `--local` to skip the remote operation and only remove local tracking.
241246

242247
This is useful when you need to restructure a stack — remove a branch, insert a branch, reorder branches, rename branches, or make other large changes. After unstacking, use `gh stack init` to re-create the stack with the desired structure — existing branches are adopted automatically.
243248

244249
| Flag | Description |
245250
|------|-------------|
246-
| `--local` | Only delete the stack locally (keep it on GitHub) |
251+
| `--local` | Only remove the stack locally (keep it on GitHub) |
247252

248253
**Examples:**
249254

250255
```sh
251-
# Delete the stack on GitHub and remove local tracking
256+
# Unstack the current stack on GitHub and remove local tracking
252257
gh stack unstack
253258

259+
# Unstack a specific stack by its stack number
260+
gh stack unstack 7
261+
254262
# Only remove local tracking
255263
gh stack unstack --local
256264
```
@@ -317,7 +325,7 @@ Performs a synchronization of the entire stack:
317325

318326
A clean remote-ahead update (PRs added on top of your local stack) is pulled down automatically without prompting, so `sync` is safe to run in automation. Sync only prompts when the stacks have truly diverged.
319327

320-
#### Diverged stacks
328+
**Diverged stacks**
321329

322330
When neither stack is a clean prefix of the other — for example, you added a branch locally while separate PRs were added to the same stack on GitHub — sync cannot merge the two automatically. In an interactive terminal it offers three choices:
323331

‎skills/gh-stack/SKILL.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ Small, incidental fixes (e.g., fixing a typo you noticed) can go in the current
161161
| View stack details (JSON) | `gh stack view --json` |
162162
| Switch branches up/down in stack | `gh stack up [n]` / `gh stack down [n]` |
163163
| Switch to top/bottom branch | `gh stack top` / `gh stack bottom` |
164+
| Check out by stack number | `gh stack checkout 7` |
164165
| Check out by PR | `gh stack checkout 42` |
165166
| Check out by branch (local only) | `gh stack checkout feature-auth` |
166-
| Tear down a stack to restructure it | `gh stack unstack` |
167+
| Tear down the current stack to restructure it | `gh stack unstack` |
168+
| Tear down a specific stack by number | `gh stack unstack 7` |
167169

168170
---
169171

0 commit comments

Comments
 (0)