Skip to content

Commit

Permalink
fix(changelog): stage changelog file if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
zbindenren committed Jan 4, 2021
1 parent 11f825a commit 0bdd110
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ func (c Command) runRelease(dst io.Writer, l *flash.Logger, cfg config.Changelog
return err
}

if !g.IsStaged(*c.file) {
l.Debug("staging changelog", "file", *c.file)

if err := g.StageFile(*c.file); err != nil {
return err
}
}

l.Debug("committing changes")

if err := g.CommitFile(*c.file, fmt.Sprintf("chore: update changelog with %s release", version.String())); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ func (c Command) HasRemotes() bool {
return err == nil
}

// IsStaged checks if a path is staged in repository.
func (c Command) IsStaged(path string) bool {
_, err := c.Run("ls-files", "--error-unmatch", path)
return err == nil
}

// RevList runs git rev-list start..end
func (c Command) RevList(start, end string) ([]string, error) {
arg := end
Expand Down

0 comments on commit 0bdd110

Please sign in to comment.