aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/vcs/git.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-04-20 21:14:00 +0200
committerAleksandr Nogikh <wp32pw@gmail.com>2023-04-28 14:53:23 +0200
commit621aee759846fed3c2699ce10a4fe815de97f250 (patch)
tree3eca9e2da7692decf009efb7745c11e728b8729f /pkg/vcs/git.go
parentd92f696afec4905d4fa574398155613187ea8407 (diff)
pkg/vcs: extract merge bases of two commits
Diffstat (limited to 'pkg/vcs/git.go')
-rw-r--r--pkg/vcs/git.go16
1 files changed, 16 insertions, 0 deletions
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
+}