Skip to content

Commit 3e82dda

Browse files
committed
rm arg from unstack so it only targets active stack
1 parent de00856 commit 3e82dda

5 files changed

Lines changed: 18 additions & 68 deletions

File tree

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,19 +433,17 @@ gh stack view --json
433433
Remove a stack from local tracking and delete it on GitHub. Also available as `gh stack delete`.
434434

435435
```
436-
gh stack unstack [flags] [branch]
436+
gh stack unstack [flags]
437437
```
438438

439-
If no branch is specified, uses the current branch to find the stack. Deletes the stack on GitHub first, then removes local tracking. Use `--local` to only remove the local tracking entry.
439+
You must have an active stack checkout out locally. The command targets the active stack — the one that contains the currently checked out branch.
440+
441+
Deletes the stack on GitHub first, if it exists, then removes local tracking. Use `--local` to only remove from local tracking.
440442

441443
| Flag | Description |
442444
|------|-------------|
443445
| `--local` | Only delete the stack locally (keep it on GitHub) |
444446

445-
| Argument | Description |
446-
|----------|-------------|
447-
| `[branch]` | A branch in the stack to delete (defaults to the current branch) |
448-
449447
**Examples:**
450448

451449
```sh
@@ -454,9 +452,6 @@ gh stack unstack
454452

455453
# Only remove local tracking
456454
gh stack unstack --local
457-
458-
# Specify a branch to identify the stack
459-
gh stack unstack feature-auth
460455
```
461456

462457
### `gh stack merge`

cmd/unstack.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,19 @@ import (
1111
)
1212

1313
type unstackOptions struct {
14-
target string
15-
local bool
14+
local bool
1615
}
1716

