You've already forked go-semantic-release
fix(gitutil): don't crash if no last version was found
This commit is contained in:
committed by
Felix Wiedmann
parent
5225b12c00
commit
f79466b238
@@ -123,10 +123,19 @@ func (g *GitUtil) GetLastVersion() (*semver.Version, *plumbing.Reference, error)
|
|||||||
// GetCommits from git hash to HEAD
|
// GetCommits from git hash to HEAD
|
||||||
func (g *GitUtil) GetCommits(lastTagHash *plumbing.Reference) ([]shared.Commit, error) {
|
func (g *GitUtil) GetCommits(lastTagHash *plumbing.Reference) ([]shared.Commit, error) {
|
||||||
|
|
||||||
excludeIter, err := g.Repository.Log(&git.LogOptions{From: lastTagHash.Hash()})
|
ref, err := g.Repository.Head()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
logOptions := &git.LogOptions{From: ref.Hash()}
|
||||||
|
|
||||||
|
if lastTagHash != nil {
|
||||||
|
logOptions = &git.LogOptions{From: lastTagHash.Hash()}
|
||||||
|
}
|
||||||
|
excludeIter, err := g.Repository.Log(logOptions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not get git log %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
seen := map[plumbing.Hash]struct{}{}
|
seen := map[plumbing.Hash]struct{}{}
|
||||||
err = excludeIter.ForEach(func(c *object.Commit) error {
|
err = excludeIter.ForEach(func(c *object.Commit) error {
|
||||||
@@ -142,10 +151,6 @@ func (g *GitUtil) GetCommits(lastTagHash *plumbing.Reference) ([]shared.Commit,
|
|||||||
return !ok && len(commit.ParentHashes) < 2
|
return !ok && len(commit.ParentHashes) < 2
|
||||||
}
|
}
|
||||||
|
|
||||||
ref, err := g.Repository.Head()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
startCommit, err := g.Repository.CommitObject(ref.Hash())
|
startCommit, err := g.Repository.CommitObject(ref.Hash())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package semanticrelease
|
package semanticrelease
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/integrations"
|
"github.com/Nightapes/go-semantic-release/internal/integrations"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"time"
|
"time"
|
||||||
@@ -102,7 +103,7 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
|
|||||||
|
|
||||||
commits, err := s.gitUtil.GetCommits(lastVersionHash)
|
commits, err := s.gitUtil.GetCommits(lastVersionHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("could not get commits %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Found %d commits till last release", len(commits))
|
log.Debugf("Found %d commits till last release", len(commits))
|
||||||
@@ -131,12 +132,15 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
|
|||||||
Version: &newVersion,
|
Version: &newVersion,
|
||||||
},
|
},
|
||||||
Last: shared.ReleaseVersionEntry{
|
Last: shared.ReleaseVersionEntry{
|
||||||
Commit: lastVersionHash.Hash().String(),
|
Commit: "",
|
||||||
Version: lastVersion,
|
Version: lastVersion,
|
||||||
},
|
},
|
||||||
Branch: provider.Branch,
|
Branch: provider.Branch,
|
||||||
Commits: analyzedCommits,
|
Commits: analyzedCommits,
|
||||||
}
|
}
|
||||||
|
if lastVersionHash != nil {
|
||||||
|
releaseVersion.Last.Commit = lastVersionHash.Hash().String()
|
||||||
|
}
|
||||||
|
|
||||||
if firstRelease {
|
if firstRelease {
|
||||||
releaseVersion.Last.Version, _ = semver.NewVersion("0.0.0")
|
releaseVersion.Last.Version, _ = semver.NewVersion("0.0.0")
|
||||||
|
|||||||
Reference in New Issue
Block a user