summaryrefslogtreecommitdiff
path: root/push_test.go
diff options
context:
space:
mode:
authorJesse Ezell <[email protected]>2014-03-26 11:18:21 -0700
committerJesse Ezell <[email protected]>2014-03-26 11:18:21 -0700
commit85420f2002ae85b2e86b3c37c04e462c1cef462a (patch)
tree943fd6fef1b14db9bd6818d4b14243e6d3641b1d /push_test.go
parent8ad5cbc53763ca8e89ede40f91edab80c8def1f1 (diff)
parent2811845a1287d949a74b8ed80a5791fd8875002a (diff)
Merge branch 'master' of http://github.com/libgit2/git2go into merge
Diffstat (limited to 'push_test.go')
-rw-r--r--push_test.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/push_test.go b/push_test.go
new file mode 100644
index 0000000..c1e6a22
--- /dev/null
+++ b/push_test.go
@@ -0,0 +1,59 @@
+package git
+
+import (
+ "log"
+ "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 {
+ log.Printf("%s -> %s", ref, msg)
+ return 0
+ })
+ checkFatal(t, err)
+
+ if !push.UnpackOk() {
+ t.Fatalf("unable to unpack")
+ }
+
+ defer remote.Free()
+ defer repo.Free()
+}