1817
func UnstackCmd(cfg *config.Config) *cobra.Command {
1918
opts := &unstackOptions{}
2019

2120
cmd := &cobra.Command{
22-
Use: "unstack [branch]",
21+
Use: "unstack",
2322
Aliases: []string{"delete"},
2423
Short: "Delete a stack locally and on GitHub",
25-
Long: "Remove a stack from local tracking and delete it on GitHub. Use --local to only remove local tracking.",
26-
Args: cobra.MaximumNArgs(1),
24+
Long: "Remove the current active stack from local tracking and delete it on GitHub. Use --local to only remove local tracking.",
25+
Args: cobra.NoArgs,
2726
RunE: func(cmd *cobra.Command, args []string) error {
28-
if len(args) > 0 {
29-
opts.target = args[0]
30-
}
3127
return runUnstack(cfg, opts)
3228
},
3329
}
@@ -38,7 +34,7 @@ func UnstackCmd(cfg *config.Config) *cobra.Command {
3834
}
3935

4036
func runUnstack(cfg *config.Config, opts *unstackOptions) error {
41-
result, err := loadStack(cfg, opts.target)
37+
result, err := loadStack(cfg, "")
4238
if err != nil {
4339
return ErrNotInStack
4440
}

cmd/unstack_test.go

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -94,37 +94,6 @@ func TestUnstack_Local(t *testing.T) {
9494
assert.Empty(t, sf.Stacks)
9595
}
9696

97-
func TestUnstack_WithTarget(t *testing.T) {
98-
gitDir := t.TempDir()
99-
restore := git.SetOps(&git.MockOps{
100-
GitDirFn: func() (string, error) { return gitDir, nil },
101-
CurrentBranchFn: func() (string, error) { return "unrelated", nil },
102-
})
103-
defer restore()
104-
105-
s1 := stack.Stack{
106-
Trunk: stack.BranchRef{Branch: "main"},
107-
Branches: []stack.BranchRef{{Branch: "b1"}, {Branch: "b2"}},
108-
}
109-
s2 := stack.Stack{
110-
Trunk: stack.BranchRef{Branch: "main"},
111-
Branches: []stack.BranchRef{{Branch: "b3"}, {Branch: "b4"}},
112-
}
113-
writeTwoStacks(t, gitDir, s1, s2)
114-
115-
cfg, outR, errR := config.NewTestConfig()
116-
err := runUnstack(cfg, &unstackOptions{target: "b3", local: true})
117-
output := collectOutput(cfg, outR, errR)
118-
119-
require.NoError(t, err)
120-
assert.Contains(t, output, "Stack removed")
121-
122-
sf, err := stack.Load(gitDir)
123-
require.NoError(t, err)
124-
require.Len(t, sf.Stacks, 1)
125-
assert.Equal(t, []string{"b1", "b2"}, sf.Stacks[0].BranchNames())
126-
}
127-
12897
func TestUnstack_NoStackID_WarnsAndSkipsAPI(t *testing.T) {
12998
gitDir := t.TempDir()
13099
restore := git.SetOps(&git.MockOps{
@@ -225,7 +194,7 @@ func TestUnstack_API409_ShowsErrorAndStopsLocalDeletion(t *testing.T) {
225194
}
226195

227196
func TestUnstack_RemovesCorrectStackByPointer(t *testing.T) {
228-
// Two stacks share the same trunk "main". Targeting "b3" should remove
197+
// Two stacks share the same trunk "main". Current branch "b3" should remove
229198
// only the second stack (b3,b4), leaving the first (b1,b2) intact.
230199
// This verifies pointer-based removal instead of branch-name-based.
231200
gitDir := t.TempDir()
@@ -246,7 +215,7 @@ func TestUnstack_RemovesCorrectStackByPointer(t *testing.T) {
246215
writeTwoStacks(t, gitDir, s1, s2)
247216

248217
cfg, outR, errR := config.NewTestConfig()
249-
err := runUnstack(cfg, &unstackOptions{target: "b3", local: true})
218+
err := runUnstack(cfg, &unstackOptions{local: true})
250219
output := collectOutput(cfg, outR, errR)
251220

252221
require.NoError(t, err)

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,19 @@ gh stack push --remote upstream
346346
Remove a stack from local tracking and delete it on GitHub. Also available as `gh stack delete`.
347347

348348
```sh
349-
gh stack unstack [flags] [branch]
349+
gh stack unstack [flags]
350350
```
351351

352-
Deletes the stack on GitHub first, 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.
352+
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.
353+
354+
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.
353355

354356
This is useful when you need to restructure a stack — remove a branch, reorder branches, rename branches, or make other large changes. After unstacking, use `gh stack init --adopt` to re-create the stack with the desired structure.
355357

356358
| Flag | Description |
357359
|------|-------------|
358360
| `--local` | Only delete the stack locally (keep it on GitHub) |
359361

360-
| Argument | Description |
361-
|----------|-------------|
362-
| `[branch]` | A branch in the stack to identify which stack to delete (defaults to the current branch) |
363-
364362
**Examples:**
365363

366364
```sh
@@ -369,9 +367,6 @@ gh stack unstack
369367

370368
# Only remove local tracking
371369
gh stack unstack --local
372-
373-
# Specify a branch to identify which stack
374-
gh stack unstack feature-auth
375370
```
376371

377372
### `gh stack link`

skills/gh-stack/SKILL.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,10 @@ When a branch name is provided, the command resolves it against locally tracked
788788

789789
Tear down a stack so you can restructure it — remove 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.
790790

791+
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.
792+
791793
```
792-
gh stack unstack [flags] [branch]
794+
gh stack unstack [flags]
793795
```
794796

795797
```bash
@@ -799,19 +801,12 @@ gh stack init --base main --adopt branch-2 branch-1 branch-3 # reordered
799801

800802
# Only remove local tracking (keep the stack on GitHub)
801803
gh stack unstack --local
802-
803-
# Specify a branch to identify which stack to tear down
804-
gh stack unstack feature-auth
805804
```
806805

807806
| Flag | Description |
808807
|------|-------------|
809808
| `--local` | Only delete the stack locally (keep it on GitHub) |
810809

811-
| Argument | Description |
812-
|----------|-------------|
813-
| `[branch]` | A branch in the stack (defaults to the current branch) |
814-
815810
---
816811

817812
## Output conventions

0 commit comments

Comments
 (0)