forked from GitLab-Red-Team/gitrob
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.go
More file actions
39 lines (34 loc) · 926 Bytes
/
Copy pathgit.go
File metadata and controls
39 lines (34 loc) · 926 Bytes
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
package github
import (
"fmt"
"gopkg.in/src-d/go-git.v4/storage/memory"
"io/ioutil"
"gitrob/common"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
)
func CloneRepository(cloneConfig *common.CloneConfiguration) (*git.Repository, string, error) {
cloneOptions := &git.CloneOptions{
URL: *cloneConfig.URL,
Depth: *cloneConfig.Depth,
ReferenceName: plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", *cloneConfig.Branch)),
SingleBranch: true,
Tags: git.NoTags,
}
var repository *git.Repository
var err error
var dir string
if !*cloneConfig.InMemClone {
dir, err = ioutil.TempDir("", "gitrob")
if err != nil {
return nil, "", err
}
repository, err = git.PlainClone(dir, false, cloneOptions)
} else {
repository, err = git.Clone(memory.NewStorage(), nil, cloneOptions)
}
if err != nil {
return nil, dir, err
}
return repository, dir, nil
}