diff options
author | Santiago M. Mola <santi@mola.io> | 2016-08-29 22:39:08 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-08-29 22:39:08 +0200 |
commit | 5cf20a4edf7803458a1c2ec94e902369bed76f28 (patch) | |
tree | b6a0276ab12f82383818892064038fb0b79e161b /commit_test.go | |
parent | a97ca42cbce377b5725ecc41e4539fc7e263b90d (diff) | |
download | go-git-5cf20a4edf7803458a1c2ec94e902369bed76f28.tar.gz |
object: Add Encode method to all objects. (#70)
Encode method encodes a typed object (commit, tree,
tag, blob) into raw core.Object representation.
Additionally, Decode does not trim commit message
lines. This is needed for Decode/Encode to be
idempotent.
Diffstat (limited to 'commit_test.go')
-rw-r--r-- | commit_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/commit_test.go b/commit_test.go index 626fdcf..886a61d 100644 --- a/commit_test.go +++ b/commit_test.go @@ -2,6 +2,7 @@ package git import ( "io" + "time" "gopkg.in/src-d/go-git.v4/core" @@ -62,6 +63,42 @@ func (s *SuiteCommit) TestParents(c *C) { c.Assert(output, DeepEquals, expected) } +func (s *SuiteCommit) TestCommitEncodeDecodeIdempotent(c *C) { + ts, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05-07:00") + c.Assert(err, IsNil) + commits := []*Commit{ + &Commit{ + Author: Signature{Name: "Foo", Email: "foo@example.local", When: ts}, + Committer: Signature{Name: "Bar", Email: "bar@example.local", When: ts}, + Message: "Message\n\nFoo\nBar\nWith trailing blank lines\n\n", + tree: core.NewHash("f000000000000000000000000000000000000001"), + parents: []core.Hash{core.NewHash("f000000000000000000000000000000000000002")}, + }, + &Commit{ + Author: Signature{Name: "Foo", Email: "foo@example.local", When: ts}, + Committer: Signature{Name: "Bar", Email: "bar@example.local", When: ts}, + Message: "Message\n\nFoo\nBar\nWith no trailing blank lines", + tree: core.NewHash("0000000000000000000000000000000000000003"), + parents: []core.Hash{ + core.NewHash("f000000000000000000000000000000000000004"), + core.NewHash("f000000000000000000000000000000000000005"), + core.NewHash("f000000000000000000000000000000000000006"), + core.NewHash("f000000000000000000000000000000000000007"), + }, + }, + } + for _, commit := range commits { + obj := &core.MemoryObject{} + err = commit.Encode(obj) + c.Assert(err, IsNil) + newCommit := &Commit{} + err = newCommit.Decode(obj) + c.Assert(err, IsNil) + commit.Hash = obj.Hash() + c.Assert(newCommit, DeepEquals, commit) + } +} + func (s *SuiteCommit) TestFile(c *C) { file, err := s.Commit.File("CHANGELOG") c.Assert(err, IsNil) |