From a960c3cba380ef1f6786378f3809f178f190ffad Mon Sep 17 00:00:00 2001 From: doratzeng Date: Tue, 12 Jul 2022 20:00:13 -0700 Subject: [PATCH] [MER-877] cli: improve error message if stack branch fails (#41) not totally sure what i'm doing but i think it works?? Screen Shot 2022-07-06 at 1 03 48 PM --- cmd/av/stack_branch.go | 11 +---------- internal/git/git.go | 13 +++++++++++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/av/stack_branch.go b/cmd/av/stack_branch.go index 49e9addc..9104a3eb 100644 --- a/cmd/av/stack_branch.go +++ b/cmd/av/stack_branch.go @@ -29,11 +29,6 @@ var stackBranchCmd = &cobra.Command{ return err } - // Validate preconditions - if _, err := repo.RevParse(&git.RevParse{Rev: name}); err == nil { - return errors.Errorf("branch %q already exists", name) - } - // Determine important contextual information from Git defaultBranch, err := repo.DefaultBranch() if err != nil { @@ -76,11 +71,7 @@ var stackBranchCmd = &cobra.Command{ Name: name, NewBranch: true, }); err != nil { - logrus.WithError(err).Debugf("failed to checkout branch %q", name) - return errors.Errorf( - "failed to create branch %q (does it already exist?)", - name, - ) + return errors.WrapIff(err, "checkout error") } branchMeta := meta.Branch{Name: name, Parent: parentBranch} diff --git a/internal/git/git.go b/internal/git/git.go index 44838d4b..00c25bdd 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -166,9 +166,18 @@ func (r *Repo) CheckoutBranch(opts *CheckoutBranch) (string, error) { args = append(args, "-b") } args = append(args, opts.Name) - if _, err := r.Git(args...); err != nil { - return "", err + res, err := r.Run(&RunOpts{ + Args: args, + }) + if err != nil { + return "", err } + if res.ExitCode != 0 { + logrus.WithFields(logrus.Fields{ + "stdout": string(res.Stdout), + "stderr": string(res.Stderr), + }).Debug("git checkout failed") + return "", errors.Errorf("failed to checkout branch %q: %s", opts.Name, string(res.Stderr)) } return previousBranchName, nil }