@@ -349,12 +349,12 @@ def iter_trees(self, *args, **kwargs):
349349 """
350350 return ( c .tree for c in self .iter_commits (* args , ** kwargs ) )
351351
352- def tree (self , ref = None ):
352+ def tree (self , rev = None ):
353353 """
354- The Tree object for the given treeish reference
354+ The Tree object for the given treeish revision
355355
356- ``ref ``
357- is a Ref instance defaulting to the active_branch if None.
356+ ``rev ``
357+ is a revision pointing to a Treeish ( being a commit or tree )
358358
359359 Examples::
360360
@@ -364,32 +364,19 @@ def tree(self, ref=None):
364364 ``git.Tree``
365365
366366 NOTE
367- A ref is requried here to assure you point to a commit or tag. Otherwise
368- it is not garantueed that you point to the root-level tree.
369-
370367 If you need a non-root level tree, find it by iterating the root tree. Otherwise
371368 it cannot know about its path relative to the repository root and subsequent
372369 operations might have unexpected results.
373370 """
374- if ref is None :
375- ref = self .active_branch
376- if not isinstance (ref , Reference ):
377- raise ValueError ( "Reference required, got %r" % ref )
378-
379-
380- # As we are directly reading object information, we must make sure
381- # we truly point to a tree object. We resolve the ref to a sha in all cases
382- # to assure the returned tree can be compared properly. Except for
383- # heads, ids should always be hexshas
384- hexsha , typename , size = self .git .get_object_header ( ref )
385- if typename != "tree" :
386- # will raise if this is not a valid tree
387- hexsha , typename , size = self .git .get_object_header ( str (ref )+ '^{tree}' )
388- # END tree handling
389- ref = hexsha
390-
391- # the root has an empty relative path and the default mode
392- return Tree (self , ref , 0 , '' )
371+ if rev is None :
372+ rev = self .active_branch
373+
374+ c = Object .new (self , rev )
375+ if c .type == "commit" :
376+ return c .tree
377+ elif c .type == "tree" :
378+ return c
379+ raise ValueError ( "Revision %s did not point to a treeish, but to %s" % (rev , c ))
393380
394381 def iter_commits (self , rev = None , paths = '' , ** kwargs ):
395382 """
0 commit comments