Skip to content

Commit

Permalink
[MER-877] cli: improve error message if stack branch fails (#41)
Browse files Browse the repository at this point in the history
not totally sure what i'm doing but i think it works??

<img width="989" alt="Screen Shot 2022-07-06 at 1 03 48 PM" src="https://user-images.githubusercontent.com/13113118/177633714-9189dd40-0078-4d47-93d9-ef1e2039299f.png">
  • Loading branch information
doratzeng authored Jul 13, 2022
1 parent 6a4c35f commit a960c3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
11 changes: 1 addition & 10 deletions cmd/av/stack_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
Expand Down
13 changes: 11 additions & 2 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit a960c3c

Please sign in to comment.