Skip to content

Commit 531a959

Browse files
committed
Surface the stack number in output and TUIs
Show the human-facing stack number wherever it is known: - Append a "(stack #N)" label to submit, link, checkout, and unstack success messages. - Add a "Stack #N" header line to the view command (short and static) and the stackview TUI header. - Add a "Stack #N" info line to the submit TUI header when submitting an already-created stack. Copilot-Session: 03673c26-a245-42da-93ed-dfcebc92a740
1 parent 329aef4 commit 531a959

12 files changed

Lines changed: 171 additions & 67 deletions

File tree

‎cmd/checkout.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func reconcileAndImportRemoteStack(cfg *config.Config, client github.ClientOps,
327327
if err := stack.Save(gitDir, sf); err != nil {
328328
return nil, "", handleSaveError(cfg, err)
329329
}
330-
cfg.Successf("Local stack matches remote — switching to branch")
330+
cfg.Successf("Local stack matches remote — switching to branch%s", stackLabel(remoteStack.Number))
331331
return localStack, targetBranch, nil
332332
}
333333

@@ -592,7 +592,7 @@ func importRemoteStack(
592592
// Update base SHAs from actual local refs
593593
updateBaseSHAs(s)
594594

595-
cfg.Successf("Imported stack with %d branches from GitHub", len(prs))
595+
cfg.Successf("Imported stack with %d branches from GitHub%s", len(prs), stackLabel(remoteStackNumber))
596596
return s, nil
597597
}
598598

