Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 923642a

Browse files
authored
Merge pull request #1095 from niukuo/panic_find_entry
fix panic in object.Tree.FindEntry
2 parents 6e931e4 + 579399e commit 923642a

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Diff for: plumbing/object/tree.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (t *Tree) FindEntry(path string) (*TreeEntry, error) {
135135
pathCurrent := ""
136136

137137
// search for the longest path in the tree path cache
138-
for i := len(pathParts); i > 1; i-- {
138+
for i := len(pathParts) - 1; i > 1; i-- {
139139
path := filepath.Join(pathParts[:i]...)
140140

141141
tree, ok := t.t[path]

Diff for: plumbing/object/tree_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ func (s *TreeSuite) TestFindEntryNotFound(c *C) {
125125
e, err := s.Tree.FindEntry("not-found")
126126
c.Assert(e, IsNil)
127127
c.Assert(err, Equals, ErrEntryNotFound)
128+
e, err = s.Tree.FindEntry("not-found/not-found/not-found")
129+
c.Assert(e, IsNil)
130+
c.Assert(err, Equals, ErrDirectoryNotFound)
128131
}
129132

130133
// Overrides returned plumbing.EncodedObject for given hash.

0 commit comments

Comments
 (0)