-
Notifications
You must be signed in to change notification settings - Fork 534
adds Tree method to Tree #224
adds Tree method to Tree #224
Conversation
Current coverage is 76.45% (diff: 90.90%)@@ master #224 diff @@
==========================================
Files 98 98
Lines 6360 6370 +10
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 4895 4870 -25
- Misses 930 977 +47
+ Partials 535 523 -12
|
@@ -48,6 +48,22 @@ func (s *TreeSuite) TestType(c *C) { | |||
c.Assert(s.Tree.Type(), Equals, plumbing.TreeObject) | |||
} | |||
|
|||
func (s *TreeSuite) TestTree(c *C) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test for Tree(path) when path points to a Blob instead of a Tree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
Fixed in a new commit.
Also add the equivalent test for File
, for consistency.
@@ -77,7 +77,7 @@ func (t *Tree) File(path string) (*File, error) { | |||
|
|||
blob, err := GetBlob(t.s, e.Hash) | |||
if err != nil { | |||
return nil, err | |||
return nil, ErrFileNotFound |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be errors other than file not found (such as decoding or network errors). So if err == plumbing.ErrObjectNotFound then ErrFileNotFound
, but otherwise just return the error.
@@ -91,7 +91,12 @@ func (t *Tree) Tree(path string) (*Tree, error) { | |||
return nil, ErrDirectoryNotFound | |||
} | |||
|
|||
return GetTree(t.s, e.Hash) | |||
ret, err := GetTree(t.s, e.Hash) | |||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as my previous comment (check the actual error).
This patch adds a new method to the Tree object that allows you to get a child tree from a parent tree by its relative name. Before this patch, this was only possible with files, using the File method. The new Tree method has a similar signature to the old File method for consistency.
This patch adds a new method to the Tree object that allows you to get a child tree from a parent tree by its relative name.
Before this patch, this was only possible with files, using the
File
method.The new
Tree
method has a similar signature to the oldFile
method for consistency.