From 621aee759846fed3c2699ce10a4fe815de97f250 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 20 Apr 2023 21:14:00 +0200 Subject: pkg/vcs: extract merge bases of two commits --- pkg/vcs/git.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'pkg/vcs/git.go') diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go index ebdfc2ac3..4ed33972c 100644 --- a/pkg/vcs/git.go +++ b/pkg/vcs/git.go @@ -588,3 +588,19 @@ func (git *git) IsRelease(commit string) (bool, error) { func (git *git) Object(name, commit string) ([]byte, error) { return git.git("show", fmt.Sprintf("%s:%s", commit, name)) } + +func (git *git) MergeBases(firstCommit, secondCommit string) ([]*Commit, error) { + output, err := git.git("merge-base", firstCommit, secondCommit) + if err != nil { + return nil, err + } + ret := []*Commit{} + for _, hash := range strings.Fields(string(output)) { + commit, err := git.getCommit(hash) + if err != nil { + return nil, err + } + ret = append(ret, commit) + } + return ret, nil +} -- cgit mrf-deployment