-
Notifications
You must be signed in to change notification settings - Fork 136
/
repo_pull.go
41 lines (35 loc) · 1.26 KB
/
repo_pull.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2015 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package git
import (
"strings"
"time"
)
// MergeBaseOptions contains optional arguments for getting merge base.
// // Docs: https://git-scm.com/docs/git-merge-base
type MergeBaseOptions struct {
// The timeout duration before giving up for each shell command execution.
// The default timeout duration will be used when not supplied.
Timeout time.Duration
}
// RepoMergeBase returns merge base between base and head revisions of the repository
// in given path.
func RepoMergeBase(repoPath, base, head string, opts ...MergeBaseOptions) (string, error) {
var opt MergeBaseOptions
if len(opts) > 0 {
opt = opts[0]
}
stdout, err := NewCommand("merge-base", base, head).RunInDirWithTimeout(opt.Timeout, repoPath)
if err != nil {
if strings.Contains(err.Error(), "exit status 1") {
return "", ErrNoMergeBase
}
return "", err
}
return strings.TrimSpace(string(stdout)), nil
}
// MergeBase returns merge base between base and head revisions of the repository.
func (r *Repository) MergeBase(base, head string, opts ...MergeBaseOptions) (string, error) {
return RepoMergeBase(r.path, base, head, opts...)
}