@@ -1200,15 +1200,11 @@ type remoteReconcileResult struct {
12001200 // original pointer).
12011201 stack * stack.Stack
12021202
1203- // skipStackObjectSync tells runSync to skip the later syncStack step so we
1204- // never push the local stack over a divergent remote. Set when disassociating.
1205- skipStackObjectSync bool
1206-
1207- // abort tells runSync to stop the whole sync immediately (before any
1208- // fast-forward, rebase, or push) and exit successfully without changes. Set
1209- // when the user cancels an interactive divergence prompt, or when a
1210- // divergence is detected in a non-interactive terminal.
1211- abort bool
1203+ // stop tells runSync to end the sync immediately after reconcile (before any
1204+ // fast-forward, rebase, or push) and exit successfully. Set when the user
1205+ // cancels or deletes the remote stack, and when a divergence is detected in a
1206+ // non-interactive terminal. The resolving path prints its own outcome message.
1207+ stop bool
12121208}
12131209
12141210// remoteStackClass classifies the relationship between the local stack's active
@@ -1424,14 +1420,14 @@ func resolveStackDivergence(cfg *config.Config, client github.ClientOps, sf *sta
14241420 if ! cfg .IsInteractive () {
14251421 cfg .Printf (" Re-run in an interactive terminal to resolve, or import the remote stack with `%s`." ,
14261422 cfg .ColorCyan ("gh stack checkout <pr>" ))
1427- return remoteReconcileResult {abort : true }, nil
1423+ cfg .Infof ("Sync aborted — no changes were made" )
1424+ return remoteReconcileResult {stop : true }, nil
14281425 }
14291426
14301427 options := []string {
1431- "Use the remote stack as the source of truth (update local to match)" ,
1432- "Use your local stack as the source of truth (update remote to match)" ,
1433- "Disassociate — unlink local stack with remote on GitHub" ,
1434- "Cancel — abort the sync and do not make any changes" ,
1428+ "Update local to match remote — replace your local stack with the remote version" ,
1429+ "Delete the remote stack on GitHub — keep your local stack and recreate on remote later" ,
1430+ "Cancel — make no changes" ,
14351431 }
14361432 p := prompter .New (cfg .In , cfg .Out , cfg .Err )
14371433 selectFn := func (prompt , def string , opts []string ) (int , error ) {
@@ -1447,7 +1443,7 @@ func resolveStackDivergence(cfg *config.Config, client github.ClientOps, sf *sta
14471443 clearSelectPrompt (cfg , len (options ))
14481444 }
14491445 printInterrupt (cfg )
1450- return remoteReconcileResult {abort : true }, errInterrupt
1446+ return remoteReconcileResult {stop : true }, errInterrupt
14511447 }
14521448 cfg .Errorf ("selection failed: %v" , err )
14531449 return remoteReconcileResult {}, ErrSilent
@@ -1457,12 +1453,11 @@ func resolveStackDivergence(cfg *config.Config, client github.ClientOps, sf *sta
14571453 case 0 :
14581454 return resolveDivergenceUseRemote (cfg , sf , s , currentBranch , gitDir , remote , prs )
14591455 case 1 :
1460- return resolveDivergenceUseLocal (cfg , client , sf , s , gitDir )
1461- case 2 :
1462- return resolveDivergenceDisassociate (cfg , sf , s , gitDir )
1456+ return resolveDivergenceDeleteRemote (cfg , client , sf , s , gitDir )
14631457 default :
1464- // Cancel: abort the whole sync without touching branches or PRs.
1465- return remoteReconcileResult {abort : true }, nil
1458+ // Cancel: stop the sync without touching branches or PRs.
1459+ cfg .Infof ("Sync aborted — no changes were made" )
1460+ return remoteReconcileResult {stop : true }, nil
14661461 }
14671462}
14681463
@@ -1476,7 +1471,6 @@ func resolveDivergenceUseRemote(cfg *config.Config, sf *stack.StackFile, s *stac
14761471
14771472 if dirty , err := git .HasUncommittedChanges (); err == nil && dirty {
14781473 cfg .Errorf ("You have uncommitted changes — commit or stash them before replacing your local stack with the remote" )
1479- res .skipStackObjectSync = true
14801474 return res , ErrSilent
14811475 }
14821476
@@ -1487,7 +1481,6 @@ func resolveDivergenceUseRemote(cfg *config.Config, sf *stack.StackFile, s *stac
14871481 removeLocalStack (sf , s )
14881482 newStack , err := importRemoteStack (cfg , sf , gitDir , remote , trunk , prs , remoteStackID )
14891483 if err != nil {
1490- res .skipStackObjectSync = true
14911484 return res , err
14921485 }
14931486
@@ -1503,7 +1496,6 @@ func resolveDivergenceUseRemote(cfg *config.Config, sf *stack.StackFile, s *stac
15031496 }
15041497
15051498 if err := stack .Save (gitDir , sf ); err != nil {
1506- res .skipStackObjectSync = true
15071499 return res , handleSaveError (cfg , err )
15081500 }
15091501
@@ -1539,43 +1531,34 @@ func nearestBranchAfterReplace(oldBranches []string, currentBranch string, newSt
15391531 return newStack .Trunk .Branch
15401532}
15411533
1542- // resolveDivergenceUseLocal makes the remote match the local stack by deleting
1543- // the diverged remote stack object and clearing the local ID. The normal
1544- // syncStack step then recreates the stack from the local PR list (when two or
1545- // more PRs exist). Remote PRs dropped from the stack remain open but unstacked.
1546- func resolveDivergenceUseLocal (cfg * config.Config , client github.ClientOps , sf * stack.StackFile , s * stack.Stack , gitDir string ) (remoteReconcileResult , error ) {
1547- var res remoteReconcileResult
1534+ // resolveDivergenceDeleteRemote deletes the diverged stack object on GitHub and
1535+ // removes the local association (clearing the stack ID). The PRs and local
1536+ // branches are left untouched — only the stack grouping on GitHub is removed. It
1537+ // stops the sync and points the user at `gh stack submit` to recreate the stack
1538+ // (which, unlike sync, also creates PRs for any un-submitted branches).
1539+ func resolveDivergenceDeleteRemote (cfg * config.Config , client github.ClientOps , sf * stack.StackFile , s * stack.Stack , gitDir string ) (remoteReconcileResult , error ) {
1540+ res := remoteReconcileResult {stop : true }
15481541
15491542 if err := client .DeleteStack (s .ID ); err != nil {
15501543 var httpErr * api.HTTPError
15511544 if errors .As (err , & httpErr ) && httpErr .StatusCode == 404 {
15521545 cfg .Warningf ("Remote stack already deleted" )
15531546 } else {
15541547 cfg .Errorf ("failed to delete remote stack: %v" , err )
1555- res .skipStackObjectSync = true
15561548 return res , ErrAPIFailure
15571549 }
15581550 } else {
1559- cfg .Successf ("Deleted the diverged stack on GitHub — it will be recreated from your local stack " )
1551+ cfg .Successf ("Deleted the stack on GitHub" )
15601552 }
15611553
15621554 s .ID = ""
15631555 if err := stack .Save (gitDir , sf ); err != nil {
1564- res .skipStackObjectSync = true
15651556 return res , handleSaveError (cfg , err )
15661557 }
1567- return res , nil
1568- }
15691558
1570- // resolveDivergenceDisassociate removes the local stack's remote stack ID so
1571- // the local and remote stacks become independent. The remote stack object is
1572- // left untouched; syncStack is skipped so nothing is pushed over it.
1573- func resolveDivergenceDisassociate (cfg * config.Config , sf * stack.StackFile , s * stack.Stack , gitDir string ) (remoteReconcileResult , error ) {
1574- res := remoteReconcileResult {skipStackObjectSync : true }
1575- s .ID = ""
1576- if err := stack .Save (gitDir , sf ); err != nil {
1577- return res , handleSaveError (cfg , err )
1578- }
1579- cfg .Successf ("Stopped tracking this stack on GitHub — your local and remote stacks are now independent" )
1559+ cfg .Printf ("" )
1560+ cfg .Printf ("Your PRs and local branches are unchanged — only the stack on GitHub was removed." )
1561+ cfg .Printf (" Run `%s` to recreate the stack on GitHub." , cfg .ColorCyan ("gh stack submit" ))
1562+ cfg .Printf (" Run `%s` first if you want to change the stack's structure." , cfg .ColorCyan ("gh stack modify" ))
15801563 return res , nil
15811564}
0 commit comments