1package git23import (4 "context"5 "strings"6)78// MergeBaseOptions contains optional arguments for getting merge base.9//10// Docs: https://git-scm.com/docs/git-merge-base11type MergeBaseOptions struct {12 CommandOptions13}1415// MergeBase returns merge base between base and head revisions of the16// repository.17func (r *Repository) MergeBase(ctx context.Context, base, head string, opts ...MergeBaseOptions) (string, error) {18 var opt MergeBaseOptions19 if len(opts) > 0 {20 opt = opts[0]21 }2223 args := []string{"merge-base", "--end-of-options", base, head}24 stdout, err := exec(ctx, r.path, args, opt.Envs)25 if err != nil {26 if isExitStatus(err, 1) {27 return "", ErrNoMergeBase28 }29 return "", err30 }31 return strings.TrimSpace(string(stdout)), nil32}