git-module

git clone git://git.lin.moe/fork/git-module.git

 1package git
 2
 3import (
 4	"context"
 5	"strings"
 6)
 7
 8// MergeBaseOptions contains optional arguments for getting merge base.
 9//
10// Docs: https://git-scm.com/docs/git-merge-base
11type MergeBaseOptions struct {
12	CommandOptions
13}
14
15// MergeBase returns merge base between base and head revisions of the
16// repository.
17func (r *Repository) MergeBase(ctx context.Context, base, head string, opts ...MergeBaseOptions) (string, error) {
18	var opt MergeBaseOptions
19	if len(opts) > 0 {
20		opt = opts[0]
21	}
22
23	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 "", ErrNoMergeBase
28		}
29		return "", err
30	}
31	return strings.TrimSpace(string(stdout)), nil
32}