From dee85c6877deafc240dc8ae7f8c59c73fb8df478 Mon Sep 17 00:00:00 2001 From: Sebastian Beisch Date: Mon, 9 Nov 2020 14:43:01 +0100 Subject: [PATCH] fix(internal/git): check merge commits and collect parent commits for changelog --- internal/gitutil/gitutil.go | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/internal/gitutil/gitutil.go b/internal/gitutil/gitutil.go index 55ced86..67ec880 100644 --- a/internal/gitutil/gitutil.go +++ b/internal/gitutil/gitutil.go @@ -138,11 +138,13 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) { var foundEnd bool err = cIter.ForEach(func(c *object.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()) commit := shared.Commit{ @@ -151,6 +153,22 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) { Hash: c.Hash.String(), } commits = append(commits, commit) + + if len(c.ParentHashes) == 2 { + parent, err := g.Repository.CommitObject(c.ParentHashes[1]) + if err == nil { + commit := shared.Commit{ + Message: parent.Message, + Author: parent.Committer.Name, + Hash: parent.Hash.String(), + } + commits = append(commits, commit) + log.Tracef("Found parent check for merge commits for hash %s", c.ParentHashes[1].String()) + + commits = append(commits, g.getParents(parent)...) + } + + } } return nil }) @@ -161,3 +179,23 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) { return commits, nil } + +func (g *GitUtil) getParents(current *object.Commit) []shared.Commit { + commits := make([]shared.Commit, 0) + for _, i2 := range current.ParentHashes { + parent, err := g.Repository.CommitObject(i2) + if err != nil { + continue + } + commit := shared.Commit{ + Message: parent.Message, + Author: parent.Committer.Name, + Hash: parent.Hash.String(), + } + commits = append(commits, commit) + if len(parent.ParentHashes) == 1 { + commits = append(commits, g.getParents(parent)...) + } + } + return commits +}