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

adds Tree method to Tree #224

Merged
merged 4 commits into from
Jan 26, 2017
Merged

adds Tree method to Tree #224

merged 4 commits into from
Jan 26, 2017

Conversation

alcortesm
Copy link
Contributor

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.

@codecov-io
Copy link

codecov-io commented Jan 25, 2017

Current coverage is 76.45% (diff: 90.90%)

Merging #224 into master will decrease coverage by 0.51%

@@             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   

Powered by Codecov. Last update 97c0273...654913c

@@ -48,6 +48,22 @@ func (s *TreeSuite) TestType(c *C) {
c.Assert(s.Tree.Type(), Equals, plumbing.TreeObject)
}

func (s *TreeSuite) TestTree(c *C) {
Copy link
Collaborator

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?

Copy link
Contributor Author

@alcortesm alcortesm Jan 26, 2017

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
Copy link
Collaborator

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 {
Copy link
Collaborator

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).

@alcortesm alcortesm merged commit 002d85c into src-d:master Jan 26, 2017
@alcortesm alcortesm deleted the improvement-tree-can-return-directories branch January 26, 2017 13:21
mcuadros pushed a commit that referenced this pull request Jan 31, 2017
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.
gsalingu-ovhus pushed a commit to gsalingu-ovhus/go-git that referenced this pull request Mar 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants