Skip to content

Commit 5ea2ec8

Browse files
committed
clean up chained branches display
1 parent 47d1a3f commit 5ea2ec8

5 files changed

Lines changed: 13 additions & 28 deletions

File tree

cmd/checkout.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func runCheckout(cfg *config.Config, opts *checkoutOptions) error {
8989
currentBranch, _ := git.CurrentBranch()
9090
if targetBranch == currentBranch {
9191
cfg.Infof("Already on %s", targetBranch)
92-
cfg.Printf("Stack: %s", s.DisplayName())
92+
cfg.Printf("Stack: %s", s.DisplayChain())
9393
return nil
9494
}
9595

@@ -99,7 +99,7 @@ func runCheckout(cfg *config.Config, opts *checkoutOptions) error {
9999
}
100100

101101
cfg.Successf("Switched to %s", targetBranch)
102-
cfg.Printf("Stack: %s", s.DisplayName())
102+
cfg.Printf("Stack: %s", s.DisplayChain())
103103
return nil
104104
}
105105

@@ -148,7 +148,7 @@ func interactiveStackPicker(cfg *config.Config, sf *stack.StackFile) (*stack.Sta
148148

149149
options := make([]string, len(sf.Stacks))
150150
for i := range sf.Stacks {
151-
options[i] = sf.Stacks[i].DisplayName()
151+
options[i] = sf.Stacks[i].DisplayChain()
152152
}
153153

154154
p := prompter.New(cfg.In, cfg.Out, cfg.Err)

cmd/init.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,7 @@ func runInit(cfg *config.Config, opts *initOptions) error {
245245
// Print result
246246
if opts.adopt {
247247
cfg.Printf("Adopting stack with trunk %s and %d branches", trunk, len(branches))
248-
chainParts := []string{"(" + trunk + ")"}
249-
for _, b := range branches {
250-
chainParts = append(chainParts, b)
251-
}
252-
cfg.Printf("Initializing stack: %s", joinChain(chainParts))
248+
cfg.Printf("Initializing stack: %s", newStack.DisplayChain())
253249
cfg.Printf("You can continue working on %s", branches[len(branches)-1])
254250
} else {
255251
cfg.Successf("Creating stack with trunk %s and branch %s", trunk, branches[len(branches)-1])
@@ -272,11 +268,3 @@ func runInit(cfg *config.Config, opts *initOptions) error {
272268
return nil
273269
}
274270

275-
// joinChain formats branches as: (trunk) <- branch1 <- branch2
276-
func joinChain(parts []string) string {
277-
result := parts[0]
278-
for _, p := range parts[1:] {
279-
result += " <- " + p
280-
}
281-
return result
282-
}

cmd/rebase.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,7 @@ func runRebase(cfg *config.Config, opts *rebaseOptions) error {
132132
}
133133
}
134134

135-
chainParts := []string{s.Trunk.Branch}
136-
for _, b := range s.Branches {
137-
chainParts = append(chainParts, b.Branch)
138-
}
139-
cfg.Printf("Stack detected: %s", joinChain(chainParts))
135+
cfg.Printf("Stack detected: %s", s.DisplayChain())
140136

141137
currentIdx := s.IndexOf(currentBranch)
142138
if currentIdx < 0 {

cmd/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func resolveStack(sf *stack.StackFile, branch string, cfg *config.Config) (*stac
9999

100100
options := make([]string, len(stacks))
101101
for i, s := range stacks {
102-
options[i] = s.DisplayName()
102+
options[i] = s.DisplayChain()
103103
}
104104

105105
p := prompter.New(cfg.In, cfg.Out, cfg.Err)
@@ -111,7 +111,7 @@ func resolveStack(sf *stack.StackFile, branch string, cfg *config.Config) (*stac
111111
s := stacks[selected]
112112

113113
if len(s.Branches) == 0 {
114-
return nil, fmt.Errorf("selected stack %q has no branches", s.DisplayName())
114+
return nil, fmt.Errorf("selected stack %q has no branches", s.DisplayChain())
115115
}
116116

117117
// Switch to the top branch of the selected stack so future commands

internal/stack/stack.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"strings"
910
)
1011

1112
const (
@@ -40,14 +41,14 @@ type Stack struct {
4041
Branches []BranchRef `json:"branches"`
4142
}
4243

43-
// DisplayName returns a human-readable chain representation of the stack.
44+
// DisplayChain returns a human-readable chain representation of the stack.
4445
// Format: (trunk) <- branch1 <- branch2 <- branch3
45-
func (s *Stack) DisplayName() string {
46-
result := "(" + s.Trunk.Branch + ")"
46+
func (s *Stack) DisplayChain() string {
47+
parts := []string{"(" + s.Trunk.Branch + ")"}
4748
for _, b := range s.Branches {
48-
result += " <- " + b.Branch
49+
parts = append(parts, b.Branch)
4950
}
50-
return result
51+
return strings.Join(parts, " <- ")
5152
}
5253

5354
// BranchNames returns the list of branch names in order.

0 commit comments

Comments
 (0)