forked from libgit2/git2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_test.go
57 lines (42 loc) · 1.13 KB
/
push_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
52
53
54
55
56
57
package git
import (
"os"
"testing"
"time"
)
func Test_Push_ToRemote(t *testing.T) {
repo := createBareTestRepo(t)
defer os.RemoveAll(repo.Path())
repo2 := createTestRepo(t)
defer os.RemoveAll(repo2.Workdir())
remote, err := repo2.CreateRemote("test_push", repo.Path())
checkFatal(t, err)
index, err := repo2.Index()
checkFatal(t, err)
index.AddByPath("README")
err = index.Write()
checkFatal(t, err)
newTreeId, err := index.WriteTree()
checkFatal(t, err)
tree, err := repo2.LookupTree(newTreeId)
checkFatal(t, err)
sig := &Signature{Name: "Rand Om Hacker", Email: "[email protected]", When: time.Now()}
// this should cause master branch to be created if it does not already exist
_, err = repo2.CreateCommit("HEAD", sig, sig, "message", tree)
checkFatal(t, err)
push, err := remote.NewPush()
checkFatal(t, err)
err = push.AddRefspec("refs/heads/master")
checkFatal(t, err)
err = push.Finish()
checkFatal(t, err)
err = push.StatusForeach(func(ref string, msg string) int {
return 0
})
checkFatal(t, err)
if !push.UnpackOk() {
t.Fatalf("unable to unpack")
}
defer remote.Free()
defer repo.Free()
}