diff --git a/client/repos_branch.go b/client/repos_branch.go index 4637256..5cd8a64 100644 --- a/client/repos_branch.go +++ b/client/repos_branch.go @@ -3,6 +3,7 @@ package client import ( "bytes" "context" + "errors" "fmt" "os/exec" "strings" @@ -74,6 +75,8 @@ func (c *Client) Branches(ctx context.Context, dirs []string, args ...string) er }) } + var errs []error + for _, dir := range dirs { currRepo = fmt.Sprintf("\nCurrent Repo: %v", dir) @@ -86,10 +89,6 @@ func (c *Client) Branches(ctx context.Context, dirs []string, args ...string) er cmd.Dir = dir err := cmd.Run() - if err != nil && !verbose { - return fmt.Errorf("branch: %w", err) // TODO: collect errors and return them all - } - if verbose { c.scrb.BeginDescribe(dir) if err != nil { @@ -101,11 +100,15 @@ func (c *Client) Branches(ctx context.Context, dirs []string, args ...string) er c.scrb.EndDescribe() } else { + if err != nil { + errs = append(errs, fmt.Errorf("%s: %w: %s", dir, err, strings.TrimSpace(errout.String()))) + } + bar.Incr() } } currRepo = "" - return nil + return errors.Join(errs...) } diff --git a/client/repos_checkout.go b/client/repos_checkout.go index 96f9b65..9bd0c44 100644 --- a/client/repos_checkout.go +++ b/client/repos_checkout.go @@ -11,10 +11,6 @@ import ( "github.com/gosuri/uiprogress" ) -var ( - ErrUnstagedChanges = errors.New("unstanged changes") -) - func (c *Client) CheckoutRepos(ctx context.Context, dirs []string, args ...string) error { count := len(dirs) args = append([]string{"checkout"}, args...) @@ -44,7 +40,8 @@ func (c *Client) CheckoutRepos(ctx context.Context, dirs []string, args ...strin }) } - unstagedRepos := []string{} + var errs []error + for _, dir := range dirs { currRepo = fmt.Sprintf("\nCurrent Repo: %v", dir) @@ -57,15 +54,6 @@ func (c *Client) CheckoutRepos(ctx context.Context, dirs []string, args ...strin cmd.Dir = dir err := cmd.Run() - if err != nil && !verbose { - if errors.Is(err, ErrUnstagedChanges) { - unstagedRepos = append(unstagedRepos, dir) - continue - } - - return fmt.Errorf("checkout repo: %w", err) //TODO: collect errors and return them all - } - if verbose { c.scrb.BeginDescribe(dir) if err != nil { @@ -77,15 +65,15 @@ func (c *Client) CheckoutRepos(ctx context.Context, dirs []string, args ...strin c.scrb.EndDescribe() } else { + if err != nil { + errs = append(errs, fmt.Errorf("%s: %w: %s", dir, err, strings.TrimSpace(errout.String()))) + } + bar.Incr() } } currRepo = "" - if len(unstagedRepos) > 0 { - return fmt.Errorf("unstaged repos needing manual attention: [%s]", strings.Join(unstagedRepos, ", ")) - } - - return nil + return errors.Join(errs...) } diff --git a/client/repos_commit.go b/client/repos_commit.go index ac50b82..8d2dcc7 100644 --- a/client/repos_commit.go +++ b/client/repos_commit.go @@ -3,6 +3,7 @@ package client import ( "bytes" "context" + "errors" "fmt" "os/exec" "strings" @@ -39,6 +40,8 @@ func (c *Client) CommitRepos(ctx context.Context, dirs []string, args ...string) }) } + var errs []error + for _, dir := range dirs { currRepo = fmt.Sprintf("\nCurrent Repo: %v", dir) @@ -51,10 +54,6 @@ func (c *Client) CommitRepos(ctx context.Context, dirs []string, args ...string) cmd.Dir = dir err := cmd.Run() - if err != nil && !verbose { - return fmt.Errorf("commit repo: %w", err) // TODO: collect errors and return them all - } - if verbose { c.scrb.BeginDescribe(dir) if err != nil { @@ -66,11 +65,15 @@ func (c *Client) CommitRepos(ctx context.Context, dirs []string, args ...string) c.scrb.EndDescribe() } else { + if err != nil { + errs = append(errs, fmt.Errorf("%s: %w: %s", dir, err, strings.TrimSpace(errout.String()))) + } + bar.Incr() } } currRepo = "" - return nil + return errors.Join(errs...) } diff --git a/client/repos_pull.go b/client/repos_pull.go index 47ec73f..48b3c83 100644 --- a/client/repos_pull.go +++ b/client/repos_pull.go @@ -3,6 +3,7 @@ package client import ( "bytes" "context" + "errors" "fmt" "os/exec" "strings" @@ -39,6 +40,8 @@ func (c *Client) PullRepos(ctx context.Context, dirs []string, args ...string) e }) } + var errs []error + for _, dir := range dirs { currRepo = fmt.Sprintf("\nCurrent Repo: %v", dir) @@ -51,10 +54,6 @@ func (c *Client) PullRepos(ctx context.Context, dirs []string, args ...string) e cmd.Dir = dir err := cmd.Run() - if err != nil && !verbose { - return fmt.Errorf("pull repo: %w", err) // TODO: collect errors and return them all - } - if verbose { c.scrb.BeginDescribe(dir) if err != nil { @@ -66,11 +65,15 @@ func (c *Client) PullRepos(ctx context.Context, dirs []string, args ...string) e c.scrb.EndDescribe() } else { + if err != nil { + errs = append(errs, fmt.Errorf("%s: %w: %s", dir, err, strings.TrimSpace(errout.String()))) + } + bar.Incr() } } currRepo = "" - return nil + return errors.Join(errs...) } diff --git a/client/repos_push.go b/client/repos_push.go index a99a6f2..f812169 100644 --- a/client/repos_push.go +++ b/client/repos_push.go @@ -3,6 +3,7 @@ package client import ( "bytes" "context" + "errors" "fmt" "os/exec" "strings" @@ -39,6 +40,8 @@ func (c *Client) PushRepos(ctx context.Context, dirs []string, args ...string) e }) } + var errs []error + for _, dir := range dirs { currRepo = fmt.Sprintf("\nCurrent Repo: %v", dir) @@ -52,10 +55,6 @@ func (c *Client) PushRepos(ctx context.Context, dirs []string, args ...string) e cmd.Dir = dir err = cmd.Run() - if err != nil && !verbose { - return fmt.Errorf("push repo: %w", err) // TODO: collect errors and return them all - } - if verbose { c.scrb.BeginDescribe(dir) if err != nil { @@ -67,11 +66,15 @@ func (c *Client) PushRepos(ctx context.Context, dirs []string, args ...string) e c.scrb.EndDescribe() } else { + if err != nil { + errs = append(errs, fmt.Errorf("%s: %w: %s", dir, err, strings.TrimSpace(errout.String()))) + } + bar.Incr() } } currRepo = "" - return nil + return errors.Join(errs...) } diff --git a/client/repos_stage.go b/client/repos_stage.go index 132f206..45f2d5f 100644 --- a/client/repos_stage.go +++ b/client/repos_stage.go @@ -3,6 +3,7 @@ package client import ( "bytes" "context" + "errors" "fmt" "os/exec" "strings" @@ -39,6 +40,8 @@ func (c *Client) StageFiles(ctx context.Context, dirs []string, args ...string) }) } + var errs []error + for _, dir := range dirs { currRepo = fmt.Sprintf("\nCurrent Repo: %v", dir) @@ -51,10 +54,6 @@ func (c *Client) StageFiles(ctx context.Context, dirs []string, args ...string) cmd.Dir = dir err := cmd.Run() - if err != nil && !verbose { - return fmt.Errorf("stage files: %w", err) // TODO: collect errors and return them all - } - if verbose { c.scrb.BeginDescribe(dir) if err != nil { @@ -66,11 +65,15 @@ func (c *Client) StageFiles(ctx context.Context, dirs []string, args ...string) c.scrb.EndDescribe() } else { + if err != nil { + errs = append(errs, fmt.Errorf("%s: %w: %s", dir, err, strings.TrimSpace(errout.String()))) + } + bar.Incr() } } currRepo = "" - return nil + return errors.Join(errs...) } diff --git a/client/repos_tag.go b/client/repos_tag.go index 1d9909b..d939f58 100644 --- a/client/repos_tag.go +++ b/client/repos_tag.go @@ -3,6 +3,7 @@ package client import ( "bytes" "context" + "errors" "fmt" "os/exec" "strings" @@ -78,6 +79,8 @@ func (c *Client) TagRepos(ctx context.Context, dirs []string, args ...string) er }) } + var errs []error + for _, dir := range dirs { currRepo = fmt.Sprintf("\nCurrent Repo: %v", dir) @@ -90,10 +93,6 @@ func (c *Client) TagRepos(ctx context.Context, dirs []string, args ...string) er cmd.Dir = dir err := cmd.Run() - if err != nil && !verbose { - return fmt.Errorf("tag repo: %w", err) // TODO: collect errors and return them all - } - if verbose { c.scrb.BeginDescribe(dir) if err != nil { @@ -105,11 +104,15 @@ func (c *Client) TagRepos(ctx context.Context, dirs []string, args ...string) er c.scrb.EndDescribe() } else { + if err != nil { + errs = append(errs, fmt.Errorf("%s: %w: %s", dir, err, strings.TrimSpace(errout.String()))) + } + bar.Incr() } } currRepo = "" - return nil + return errors.Join(errs...) }