Skip to content

Commit 131fc55

Browse files
committed
Release v2.6.1: Fix spinner timing across all commands
Buffer output before stopping spinner in graph, conflicts, sweep, view. Content prints immediately after spinner clears with no visible gap. Updated who spinner message to indicate it may take a moment.
1 parent 9ad5a4b commit 131fc55

7 files changed

Lines changed: 65 additions & 41 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.6.0
1+
2.6.1

cmd/conflicts.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"bytes"
45
"fmt"
56
"regexp"
67
"strings"
@@ -105,9 +106,10 @@ func runConflicts(cmd *cobra.Command, args []string) error {
105106
}
106107
}
107108

108-
sp.Stop()
109+
var buf bytes.Buffer
109110

110111
if len(conflicts) == 0 {
112+
sp.Stop()
111113
ui.PrintSuccess("No conflicts. Clean merge.")
112114
if mb != "" {
113115
stat := git.RunUnchecked("diff", "--stat", mb+".."+target)
@@ -121,7 +123,7 @@ func runConflicts(cmd *cobra.Command, args []string) error {
121123
return nil
122124
}
123125

124-
fmt.Printf("%s %d conflict%s found\n\n", ui.ErrorStyle.Render("X"), len(conflicts), ui.Plural(len(conflicts)))
126+
fmt.Fprintf(&buf, "%s %d conflict%s found\n\n", ui.ErrorStyle.Render("X"), len(conflicts), ui.Plural(len(conflicts)))
125127
for _, f := range conflicts {
126128
// Try to get authors
127129
ourAuthor := git.RunUnchecked("log", "-1", "--format=%an", "--", f)
@@ -130,11 +132,14 @@ func runConflicts(cmd *cobra.Command, args []string) error {
130132
if ourAuthor != "" && theirAuthor != "" && ourAuthor != theirAuthor {
131133
authors = fmt.Sprintf(" (%s + %s)", ourAuthor, theirAuthor)
132134
}
133-
fmt.Printf(" %s%s\n", f, authors)
135+
fmt.Fprintf(&buf, " %s%s\n", f, authors)
134136
}
135137

136138
if cleanFiles > 0 {
137-
fmt.Printf("\n %d other file%s merge cleanly\n", cleanFiles, ui.Plural(cleanFiles))
139+
fmt.Fprintf(&buf, "\n %d other file%s merge cleanly\n", cleanFiles, ui.Plural(cleanFiles))
138140
}
141+
142+
sp.Stop()
143+
fmt.Print(buf.String())
139144
return nil
140145
}

cmd/graph.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"bytes"
45
"fmt"
56

67
"github.com/mubbie/gx-cli/internal/git"
@@ -25,37 +26,42 @@ func runGraph(cmd *cobra.Command, args []string) error {
2526

2627
sp := ui.StartSpinner("Building branch tree...")
2728
tree := stack.BuildTree()
28-
sp.Stop()
29+
2930
if len(tree.Roots) == 0 && len(tree.Orphans) == 0 {
31+
sp.Stop()
3032
fmt.Println("No branches found.")
3133
return nil
3234
}
3335

34-
fmt.Println()
35-
fmt.Println(ui.BoldStyle.Render("Branch Stack:"))
36-
fmt.Println()
36+
var buf bytes.Buffer
37+
fmt.Fprintln(&buf)
38+
fmt.Fprintln(&buf, ui.BoldStyle.Render("Branch Stack:"))
39+
fmt.Fprintln(&buf)
3740

3841
for i, root := range tree.Roots {
3942
isLast := i == len(tree.Roots)-1 && len(tree.Orphans) == 0
40-
renderNode(root, "", isLast)
43+
renderNodeTo(&buf, root, "", isLast)
4144
}
4245

4346
if len(tree.Orphans) > 0 {
44-
fmt.Println()
45-
fmt.Println(ui.WarningStyle.Bold(true).Render("Orphaned Branches:"))
47+
fmt.Fprintln(&buf)
48+
fmt.Fprintln(&buf, ui.WarningStyle.Bold(true).Render("Orphaned Branches:"))
4649
for i, orphan := range tree.Orphans {
47-
renderNode(orphan, "", i == len(tree.Orphans)-1)
50+
renderNodeTo(&buf, orphan, "", i == len(tree.Orphans)-1)
4851
}
4952
}
5053

51-
fmt.Println()
52-
fmt.Println(ui.DimStyle.Render("Legend: * current branch + merged (+ahead/-behind) ! orphaned"))
53-
fmt.Println(ui.DimStyle.Render("Relationships stored in .git/gx/stack.json"))
54-
fmt.Println()
54+
fmt.Fprintln(&buf)
55+
fmt.Fprintln(&buf, ui.DimStyle.Render("Legend: * current branch + merged (+ahead/-behind) ! orphaned"))
56+
fmt.Fprintln(&buf, ui.DimStyle.Render("Relationships stored in .git/gx/stack.json"))
57+
fmt.Fprintln(&buf)
58+
59+
sp.Stop()
60+
fmt.Print(buf.String())
5561
return nil
5662
}
5763

58-
func renderNode(node *stack.BranchNode, prefix string, isLast bool) {
64+
func renderNodeTo(buf *bytes.Buffer, node *stack.BranchNode, prefix string, isLast bool) {
5965
connector := ui.DimStyle.Render("|-- ")
6066
if isLast {
6167
connector = ui.DimStyle.Render("`-- ")
@@ -87,13 +93,13 @@ func renderNode(node *stack.BranchNode, prefix string, isLast bool) {
8793
name = ui.BranchStyle.Render(node.Name)
8894
}
8995

90-
fmt.Printf("%s%s%s%s\n", prefix, connector, name, indicators)
96+
fmt.Fprintf(buf, "%s%s%s%s\n", prefix, connector, name, indicators)
9197

9298
childPrefix := prefix + ui.DimStyle.Render("|") + " "
9399
if isLast {
94100
childPrefix = prefix + " "
95101
}
96102
for i, child := range node.Children {
97-
renderNode(child, childPrefix, i == len(node.Children)-1)
103+
renderNodeTo(buf, child, childPrefix, i == len(node.Children)-1)
98104
}
99105
}

cmd/sweep.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"bytes"
45
"fmt"
56
"strings"
67

@@ -88,42 +89,47 @@ func runSweep(cmd *cobra.Command, args []string) error {
8889
}
8990
}
9091

91-
sp.Stop()
92-
fmt.Println()
93-
9492
if len(merged) == 0 && len(squashMerged) == 0 && len(staleRefs) == 0 {
93+
sp.Stop()
94+
fmt.Println()
9595
ui.PrintSuccess("Nothing to clean up. Repository is tidy!")
9696
return nil
9797
}
9898

99+
var buf bytes.Buffer
100+
fmt.Fprintln(&buf)
101+
99102
if len(merged) > 0 {
100-
fmt.Println(ui.BoldStyle.Render("Merged branches (safe to delete):"))
103+
fmt.Fprintln(&buf, ui.BoldStyle.Render("Merged branches (safe to delete):"))
101104
for _, b := range merged {
102-
fmt.Printf(" %s\n", ui.BranchStyle.Render(b))
105+
fmt.Fprintf(&buf, " %s\n", ui.BranchStyle.Render(b))
103106
}
104-
fmt.Println()
107+
fmt.Fprintln(&buf)
105108
}
106109
if len(squashMerged) > 0 {
107-
fmt.Println(ui.BoldStyle.Render("Likely squash-merged branches:"))
110+
fmt.Fprintln(&buf, ui.BoldStyle.Render("Likely squash-merged branches:"))
108111
for _, b := range squashMerged {
109-
fmt.Printf(" %s\n", ui.BranchStyle.Render(b))
112+
fmt.Fprintf(&buf, " %s\n", ui.BranchStyle.Render(b))
110113
}
111-
fmt.Println()
114+
fmt.Fprintln(&buf)
112115
}
113116
if len(staleRefs) > 0 {
114-
fmt.Println(ui.BoldStyle.Render("Stale remote tracking refs:"))
117+
fmt.Fprintln(&buf, ui.BoldStyle.Render("Stale remote tracking refs:"))
115118
for _, r := range staleRefs {
116-
fmt.Printf(" %s\n", ui.DimStyle.Render(r))
119+
fmt.Fprintf(&buf, " %s\n", ui.DimStyle.Render(r))
117120
}
118-
fmt.Println()
121+
fmt.Fprintln(&buf)
119122
}
120123

121-
fmt.Printf("%s %s merged, %s likely squash-merged, %s stale refs\n\n",
124+
fmt.Fprintf(&buf, "%s %s merged, %s likely squash-merged, %s stale refs\n\n",
122125
ui.BoldStyle.Render("Summary:"),
123126
ui.BoldStyle.Render(fmt.Sprintf("%d", len(merged))),
124127
ui.BoldStyle.Render(fmt.Sprintf("%d", len(squashMerged))),
125128
ui.BoldStyle.Render(fmt.Sprintf("%d", len(staleRefs))))
126129

130+
sp.Stop()
131+
fmt.Print(buf.String())
132+
127133
if dryRun {
128134
fmt.Printf("%s would delete %d branches, %d stale refs\n", ui.WarningStyle.Render("DRY RUN"), len(merged)+len(squashMerged), len(staleRefs))
129135
return nil

cmd/view.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"os/exec"
@@ -81,14 +82,15 @@ func runView(cmd *cobra.Command, args []string) error {
8182

8283
hasGH := isGHAvailable()
8384
var prMap map[string]prInfo
85+
var sp *ui.Spinner
8486
if hasGH {
85-
sp := ui.StartSpinner("Fetching PR status...")
87+
sp = ui.StartSpinner("Fetching PR status...")
8688
prMap = fetchPRMap()
87-
sp.Stop()
8889
}
8990

90-
fmt.Println()
91-
fmt.Println(ui.BranchStyle.Render(trunk))
91+
var buf bytes.Buffer
92+
fmt.Fprintln(&buf)
93+
fmt.Fprintln(&buf, ui.BranchStyle.Render(trunk))
9294
for _, branch := range allBranches {
9395
meta := cfg.Branches[branch]
9496
parent := trunk
@@ -114,9 +116,14 @@ func runView(cmd *cobra.Command, args []string) error {
114116
if branch == current {
115117
parts = append(parts, " "+ui.HeadMarker.Render("<"))
116118
}
117-
fmt.Println(strings.Join(parts, ""))
119+
fmt.Fprintln(&buf, strings.Join(parts, ""))
118120
}
119-
fmt.Println()
121+
fmt.Fprintln(&buf)
122+
123+
if sp != nil {
124+
sp.Stop()
125+
}
126+
fmt.Print(buf.String())
120127
return nil
121128
}
122129

cmd/who.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func runWho(cmd *cobra.Command, args []string) error {
4949
}
5050

5151
func whoRepo(n int, since string) error {
52-
sp := ui.StartSpinner("Analyzing contributors...")
52+
sp := ui.StartSpinner("Analyzing contributors (this may take a moment)...")
5353

5454
// Get commit counts + emails
5555
shortlogArgs := []string{"shortlog", "-sne", "--all"}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "gx-git"
7-
version = "2.6.0"
7+
version = "2.6.1"
88
description = "Git Productivity Toolkit"
99
readme = "README.md"
1010
license = {text = "MIT"}

0 commit comments

Comments
 (0)