summaryrefslogtreecommitdiff
path: root/repository_test.go
diff options
context:
space:
mode:
authorlhchavez <[email protected]>2020-02-23 13:53:17 +0000
committerlhchavez <[email protected]>2020-02-23 13:53:17 +0000
commitc20008416a64e2ae884a14332b258160a261a5df (patch)
tree58ae95d9f007937876eed1aac89b0518a034e442 /repository_test.go
parent79fe156d307a9c7b294aa92c741dc0c2759a1894 (diff)
parent4bca045e5aa98b0b791fb467705de0692fe3514f (diff)
Merge remote-tracking branch 'upstream/master' into git_index_add_frombuffer
Diffstat (limited to 'repository_test.go')
-rw-r--r--repository_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go
new file mode 100644
index 0000000..1950c69
--- /dev/null
+++ b/repository_test.go
@@ -0,0 +1,42 @@
+package git
+
+import (
+ "testing"
+ "time"
+)
+
+func TestCreateCommitFromIds(t *testing.T) {
+ t.Parallel()
+ repo := createTestRepo(t)
+ defer cleanupTestRepo(t, repo)
+
+ 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)
+ err = idx.Write()
+ checkFatal(t, err)
+ treeId, err := idx.WriteTree()
+ checkFatal(t, err)
+
+ message := "This is a commit\n"
+ tree, err := repo.LookupTree(treeId)
+ checkFatal(t, err)
+ expectedCommitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree)
+ checkFatal(t, err)
+
+ commitId, err := repo.CreateCommitFromIds("", sig, sig, message, treeId)
+ checkFatal(t, err)
+
+ if !expectedCommitId.Equal(commitId) {
+ t.Errorf("mismatched commit ids, expected %v, got %v", expectedCommitId.String(), commitId.String())
+ }
+}