-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclone_test.go
51 lines (45 loc) · 1.12 KB
/
clone_test.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
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"io/ioutil"
"os"
"testing"
"golang.org/x/crypto/ssh"
"gopkg.in/src-d/go-billy.v4/memfs"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
go_git_ssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
"gopkg.in/src-d/go-git.v4/storage/memory"
)
func TestClone(t *testing.T) {
s := fmt.Sprintf("%s/.ssh/id_rsa", os.Getenv("HOME"))
sshKey, err := ioutil.ReadFile(s)
signer, err := ssh.ParsePrivateKey([]byte(sshKey))
auth := &go_git_ssh.PublicKeys{User: "git", Signer: signer}
r, err := git.Clone(memory.NewStorage(), memfs.New(), &git.CloneOptions{
URL: "[email protected]:binxio/google-pubsub-testbench.git",
Auth: auth,
})
if err != nil {
t.Fatal(err)
}
err = r.Fetch(&git.FetchOptions{
RefSpecs: []config.RefSpec{"refs/*:refs/*", "HEAD:refs/heads/HEAD"},
Auth: auth,
})
if err != nil {
t.Fatal(err)
}
wt, err := r.Worktree()
if err != nil {
t.Fatal(err)
}
err = wt.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewBranchReferenceName("cloud_implementation"),
Force: true,
})
if err != nil {
t.Fatal(err)
}
}