Skip to content

Commit bd76d31

Browse files
committed
early exit if all branches merged
1 parent 9b6b712 commit bd76d31

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Push all branches and create/update PRs and the stack on GitHub.
283283
gh stack submit [flags]
284284
```
285285

286-
Creates a Stacked PR for every branch in the stack, pushing branches to remote if needed.
286+
Creates a Stacked PR for every branch in the stack, pushing branches to the remote.
287287

288288
After creating PRs, `submit` automatically creates a **Stack** on GitHub to link the PRs together. If the stack already exists on GitHub (e.g., from a previous submit), new PRs will be added to the top of the stack.
289289

cmd/push.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func runPush(cfg *config.Config, opts *pushOptions) error {
7676
cfg.Printf("Skipping %d merged %s", len(merged), plural(len(merged), "branch", "branches"))
7777
}
7878
activeBranches := activeBranchNames(s)
79+
if len(activeBranches) == 0 {
80+
cfg.Printf("No active branches to push (all merged)")
81+
return nil
82+
}
7983
cfg.Printf("Pushing %d %s to %s...", len(activeBranches), plural(len(activeBranches), "branch", "branches"), remote)
8084
if err := git.Push(remote, activeBranches, true, true); err != nil {
8185
cfg.Errorf("failed to push: %s", err)

cmd/rebase.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ func runRebase(cfg *config.Config, opts *rebaseOptions) error {
324324
}
325325

326326
cfg.Printf("%s rebased locally with %s", rangeDesc, s.Trunk.Branch)
327-
cfg.Printf("To push up your changes and open/update the stack of PRs, run `%s`",
328-
cfg.ColorCyan("gh stack submit"))
327+
cfg.Printf("To push up your changes, run `%s`",
328+
cfg.ColorCyan("gh stack push"))
329329

330330
return nil
331331
}

cmd/submit.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func runSubmit(cfg *config.Config, opts *submitOptions) error {
9090
cfg.Printf("Skipping %d merged %s", len(merged), plural(len(merged), "branch", "branches"))
9191
}
9292
activeBranches := activeBranchNames(s)
93+
if len(activeBranches) == 0 {
94+
cfg.Printf("All branches are merged, nothing to submit")
95+
return nil
96+
}
9397
cfg.Printf("Pushing %d %s to %s...", len(activeBranches), plural(len(activeBranches), "branch", "branches"), remote)
9498
if err := git.Push(remote, activeBranches, true, true); err != nil {
9599
cfg.Errorf("failed to push: %s", err)
@@ -304,14 +308,14 @@ func handleCreate422(cfg *config.Config, httpErr *api.HTTPError) {
304308
msg := httpErr.Message
305309

306310
if strings.Contains(msg, "already stacked") {
307-
cfg.Errorf("One or more PRs are already part of an existing stack on GitHub")
311+
cfg.Warningf("One or more PRs are already part of an existing stack on GitHub")
308312
cfg.Printf(" To fix this, unstack the PRs from the web, then `%s`",
309313
cfg.ColorCyan("gh stack submit"))
310314
return
311315
}
312316

313317
if strings.Contains(msg, "must form a stack") {
314-
cfg.Errorf("Cannot create stack: %s", msg)
318+
cfg.Warningf("Cannot create stack: %s", msg)
315319
cfg.Printf(" Each PR's base branch must match the previous PR's head branch.")
316320
return
317321
}

0 commit comments

Comments
 (0)