@@ -2,6 +2,7 @@ package cmd
22
33import (
44 "fmt"
5+ "io"
56 "os"
67 "strings"
78
@@ -59,9 +60,8 @@ func runAdd(cmd *cobra.Command, args []string) error {
5960 remote := worktree .DefaultRemote ()
6061
6162 if remote != "" {
62- if err := ui .Spin (fmt .Sprintf ("Fetching from %s" , remote ), func () error {
63- _ , err := git .RunWithOutput ("fetch" , remote , "--prune" )
64- return err
63+ if err := ui .SpinWithOutput (fmt .Sprintf ("Fetching from %s" , remote ), func (w io.Writer ) error {
64+ return git .RunTo (w , "fetch" , remote , "--prune" )
6565 }); err != nil {
6666 return err
6767 }
@@ -139,17 +139,15 @@ func runAddInteractive(remote string) error {
139139
140140 // Create worktree from selected remote branch
141141 branch := selected .Value
142- if err := ui .Spin (fmt .Sprintf ("Creating worktree for %s" , ui .Accent (branch )), func () error {
143- _ , err := git .RunWithOutput ("worktree" , "add" , "-b" , branch , branch , remote + "/" + branch )
144- return err
142+ if err := ui .SpinWithOutput (fmt .Sprintf ("Creating worktree for %s" , ui .Accent (branch )), func (w io.Writer ) error {
143+ return git .RunTo (w , "worktree" , "add" , "-b" , branch , branch , remote + "/" + branch )
145144 }); err != nil {
146145 return err
147146 }
148147
149148 // Set upstream tracking
150- if err := ui .Spin (fmt .Sprintf ("Setting upstream to %s" , ui .Accent (remote + "/" + branch )), func () error {
151- _ , err := git .RunWithOutput ("branch" , "--set-upstream-to=" + remote + "/" + branch , branch )
152- return err
149+ if err := ui .SpinWithOutput (fmt .Sprintf ("Setting upstream to %s" , ui .Accent (remote + "/" + branch )), func (w io.Writer ) error {
150+ return git .RunTo (w , "branch" , "--set-upstream-to=" + remote + "/" + branch , branch )
153151 }); err != nil {
154152 return err
155153 }
@@ -167,9 +165,8 @@ func createNewBranch() error {
167165
168166 wtPath := branchName
169167
170- return ui .Spin (fmt .Sprintf ("Creating worktree for %s" , ui .Accent (branchName )), func () error {
171- _ , err := git .RunWithOutput ("worktree" , "add" , "-b" , branchName , wtPath )
172- return err
168+ return ui .SpinWithOutput (fmt .Sprintf ("Creating worktree for %s" , ui .Accent (branchName )), func (w io.Writer ) error {
169+ return git .RunTo (w , "worktree" , "add" , "-b" , branchName , wtPath )
173170 })
174171}
175172
@@ -199,9 +196,8 @@ func runAddDirect(cmd *cobra.Command, args []string, remote string) error {
199196
200197 // Create the worktree
201198 fullArgs := append ([]string {"worktree" , "add" }, gitArgs ... )
202- if err := ui .Spin ("Creating worktree" , func () error {
203- _ , err := git .RunWithOutput (fullArgs ... )
204- return err
199+ if err := ui .SpinWithOutput ("Creating worktree" , func (w io.Writer ) error {
200+ return git .RunTo (w , fullArgs ... )
205201 }); err != nil {
206202 return err
207203 }
@@ -213,9 +209,8 @@ func runAddDirect(cmd *cobra.Command, args []string, remote string) error {
213209 }
214210 if trackBranch != "" && remote != "" {
215211 if _ , err := git .Query ("rev-parse" , "--verify" , remote + "/" + trackBranch ); err == nil {
216- if err := ui .Spin (fmt .Sprintf ("Setting upstream to %s" , ui .Accent (remote + "/" + trackBranch )), func () error {
217- _ , err := git .RunWithOutput ("branch" , "--set-upstream-to=" + remote + "/" + trackBranch , trackBranch )
218- return err
212+ if err := ui .SpinWithOutput (fmt .Sprintf ("Setting upstream to %s" , ui .Accent (remote + "/" + trackBranch )), func (w io.Writer ) error {
213+ return git .RunTo (w , "branch" , "--set-upstream-to=" + remote + "/" + trackBranch , trackBranch )
219214 }); err != nil {
220215 return err
221216 }
0 commit comments