|
@@ -5,33 +5,34 @@ import (
|
5
|
5
|
"os"
|
6
|
6
|
"strings"
|
7
|
7
|
|
8
|
|
- gogit "gopkg.in/src-d/go-git.v4"
|
|
8
|
+ "config"
|
9
|
9
|
|
10
|
10
|
"golang.org/x/crypto/ssh"
|
|
11
|
+ gogit "gopkg.in/src-d/go-git.v4"
|
11
|
12
|
gitssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
|
12
|
13
|
)
|
13
|
14
|
|
14
|
|
-func Sync(repo string, clonePath string, privateKeyPath string) (r *gogit.Repository, err error) {
|
15
|
|
- auth, err := getAuth(privateKeyPath)
|
|
15
|
+func Sync(cfg config.GitSettings) (r *gogit.Repository, err error) {
|
|
16
|
+ auth, err := getAuth(cfg.User, cfg.PrivateKeyPath)
|
16
|
17
|
if err != nil {
|
17
|
18
|
return
|
18
|
19
|
}
|
19
|
20
|
|
20
|
|
- exists, err := dirExists(clonePath)
|
|
21
|
+ exists, err := dirExists(cfg.ClonePath)
|
21
|
22
|
if err != nil {
|
22
|
23
|
return
|
23
|
24
|
}
|
24
|
25
|
|
25
|
26
|
if exists {
|
26
|
|
- r, err = pull(clonePath, auth)
|
|
27
|
+ r, err = pull(cfg.ClonePath, auth)
|
27
|
28
|
} else {
|
28
|
|
- r, err = clone(repo, clonePath, auth)
|
|
29
|
+ r, err = clone(cfg.URL, cfg.ClonePath, auth)
|
29
|
30
|
}
|
30
|
31
|
|
31
|
32
|
return
|
32
|
33
|
}
|
33
|
34
|
|
34
|
|
-func getAuth(privateKeyPath string) (*gitssh.PublicKeys, error) {
|
|
35
|
+func getAuth(user string, privateKeyPath string) (*gitssh.PublicKeys, error) {
|
35
|
36
|
privateKey, err := ioutil.ReadFile(privateKeyPath)
|
36
|
37
|
if err != nil {
|
37
|
38
|
return nil, err
|
|
@@ -91,8 +92,8 @@ func dirExists(path string) (bool, error) {
|
91
|
92
|
return true, err
|
92
|
93
|
}
|
93
|
94
|
|
94
|
|
-func Push(r *gogit.Repository, keyPath string) error {
|
95
|
|
- auth, err := getAuth(keyPath)
|
|
95
|
+func Push(r *gogit.Repository, cfg config.GitSettings) error {
|
|
96
|
+ auth, err := getAuth(cfg.User, cfg.PrivateKeyPath)
|
96
|
97
|
if err != nil {
|
97
|
98
|
return err
|
98
|
99
|
}
|