diff options
Diffstat (limited to 'plumbing/object/tree_test.go')
-rw-r--r-- | plumbing/object/tree_test.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/plumbing/object/tree_test.go b/plumbing/object/tree_test.go index 319caae..474bb6a 100644 --- a/plumbing/object/tree_test.go +++ b/plumbing/object/tree_test.go @@ -1,9 +1,11 @@ package object import ( + "context" "errors" "io" + fixtures "github.com/go-git/go-git-fixtures/v4" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/cache" "github.com/go-git/go-git/v5/plumbing/filemode" @@ -11,7 +13,6 @@ import ( "github.com/go-git/go-git/v5/storage/filesystem" . "gopkg.in/check.v1" - "github.com/go-git/go-git-fixtures/v4" ) type TreeSuite struct { @@ -240,6 +241,33 @@ func (s *TreeSuite) TestTreeDecodeEncodeIdempotent(c *C) { } } +func (s *TreeSuite) TestTreeDiff(c *C) { + f := fixtures.ByURL("https://github.com/src-d/go-git.git").One() + storer := filesystem.NewStorage(f.DotGit(), cache.NewObjectLRUDefault()) + commit, err := GetCommit(storer, plumbing.NewHash("89f8bda31d29767a6d6ba8f9d0dfb941d598e843")) + c.Assert(err, IsNil) + + tree, err := commit.Tree() + c.Assert(err, IsNil) + + parentCommit, err := commit.Parent(0) + c.Assert(err, IsNil) + + parentTree, err := parentCommit.Tree() + c.Assert(err, IsNil) + + ch, err := parentTree.Diff(tree) + c.Assert(err, IsNil) + + c.Assert(ch, HasLen, 3) + c.Assert(ch[0].From.Name, Equals, "examples/object_storage/main.go") + c.Assert(ch[0].To.Name, Equals, "examples/storage/main.go") + + ch, err = parentTree.DiffContext(context.Background(), tree) + c.Assert(err, IsNil) + c.Assert(ch, HasLen, 3) +} + func (s *TreeSuite) TestTreeIter(c *C) { encIter, err := s.Storer.IterEncodedObjects(plumbing.TreeObject) c.Assert(err, IsNil) |