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 #885 from jsravn/findentry-return-file-not-found
Browse files Browse the repository at this point in the history
plumbing: object, return ErrFileNotFound in FindEntry. Fixes #883
  • Loading branch information
mcuadros committed Jul 16, 2018
2 parents 400b083 + b304997 commit 5b1d537
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions plumbing/object/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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 @@ -167,16 +168,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

0 comments on commit 5b1d537

Please sign in to comment.