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

Commit c75c171

Browse files
committed
plumbing: object, return ErrFileNotFound in FindEntry. Fixes #883
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 <[email protected]>
1 parent fcfd239 commit c75c171

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

plumbing/object/tree.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ func (t *Tree) FindEntry(path string) (*TreeEntry, error) {
146146
t.t[pathCurrent] = tree
147147
}
148148

149-
return tree.entry(pathParts[0])
149+
entry, err := tree.entry(pathParts[0])
150+
if err != nil {
151+
return nil, ErrFileNotFound
152+
}
153+
return entry, nil
150154
}
151155

152156
func (t *Tree) dir(baseName string) (*Tree, error) {

plumbing/object/tree_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ func (s *TreeSuite) TestFindEntry(c *C) {
114114
c.Assert(e.Name, Equals, "foo.go")
115115
}
116116

117+
func (s *TreeSuite) TestFindEntryFileNotFound(c *C) {
118+
e, err := s.Tree.FindEntry("not-found")
119+
c.Assert(e, IsNil)
120+
c.Assert(err, Equals, ErrFileNotFound)
121+
}
122+
117123
// Overrides returned plumbing.EncodedObject for given hash.
118124
// Otherwise, delegates to actual storer to get real object
119125
type fakeStorer struct {

0 commit comments

Comments
 (0)