Merge pull request #11 from alcortesm/ignore-submodules

Ignore submodule dirs (empty directories without associated object)
diff --git a/file_test.go b/file_test.go
index 8c22bb3..b5bdeac 100644
--- a/file_test.go
+++ b/file_test.go
@@ -22,6 +22,7 @@
 		packfile string
 	}{
 		{"https://github.com/tyba/git-fixture.git", "formats/packfile/fixtures/git-fixture.ofs-delta"},
+		{"https://github.com/cpcs499/Final_Pres_P", "formats/packfile/fixtures/Final_Pres_P.ofs-delta"},
 	}
 	s.repos = make(map[string]*Repository, 0)
 	for _, fixRepo := range fixtureRepos {
@@ -131,3 +132,31 @@
 			"subtest %d: commit=%s, path=%s", i, t.commit, t.path))
 	}
 }
+
+var ignoreEmptyDirEntriesTests = []struct {
+	repo   string // the repo name as in localRepos
+	commit string // the commit to search for the file
+}{
+	{
+		"https://github.com/cpcs499/Final_Pres_P",
+		"70bade703ce556c2c7391a8065c45c943e8b6bc3",
+		// the Final dir in this commit is empty
+	},
+}
+
+// It is difficult to assert that we are ignoring an (empty) dir as even
+// if we don't, no files will be found in it.
+//
+// At least this test has a high chance of panicking if
+// we don't ignore empty dirs.
+func (s *SuiteFile) TestIgnoreEmptyDirEntries(c *C) {
+	for i, t := range ignoreEmptyDirEntriesTests {
+		commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit))
+		c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit))
+
+		for file := range commit.Tree().Files() {
+			_ = file.Contents()
+			// this would probably panic if we are not ignoring empty dirs
+		}
+	}
+}
diff --git a/tree.go b/tree.go
index 2ca084e..7b988a1 100644
--- a/tree.go
+++ b/tree.go
@@ -39,7 +39,11 @@
 
 func (t *Tree) walkEntries(base string, ch chan *File) {
 	for _, entry := range t.Entries {
-		obj, _ := t.r.Storage.Get(entry.Hash)
+		obj, ok := t.r.Storage.Get(entry.Hash)
+		if !ok {
+			continue // ignore entries without hash (= submodule dirs)
+		}
+
 		if obj.Type() == core.TreeObject {
 			tree := &Tree{r: t.r}
 			tree.Decode(obj)