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 }