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

plumbing: object, return ErrFileNotFound in FindEntry. Fixes #883 #885

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions plumbing/object/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
ErrMaxTreeDepth = errors.New("maximum tree depth exceeded")
ErrFileNotFound = errors.New("file not found")
ErrDirectoryNotFound = errors.New("directory not found")
ErrEntryNotFound = errors.New("entry not found")
)

// Tree is basically like a directory - it references a bunch of other trees
Expand Down Expand Up @@ -166,16 +167,14 @@ func (t *Tree) dir(baseName string) (*Tree, error) {
return tree, err
}

var errEntryNotFound = errors.New("entry not found")

func (t *Tree) entry(baseName string) (*TreeEntry, error) {
if t.m == nil {
t.buildMap()
}

entry, ok := t.m[baseName]
if !ok {
return nil, errEntryNotFound
return nil, ErrEntryNotFound
}

return entry, nil
Expand Down
6 changes: 6 additions & 0 deletions plumbing/object/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ func (s *TreeSuite) TestFindEntry(c *C) {
c.Assert(e.Name, Equals, "foo.go")
}

func (s *TreeSuite) TestFindEntryNotFound(c *C) {
e, err := s.Tree.FindEntry("not-found")
c.Assert(e, IsNil)
c.Assert(err, Equals, ErrEntryNotFound)
}

// Overrides returned plumbing.EncodedObject for given hash.
// Otherwise, delegates to actual storer to get real object
type fakeStorer struct {
Expand Down