summaryrefslogtreecommitdiff
path: root/git_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'git_test.go')
-rw-r--r--git_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/git_test.go b/git_test.go
new file mode 100644
index 0000000..52aea1d
--- /dev/null
+++ b/git_test.go
@@ -0,0 +1,47 @@
+package git
+
+import (
+ "testing"
+ "io/ioutil"
+ "time"
+)
+
+func createTestRepo(t *testing.T) *Repository {
+ // figure out where we can create the test repo
+ path, err := ioutil.TempDir("", "git2go")
+ checkFatal(t, err)
+ repo, err := InitRepository(path, false)
+ checkFatal(t, err)
+
+ tmpfile := "README"
+ err = ioutil.WriteFile(path + "/" + tmpfile, []byte("foo\n"), 0644)
+ checkFatal(t, err)
+
+ return repo
+}
+
+func seedTestRepo(t *testing.T, repo *Repository) (*Oid, *Oid) {
+ loc, err := time.LoadLocation("Europe/Berlin")
+ checkFatal(t, err)
+ sig := &Signature{
+ Name: "Rand Om Hacker",
+ Email: "[email protected]",
+ When: time.Date(2013, 03, 06, 14, 30, 0, 0, loc),
+ }
+
+ idx, err := repo.Index()
+ checkFatal(t, err)
+ err = idx.AddByPath("README")
+ checkFatal(t, err)
+ treeId, err := idx.WriteTree()
+ checkFatal(t, err)
+
+ message := "This is a commit\n"
+ tree, err := repo.LookupTree(treeId)
+ checkFatal(t, err)
+ commitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree)
+ checkFatal(t, err)
+
+ return commitId, treeId
+}
+