‎cmd/link.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ func findMatchingStack(stacks []github.RemoteStack, prNumbers []int) (*github.Re
551551

552552
// createLink creates a new stack with the given PR numbers.
553553
func createLink(cfg *config.Config, client github.ClientOps, prNumbers []int) error {
554-
if _, err := client.CreateStack(prNumbers); err != nil {
554+
rs, err := client.CreateStack(prNumbers)
555+
if err != nil {
555556
var httpErr *api.HTTPError
556557
if errors.As(err, &httpErr) {
557558
switch httpErr.StatusCode {
@@ -570,7 +571,7 @@ func createLink(cfg *config.Config, client github.ClientOps, prNumbers []int) er
570571
return ErrAPIFailure
571572
}
572573

573-
cfg.Successf("Created stack with %d PRs", len(prNumbers))
574+
cfg.Successf("Created stack with %d PRs%s", len(prNumbers), stackLabel(rs.Number))
574575
return nil
575576
}
576577

@@ -617,7 +618,8 @@ func updateLink(cfg *config.Config, client github.ClientOps, existing *github.Re
617618
return ErrInvalidArgs
618619
}
619620

620-
if _, err := client.AddToStack(existing.Number, delta); err != nil {
621+
rs, err := client.AddToStack(existing.Number, delta)
622+
if err != nil {
621623
var httpErr *api.HTTPError
622624
if errors.As(err, &httpErr) {
623625
switch httpErr.StatusCode {
@@ -637,7 +639,7 @@ func updateLink(cfg *config.Config, client github.ClientOps, existing *github.Re
637639
return ErrAPIFailure
638640
}
639641

640-
cfg.Successf("Updated stack to %d PRs", len(prNumbers))
642+
cfg.Successf("Updated stack to %d PRs%s", len(prNumbers), stackLabel(rs.Number))
641643
return nil
642644
}
643645

‎cmd/submit.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ func collectPRDrafts(cfg *config.Config, client github.ClientOps, s *stack.Stack
295295
RepoLabel: repoLabel,
296296
Version: Version,
297297
CanCreateStack: canCreateStack,
298+
StackNumber: s.Number,
298299
})
299300

300301
// Use cell-motion mouse mode (clicks, drag, and wheel) rather than all-motion.
@@ -780,7 +781,7 @@ func reconcileUntrackedStack(cfg *config.Config, client github.ClientOps, s *sta
780781
s.Number = matched.Number
781782

782783
if slicesEqual(matched.PRNumbers(), prNumbers) {
783-
cfg.Successf("Linked to the existing stack on GitHub (%d PRs, already up to date)", len(prNumbers))
784+
cfg.Successf("Linked to the existing stack on GitHub (%d PRs, already up to date)%s", len(prNumbers), stackLabel(matched.Number))
784785
return true
785786
}
786787

@@ -836,7 +837,7 @@ func updateStack(cfg *config.Config, client github.ClientOps, s *stack.Stack, pr
836837
if slicesEqual(current, prNumbers) {
837838
s.ID = strconv.Itoa(remote.ID)
838839
s.Number = remote.Number
839-
cfg.Successf("Stack on GitHub is up to date with %d PRs", len(prNumbers))
840+
cfg.Successf("Stack on GitHub is up to date with %d PRs%s", len(prNumbers), stackLabel(remote.Number))
840841
return true
841842
}
842843

@@ -886,7 +887,7 @@ func updateStack(cfg *config.Config, client github.ClientOps, s *stack.Stack, pr
886887

887888
s.ID = strconv.Itoa(rs.ID)
888889
s.Number = rs.Number
889-
cfg.Successf("Stack updated on GitHub with %d PRs", len(prNumbers))
890+
cfg.Successf("Stack updated on GitHub with %d PRs%s", len(prNumbers), stackLabel(rs.Number))
890891
return true
891892
}
892893

@@ -898,7 +899,7 @@ func createNewStack(cfg *config.Config, client github.ClientOps, s *stack.Stack,
898899
if err == nil {
899900
s.ID = strconv.Itoa(rs.ID)
900901
s.Number = rs.Number
901-
cfg.Successf("Stack created on GitHub with %d PRs", len(prNumbers))
902+
cfg.Successf("Stack created on GitHub with %d PRs%s", len(prNumbers), stackLabel(rs.Number))
902903
return true
903904
}
904905

‎cmd/unstack.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func runUnstack(cfg *config.Config, opts *unstackOptions) error {
130130
cfg.Printf("The stack was left in place — local tracking is unchanged")
131131
return nil
132132
} else {
133-
cfg.Successf("Stack removed on GitHub")
133+
cfg.Successf("Stack removed on GitHub%s", stackLabel(number))
134134
}
135135
}
136136
}

‎cmd/utils.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ func warnStacksUnavailable(cfg *config.Config) {
7878
cfg.Warningf("Stacked PRs are not enabled for this repository")
7979
}
8080

81+
// stackLabel returns a " (stack #N)" suffix for appending to user-facing
82+
// messages when the human-facing stack number is known, or an empty string
83+
// otherwise.
84+
func stackLabel(number int) string {
85+
if number <= 0 {
86+
return ""
87+
}
88+
return fmt.Sprintf(" (stack #%d)", number)
89+
}
90+
8191
// stackNumberByID resolves an internal stack ID (as stored in the local stack
8292
// file) to its human-facing stack number by consulting the remote stack list.
8393
// Returns ok=false when no remote stack matches the ID (e.g. it was deleted).

‎cmd/view.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ func viewShort(cfg *config.Config, s *stack.Stack, currentBranch string) error {
144144
repoName = repo.Name
145145
}
146146

147+
if s.Number > 0 {
148+
cfg.Outf("%s\n", cfg.ColorBold(fmt.Sprintf("Stack #%d", s.Number)))
149+
}
150+
147151
for i := len(s.Branches) - 1; i >= 0; i-- {
148152
b := s.Branches[i]
149153
merged := b.IsMerged()
@@ -311,7 +315,7 @@ func viewFullTUI(cfg *config.Config, s *stack.Stack, currentBranch string, prDet
311315
reversed[len(nodes)-1-i] = n
312316
}
313317

314-
model := stackview.New(reversed, s.Trunk, Version)
318+
model := stackview.New(reversed, s.Trunk, Version, s.Number)
315319

316320
p := tea.NewProgram(
317321
model,
@@ -351,6 +355,10 @@ func viewFullStatic(cfg *config.Config, s *stack.Stack, currentBranch string) er
351355

352356
var buf bytes.Buffer
353357

358+
if s.Number > 0 {
359+
fmt.Fprintf(&buf, "%s\n\n", cfg.ColorBold(fmt.Sprintf("Stack #%d", s.Number)))
360+
}
361+
354362
for i := len(s.Branches) - 1; i >= 0; i-- {
355363
b := s.Branches[i]
356364

‎internal/tui/stackview/model.go‎

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ var keys = keyMap{
6363

6464
// Model is the Bubbletea model for the interactive stack view.
6565
type Model struct {
66-
nodes []BranchNode
67-
trunk stack.BranchRef
68-
version string
69-
cursor int // index into nodes (displayed top-down, so 0 = top of stack)
70-
help help.Model
71-
width int
72-
height int
66+
nodes []BranchNode
67+
trunk stack.BranchRef
68+
version string
69+
stackNumber int
70+
cursor int // index into nodes (displayed top-down, so 0 = top of stack)
71+
help help.Model
72+
width int
73+
height int
7374

7475
// scrollOffset tracks vertical scroll position for tall stacks.
7576
scrollOffset int
@@ -78,8 +79,9 @@ type Model struct {
7879
checkoutBranch string
7980
}
8081

81-
// New creates a new stack view model.
82-
func New(nodes []BranchNode, trunk stack.BranchRef, version string) Model {
82+
// New creates a new stack view model. stackNumber is the human-facing stack
83+
// number shown in the header; pass 0 when it is not known.
84+
func New(nodes []BranchNode, trunk stack.BranchRef, version string, stackNumber int) Model {
8385
h := help.New()
8486
h.ShowAll = true
8587

@@ -103,11 +105,12 @@ func New(nodes []BranchNode, trunk stack.BranchRef, version string) Model {
103105
}
104106

105107
return Model{
106-
nodes: nodes,
107-
trunk: trunk,
108-
version: version,
109-
cursor: cursor,
110-
help: h,
108+
nodes: nodes,
109+
trunk: trunk,
110+
version: version,
111+
stackNumber: stackNumber,
112+
cursor: cursor,
113+
help: h,
111114
}
112115
}
113116

@@ -443,15 +446,22 @@ func (m Model) buildHeaderConfig() shared.HeaderConfig {
443446
// is hidden and the actions that depend on it are dimmed; only quit works.
444447
allMerged := branchCount > 0 && mergedCount == branchCount
445448

449+
infoLines := make([]shared.HeaderInfoLine, 0, 3)
450+
if m.stackNumber > 0 {
451+
infoLines = append(infoLines, shared.HeaderInfoLine{Icon: "◆", Label: fmt.Sprintf("Stack #%d", m.stackNumber)})
452+
} else {
453+
infoLines = append(infoLines, shared.HeaderInfoLine{Icon: "✓", Label: "Stack initialized"})
454+
}
455+
infoLines = append(infoLines,
456+
shared.HeaderInfoLine{Icon: "◼", Label: "Base: " + m.trunk.Branch},
457+
shared.HeaderInfoLine{Icon: branchIcon, Label: branchInfo},
458+
)
459+
446460
return shared.HeaderConfig{
447-
ShowArt: true,
448-
Title: "View Stack",
449-
Subtitle: "v" + m.version,
450-
InfoLines: []shared.HeaderInfoLine{
451-
{Icon: "✓", Label: "Stack initialized"},
452-
{Icon: "◆", Label: "Base: " + m.trunk.Branch},
453-
{Icon: branchIcon, Label: branchInfo},
454-
},
461+
ShowArt: true,
462+
Title: "View Stack",
463+
Subtitle: "v" + m.version,
464+
InfoLines: infoLines,
455465
ShortcutColumns: 1,
456466
Shortcuts: []shared.ShortcutEntry{
457467
{Key: "↑↓", Desc: "navigate", Disabled: allMerged},

0 commit comments

Comments
 (0)