summaryrefslogtreecommitdiff
path: root/push_test.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2014-03-18 05:21:35 +0100
committerCarlos Martín Nieto <[email protected]>2014-03-18 05:21:35 +0100
commit5f35f137372917332cd329cf723a9d005e13d582 (patch)
tree5fb0ce34a23761b99d4873f6d241545a4b84e32d /push_test.go
parentdbdbb4b0d124ef1f00cb67f84cef2ea35278aeef (diff)
parent51aa76d6f7170bba60ab2252b74a3cab0276996f (diff)
Merge pull request #61 from jezell/remotes-wip
Cleaned up remotes / clone / add push / fetch
Diffstat (limited to 'push_test.go')
-rw-r--r--push_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/push_test.go b/push_test.go
new file mode 100644
index 0000000..dfd4af7
--- /dev/null
+++ b/push_test.go
@@ -0,0 +1,56 @@
+package git
+
+import (
+ "log"
+ "testing"
+ "time"
+)
+
+func Test_Push_ToRemote(t *testing.T) {
+ repo := createBareTestRepo(t)
+ repo2 := createTestRepo(t)
+
+ 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()
+}