aboutsummaryrefslogtreecommitdiffstats
path: root/tree_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'tree_test.go')
-rw-r--r--tree_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/tree_test.go b/tree_test.go
index cf1ebdd..5f285af 100644
--- a/tree_test.go
+++ b/tree_test.go
@@ -2,6 +2,7 @@ package git
import (
"io"
+ "os"
"gopkg.in/src-d/go-git.v4/core"
@@ -1254,6 +1255,28 @@ func (s *SuiteTree) TestTreeDecodeReadBug(c *C) {
c.Assert(EntriesEquals(obtained.Entries, expected.Entries), Equals, true)
}
+func (s *SuiteTree) TestTreeDecodeEncodeIdempotent(c *C) {
+ trees := []*Tree{
+ &Tree{
+ Entries: []TreeEntry{
+ TreeEntry{"foo", os.FileMode(0), core.NewHash("b029517f6300c2da0f4b651b8642506cd6aaf45d")},
+ TreeEntry{"bar", os.FileMode(0), core.NewHash("c029517f6300c2da0f4b651b8642506cd6aaf45d")},
+ TreeEntry{"baz", os.FileMode(0), core.NewHash("d029517f6300c2da0f4b651b8642506cd6aaf45d")},
+ },
+ },
+ }
+ for _, tree := range trees {
+ obj := &core.MemoryObject{}
+ err := tree.Encode(obj)
+ c.Assert(err, IsNil)
+ newTree := &Tree{}
+ err = newTree.Decode(obj)
+ c.Assert(err, IsNil)
+ tree.Hash = obj.Hash()
+ c.Assert(newTree, DeepEquals, tree)
+ }
+}
+
func EntriesEquals(a, b []TreeEntry) bool {
if a == nil && b == nil {
return true