1- // cmd/cascade .go
1+ // cmd/restack .go
22package cmd
33
44import (
@@ -15,31 +15,31 @@ import (
1515 "github.com/spf13/cobra"
1616)
1717
18- // ErrConflict indicates a rebase conflict occurred during cascade .
18+ // ErrConflict indicates a rebase conflict occurred during restack .
1919var ErrConflict = errors .New ("rebase conflict: resolve and run 'gh stack continue', or 'gh stack abort'" )
2020
21- var cascadeCmd = & cobra.Command {
21+ var restackCmd = & cobra.Command {
2222 Use : "restack" ,
2323 Aliases : []string {"cascade" },
2424 Short : "Rebase current branch and descendants onto their parents" ,
2525 Long : `Rebase the current branch onto its parent, then recursively restack descendants.` ,
26- RunE : runCascade ,
26+ RunE : runRestack ,
2727}
2828
2929var (
30- cascadeOnlyFlag bool
31- cascadeDryRunFlag bool
32- cascadeWorktreesFlag bool
30+ restackOnlyFlag bool
31+ restackDryRunFlag bool
32+ restackWorktreesFlag bool
3333)
3434
3535func init () {
36- cascadeCmd .Flags ().BoolVar (& cascadeOnlyFlag , "only" , false , "only restack current branch, not descendants" )
37- cascadeCmd .Flags ().BoolVar (& cascadeDryRunFlag , "dry-run" , false , "show what would be done" )
38- cascadeCmd .Flags ().BoolVar (& cascadeWorktreesFlag , "worktrees" , false , "rebase branches checked out in linked worktrees in-place" )
39- rootCmd .AddCommand (cascadeCmd )
36+ restackCmd .Flags ().BoolVar (& restackOnlyFlag , "only" , false , "only restack current branch, not descendants" )
37+ restackCmd .Flags ().BoolVar (& restackDryRunFlag , "dry-run" , false , "show what would be done" )
38+ restackCmd .Flags ().BoolVar (& restackWorktreesFlag , "worktrees" , false , "rebase branches checked out in linked worktrees in-place" )
39+ rootCmd .AddCommand (restackCmd )
4040}
4141
42- func runCascade (cmd * cobra.Command , args []string ) error {
42+ func runRestack (cmd * cobra.Command , args []string ) error {
4343 s := style .New ()
4444
4545 cwd , err := os .Getwd ()
@@ -54,7 +54,7 @@ func runCascade(cmd *cobra.Command, args []string) error {
5454
5555 g := git .New (cwd )
5656
57- // Check if cascade already in progress
57+ // Check if restack already in progress
5858 if state .Exists (g .GetGitDir ()) {
5959 return errors .New ("operation already in progress; use 'gh stack continue' or 'gh stack abort'" )
6060 }
@@ -76,36 +76,36 @@ func runCascade(cmd *cobra.Command, args []string) error {
7676 return fmt .Errorf ("branch %q is not tracked in the stack\n \n To add it, run:\n gh stack adopt %s # to stack on %s\n gh stack adopt -p <parent> # to stack on a different branch" , currentBranch , trunk , trunk )
7777 }
7878
79- // Collect branches to cascade
79+ // Collect branches to restack
8080 var branches []* tree.Node
8181 branches = append (branches , node )
82- if ! cascadeOnlyFlag {
82+ if ! restackOnlyFlag {
8383 branches = append (branches , tree .GetDescendants (node )... )
8484 }
8585
8686 // Save undo snapshot (unless dry-run)
8787 var stashRef string
88- if ! cascadeDryRunFlag {
88+ if ! restackDryRunFlag {
8989 var saveErr error
90- stashRef , saveErr = saveUndoSnapshot (g , cfg , branches , nil , "cascade " , "gh stack restack" , s )
90+ stashRef , saveErr = saveUndoSnapshot (g , cfg , branches , nil , "restack " , "gh stack restack" , s )
9191 if saveErr != nil {
9292 fmt .Printf ("%s could not save undo state: %v\n " , s .WarningIcon (), saveErr )
9393 }
9494 }
9595
9696 // Build worktree map if --worktrees flag is set
9797 var worktrees map [string ]string
98- if cascadeWorktreesFlag {
98+ if restackWorktreesFlag {
9999 var wtErr error
100100 worktrees , wtErr = g .ListWorktrees ()
101101 if wtErr != nil {
102102 return fmt .Errorf ("failed to list worktrees: %w" , wtErr )
103103 }
104104 }
105105
106- err = doCascadeWithState (g , cfg , branches , CascadeOptions {
107- DryRun : cascadeDryRunFlag ,
108- Operation : state .OperationCascade ,
106+ err = doRestackWithState (g , cfg , branches , RestackOptions {
107+ DryRun : restackDryRunFlag ,
108+ Operation : state .OperationRestack ,
109109 StashRef : stashRef ,
110110 Worktrees : worktrees ,
111111 }, s )
@@ -121,15 +121,15 @@ func runCascade(cmd *cobra.Command, args []string) error {
121121 return err
122122}
123123
124- // CascadeOptions configures the behaviour of doCascadeWithState .
124+ // RestackOptions configures the behaviour of doRestackWithState .
125125//
126126// The submit-specific fields (UpdateOnly, OpenWeb, PushOnly, Branches) are
127127// only meaningful when Operation is state.OperationSubmit; they are persisted
128- // to cascade state so that the push/PR phases can be resumed after a conflict.
129- type CascadeOptions struct {
128+ // to restack state so that the push/PR phases can be resumed after a conflict.
129+ type RestackOptions struct {
130130 // DryRun prints what would be done without actually rebasing.
131131 DryRun bool
132- // Operation is the type of operation being performed (state.OperationCascade
132+ // Operation is the type of operation being performed (state.OperationRestack
133133 // or state.OperationSubmit).
134134 Operation string
135135 // UpdateOnly skips creating new PRs; only existing PRs are updated.
@@ -140,8 +140,8 @@ type CascadeOptions struct {
140140 // PushOnly skips the PR creation/update phase entirely. Submit-only.
141141 PushOnly bool
142142 // Branches is the complete list of branch names being submitted, used
143- // to rebuild the full set for push/PR phases after cascade completes.
144- // Submit-only. Mirrors state.CascadeState .Branches.
143+ // to rebuild the full set for push/PR phases after restack completes.
144+ // Submit-only. Mirrors state.RestackState .Branches.
145145 Branches []string
146146 // StashRef is the commit hash of auto-stashed changes (if any), persisted
147147 // to state so they can be restored when the operation completes or is aborted.
@@ -152,8 +152,8 @@ type CascadeOptions struct {
152152 Worktrees map [string ]string
153153}
154154
155- // doCascadeWithState performs cascade and saves state with the given operation type.
156- func doCascadeWithState (g * git.Git , cfg * config.Config , branches []* tree.Node , opts CascadeOptions , s * style.Style ) error {
155+ // doRestackWithState performs restack and saves state with the given operation type.
156+ func doRestackWithState (g * git.Git , cfg * config.Config , branches []* tree.Node , opts RestackOptions , s * style.Style ) error {
157157 originalBranch , err := g .CurrentBranch ()
158158 if err != nil {
159159 return err
@@ -287,7 +287,7 @@ func doCascadeWithState(g *git.Git, cfg *config.Config, branches []*tree.Node, o
287287 remaining = append (remaining , r .Name )
288288 }
289289
290- st := & state.CascadeState {
290+ st := & state.RestackState {
291291 Current : b .Name ,
292292 Pending : remaining ,
293293 OriginalHead : originalHead ,
@@ -323,7 +323,7 @@ func doCascadeWithState(g *git.Git, cfg *config.Config, branches []*tree.Node, o
323323
324324 // Return to original branch
325325 if ! opts .DryRun {
326- _ = g .Checkout (originalBranch ) //nolint:errcheck // best effort - cascade succeeded
326+ _ = g .Checkout (originalBranch ) //nolint:errcheck // best effort - restack succeeded
327327 }
328328
329329 return nil
@@ -332,7 +332,7 @@ func doCascadeWithState(g *git.Git, cfg *config.Config, branches []*tree.Node, o
332332// displayOperationName maps internal operation constants to user-facing names.
333333func displayOperationName (op string ) string {
334334 switch op {
335- case state .OperationCascade :
335+ case state .OperationRestack :
336336 return "Restack"
337337 case state .OperationSubmit :
338338 return "Submit"
0 commit comments