From b18d6490aefe8509791843136530e3426d0c8200 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 13 Feb 2017 00:15:19 +0100 Subject: plumbing/object: allow TreeIter return SubModule entries --- plumbing/object/tree_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'plumbing/object/tree_test.go') diff --git a/plumbing/object/tree_test.go b/plumbing/object/tree_test.go index be721b9..0ddf391 100644 --- a/plumbing/object/tree_test.go +++ b/plumbing/object/tree_test.go @@ -4,7 +4,10 @@ import ( "io" "os" + fixtures "github.com/src-d/go-git-fixtures" + "srcd.works/go-git.v4/plumbing" + "srcd.works/go-git.v4/storage/filesystem" . "gopkg.in/check.v1" "srcd.works/go-git.v4/plumbing/storer" @@ -262,6 +265,41 @@ func (s *TreeSuite) TestTreeWalkerNextNonRecursive(c *C) { c.Assert(count, Equals, 8) } +func (s *TreeSuite) TestTreeWalkerNextSubmodule(c *C) { + st, err := filesystem.NewStorage(fixtures.ByTag("submodule").One().DotGit()) + c.Assert(err, IsNil) + + hash := plumbing.NewHash("a692ec699bff9117c1ed91752afbb7d9d272ebef") + commit, err := GetCommit(st, hash) + c.Assert(err, IsNil) + + tree, err := commit.Tree() + c.Assert(err, IsNil) + + expected := []string{ + ".gitmodules", + "basic", + "itself", + } + + var count int + walker := NewTreeWalker(tree, true) + for { + name, entry, err := walker.Next() + if err == io.EOF { + break + } + + c.Assert(err, IsNil) + c.Assert(entry, NotNil) + c.Assert(name, Equals, expected[count]) + + count++ + } + + c.Assert(count, Equals, 3) +} + var treeWalkerExpects = []struct { Path, Mode, Name, Hash, Tree string }{{ -- cgit