aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2019-04-02 20:31:40 +0200
committerGitHub <noreply@github.com>2019-04-02 20:31:40 +0200
commit923642abf033cd40b5f3aa5205e517d1feb32f4d (patch)
treea53152fc01d41daaaaf88e1a8c9e1baaa157cfc3 /plumbing
parent6e931e4fdefa202c76242109453447182ae16444 (diff)
parent579399e38a80422e47cd21023ee60259be975bf3 (diff)
downloadgo-git-923642abf033cd40b5f3aa5205e517d1feb32f4d.tar.gz
Merge pull request #1095 from niukuo/panic_find_entry
fix panic in object.Tree.FindEntry
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/object/tree.go2
-rw-r--r--plumbing/object/tree_test.go3
2 files changed, 4 insertions, 1 deletions
diff --git a/plumbing/object/tree.go b/plumbing/object/tree.go
index 78d61a1..1f9ea26 100644
--- a/plumbing/object/tree.go
+++ b/plumbing/object/tree.go
@@ -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]
diff --git a/plumbing/object/tree_test.go b/plumbing/object/tree_test.go
index 889c63a..b408595 100644
--- a/plumbing/object/tree_test.go
+++ b/plumbing/object/tree_test.go
@@ -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.