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

Commit b304997

Browse files
committed
plumbing: object, expose ErrEntryNotFound in FindEntry. Fixes #883
FindEntry will return ErrDirNotFound if the directory doesn't exist. But it doesn't return a public error if the entry itself is missing. This exposes the internal error ErrEntryNotFound, so users can programmatically check for this condition. Signed-off-by: James Ravn <[email protected]>
1 parent fcfd239 commit b304997

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

plumbing/object/tree.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
2525
ErrMaxTreeDepth = errors.New("maximum tree depth exceeded")
2626
ErrFileNotFound = errors.New("file not found")
2727
ErrDirectoryNotFound = errors.New("directory not found")
28+
ErrEntryNotFound = errors.New("entry not found")
2829
)
2930

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

169-
var errEntryNotFound = errors.New("entry not found")
170-
171170
func (t *Tree) entry(baseName string) (*TreeEntry, error) {
172171
if t.m == nil {
173172
t.buildMap()
174173
}
175174

176175
entry, ok := t.m[baseName]
177176
if !ok {
178-
return nil, errEntryNotFound
177+
return nil, ErrEntryNotFound
179178
}
180179

181180
return entry, nil

plumbing/object/tree_test.go

Lines changed: 6 additions & 0 deletions
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) TestFindEntryNotFound(c *C) {
118+
e, err := s.Tree.FindEntry("not-found")
119+
c.Assert(e, IsNil)
120+
c.Assert(err, Equals, ErrEntryNotFound)
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)