aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plumbing/object/file.go2
-rw-r--r--plumbing/object/file_test.go26
-rw-r--r--plumbing/object/tree.go5
-rw-r--r--plumbing/object/tree_test.go38
4 files changed, 65 insertions, 6 deletions
diff --git a/plumbing/object/file.go b/plumbing/object/file.go
index 35e7f24..4866777 100644
--- a/plumbing/object/file.go
+++ b/plumbing/object/file.go
@@ -81,7 +81,7 @@ func (iter *FileIter) Next() (*File, error) {
return nil, err
}
- if entry.Mode.IsDir() {
+ if entry.Mode.IsDir() || entry.Mode == SubmoduleMode {
continue
}
diff --git a/plumbing/object/file_test.go b/plumbing/object/file_test.go
index 4c8bbb6..426fa8f 100644
--- a/plumbing/object/file_test.go
+++ b/plumbing/object/file_test.go
@@ -247,3 +247,29 @@ func (s *FileSuite) TestFileIter(c *C) {
c.Assert(count, Equals, 1)
}
+
+func (s *FileSuite) TestFileIterSubmodule(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",
+ }
+
+ var count int
+ i := tree.Files()
+ i.ForEach(func(f *File) error {
+ c.Assert(f.Name, Equals, expected[count])
+ count++
+ return nil
+ })
+
+ c.Assert(count, Equals, 1)
+}
diff --git a/plumbing/object/tree.go b/plumbing/object/tree.go
index 3bcd80a..27d8578 100644
--- a/plumbing/object/tree.go
+++ b/plumbing/object/tree.go
@@ -375,11 +375,6 @@ func (w *TreeWalker) Next() (name string, entry TreeEntry, err error) {
return
}
- if entry.Mode == SubmoduleMode {
- err = nil
- continue
- }
-
if entry.Mode.IsDir() {
obj, err = GetTree(w.s, entry.Hash)
}
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
}{{