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

Commit

Permalink
Merge pull request #1095 from niukuo/panic_find_entry
Browse files Browse the repository at this point in the history
fix panic in object.Tree.FindEntry
  • Loading branch information
mcuadros authored Apr 2, 2019
2 parents 6e931e4 + 579399e commit 923642a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plumbing/object/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (t *Tree) FindEntry(path string) (*TreeEntry, error) {
pathCurrent := ""

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

tree, ok := t.t[path]
Expand Down
3 changes: 3 additions & 0 deletions plumbing/object/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func (s *TreeSuite) TestFindEntryNotFound(c *C) {
e, err := s.Tree.FindEntry("not-found")
c.Assert(e, IsNil)
c.Assert(err, Equals, ErrEntryNotFound)
e, err = s.Tree.FindEntry("not-found/not-found/not-found")
c.Assert(e, IsNil)
c.Assert(err, Equals, ErrDirectoryNotFound)
}

// Overrides returned plumbing.EncodedObject for given hash.
Expand Down

0 comments on commit 923642a

Please sign in to comment.