From 74e895b5ad6f956774d7b3db25e9b7ddf115eb4a Mon Sep 17 00:00:00 2001 From: Nightapes Date: Tue, 8 Oct 2019 20:46:57 +0200 Subject: [PATCH] fix(commits): don't break if commit is found and error happens on older commits and add better error message when git clone --depth is used --- go.mod | 1 + internal/gitutil/gitutil.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 3274316..9da1042 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/google/go-cmp v0.3.0 // indirect github.com/google/go-github/v25 v25.1.3 github.com/kevinburke/ssh_config v0.0.0-20190630040420-2e50c441276c // indirect + github.com/pkg/errors v0.8.1 github.com/sirupsen/logrus v1.4.2 github.com/spf13/cobra v0.0.5 github.com/stretchr/testify v1.3.0 diff --git a/internal/gitutil/gitutil.go b/internal/gitutil/gitutil.go index 1ebb33d..ca0c8c9 100644 --- a/internal/gitutil/gitutil.go +++ b/internal/gitutil/gitutil.go @@ -5,12 +5,15 @@ import ( "fmt" "sort" + "github.com/pkg/errors" + "github.com/Masterminds/semver" "github.com/Nightapes/go-semantic-release/internal/shared" log "github.com/sirupsen/logrus" "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/object" + "gopkg.in/src-d/go-git.v4/plumbing/storer" ) // GitUtil struct @@ -139,7 +142,7 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) { if c.Hash.String() == lastTagHash { log.Debugf("Found commit with hash %s, will stop here", c.Hash.String()) foundEnd = true - + return storer.ErrStop } if !foundEnd { log.Tracef("Found commit with hash %s", c.Hash.String()) @@ -153,5 +156,9 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) { return nil }) - return commits, err + if err != nil { + return commits, errors.Wrap(err, "Could not read commits, check git clone depth in your ci") + } + + return commits, nil }