Skip to content

Commit

Permalink
improve error message for dirty git tree (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelanford committed Feb 25, 2022
1 parent 02fddf9 commit 31b0a32
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/diff/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func Run(opts Options) (*Diff, error) {
if stat, err := wt.Status(); err != nil {
return nil, fmt.Errorf("failed to get git status: %w", err)
} else if !stat.IsClean() {
return nil, fmt.Errorf("git tree is dirty")
return nil, &GitStatusError{stat, fmt.Errorf("current git tree is dirty")}
}

origRef, err := repo.Head()
Expand Down Expand Up @@ -103,6 +103,15 @@ func Run(opts Options) (*Diff, error) {
return diff, nil
}

type GitStatusError struct {
Stat git.Status
Err error
}

func (err *GitStatusError) Error() string {
return fmt.Sprintf("%v\n%v", err.Err, err.Stat)
}

func compareChangesAdditionsAndRemovals(oldPkgs, newPkgs map[string]*packages.Package) (map[string]apidiff.Report, bool) {
reports, incompatible := compareChangesAndAdditions(oldPkgs, newPkgs)

Expand Down

0 comments on commit 31b0a32

Please sign in to comment.