Skip to content

Commit

Permalink
style(internal) clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightapes authored and fwiedmann committed Apr 28, 2021
1 parent 2cd2477 commit 5225b12
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions internal/gitutil/gitutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,12 @@ func (g *GitUtil) GetLastVersion() (*semver.Version, *plumbing.Reference, error)
// GetCommits from git hash to HEAD
func (g *GitUtil) GetCommits(lastTagHash *plumbing.Reference) ([]shared.Commit, error) {

ref, err := g.Repository.Head()
if err != nil {
return nil, err
}

excludeIter, err := g.Repository.Log(&git.LogOptions{From: lastTagHash.Hash()})
if err != nil {
return nil, err
}

startCommit, err := g.Repository.CommitObject(ref.Hash())
if err != nil {
return nil, err
}
seen := map[plumbing.Hash]struct{}{}

err = excludeIter.ForEach(func(c *object.Commit) error {
seen[c.Hash] = struct{}{}
return nil
Expand All @@ -152,6 +142,14 @@ func (g *GitUtil) GetCommits(lastTagHash *plumbing.Reference) ([]shared.Commit,
return !ok && len(commit.ParentHashes) < 2
}

ref, err := g.Repository.Head()
if err != nil {
return nil, err
}
startCommit, err := g.Repository.CommitObject(ref.Hash())
if err != nil {
return nil, err
}
cIter := object.NewFilterCommitIter(startCommit, &isValid, nil)

commits := make(map[string]shared.Commit)
Expand All @@ -165,7 +163,6 @@ func (g *GitUtil) GetCommits(lastTagHash *plumbing.Reference) ([]shared.Commit,
}
return nil
})

if err != nil {
return nil, errors.Wrap(err, "Could not read commits, check git clone depth in your ci")
}
Expand Down

0 comments on commit 5225b12

Please sign in to comment.