Skip to content

Commit

Permalink
fix(changelog): command does not fail when there was no commit since …
Browse files Browse the repository at this point in the history
…last tag

Release failed with a cryptic git error, when there was no commit since last
tag. Now command exits with `no commits since last tag` error message.

Closes: #1
  • Loading branch information
zbindenren committed Jan 12, 2021
1 parent ecdd4a4 commit adbe8e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (c Command) runRelease(dst io.Writer, l *flash.Logger, cfg config.Changelog
return err
}

if len(revs) == 0 {
return errors.New("no commits since last tag")
}

cw, err := c.createChangelog(g, cfg, l, revs)
if err != nil {
return err
Expand Down
10 changes: 8 additions & 2 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ func (c Command) RevList(start, end string) ([]string, error) {
arg = start + ".." + end
}

refs, err := c.Run("rev-list", arg)
revs, err := c.Run("rev-list", arg)
if err != nil {
return nil, err
}

return strings.Split(strings.TrimSpace(refs), "\n"), nil
revs = strings.TrimSpace(revs)

if revs == "" {
return []string{}, nil
}

return strings.Split(strings.TrimSpace(revs), "\n"), nil
}

// CreateRelease creates a release tag.
Expand Down

0 comments on commit adbe8e1

Please sign in to comment.