Skip to content

Commit

Permalink
plumbing: object, return ErrFileNotFound in FindEntry. Fixes src-d#883
Browse files Browse the repository at this point in the history
FindEntry will return ErrDirNotFound if the directory doesn't exist. But
it doesn't return the corresponding error if the file itself is missing.
This adds the logic to return ErrFileNotFound, so users can
programmatically check for this condition.

Signed-off-by: James Ravn <james@r-vn.org>
  • Loading branch information
jsravn committed Jul 5, 2018
1 parent fcfd239 commit c75c171
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plumbing/object/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ func (t *Tree) FindEntry(path string) (*TreeEntry, error) {
t.t[pathCurrent] = tree
}

return tree.entry(pathParts[0])
entry, err := tree.entry(pathParts[0])
if err != nil {
return nil, ErrFileNotFound
}
return entry, nil
}

func (t *Tree) dir(baseName string) (*Tree, error) {
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) TestFindEntryFileNotFound(c *C) {
e, err := s.Tree.FindEntry("not-found")
c.Assert(e, IsNil)
c.Assert(err, Equals, ErrFileNotFound)
}

// 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 c75c171

Please sign in to comment.