@@ -277,19 +277,23 @@ def commit_count(self, start='master', path=''):
277277 """
278278 return Commit .count (self , start , path )
279279
280- def commit (self , id , path = '' ):
280+ def commit (self , id = None , path = '' ):
281281 """
282282 The Commit object for the specified id
283283
284284 ``id``
285- is the SHA1 identifier of the commit
285+ is the SHA1 identifier of the commit or a ref or a ref name
286+ if None, it defaults to the active branch
287+
286288
287289 ``path``
288290 is an optional path, if set the returned commit must contain the path.
289291
290292 Returns
291293 ``git.Commit``
292294 """
295+ if id is None :
296+ id = self .active_branch
293297 options = {'max_count' : 1 }
294298
295299 commits = Commit .find_all (self , id , path , ** options )
@@ -311,22 +315,34 @@ def commit_deltas_from(self, other_repo, ref='master', other_ref='master'):
311315 diff_refs = list (set (other_repo_refs ) - set (repo_refs ))
312316 return map (lambda ref : Commit .find_all (other_repo , ref , max_count = 1 )[0 ], diff_refs )
313317
314- def tree (self , treeish = 'master' ):
318+ def tree (self , treeish = None ):
315319 """
316320 The Tree object for the given treeish reference
317321
318322 ``treeish``
319- is the reference (default 'master')
323+ is a Ref instance defaulting to the active_branch if None.
320324
321325 Examples::
322326
323- repo.tree('master')
324-
327+ repo.tree(repo.heads[0])
325328
326329 Returns
327330 ``git.Tree``
331+
332+ NOTE
333+ A ref is requried here to assure you point to a commit or tag. Otherwise
334+ it is not garantueed that you point to the root-level tree.
335+
336+ If you need a non-root level tree, find it by iterating the root tree.
328337 """
329- return Tree (self , id = treeish )
338+ if treeish is None :
339+ treeish = self .active_branch
340+ if not isinstance (treeish , Ref ):
341+ raise ValueError ( "Treeish reference required, got %r" % treeish )
342+
343+ # we should also check whether the ref has a valid commit ... but lets n
344+ # not be over-critical
345+ return Tree (self , treeish )
330346
331347 def blob (self , id ):
332348 """
@@ -588,13 +604,9 @@ def active_branch(self):
588604 The name of the currently active branch.
589605
590606 Returns
591- str ( the branch name)
607+ Head to the active branch
592608 """
593- branch = self .git .symbolic_ref ('HEAD' ).strip ()
594- if branch .startswith ('refs/heads/' ):
595- branch = branch [len ('refs/heads/' ):]
596-
597- return branch
609+ return Head ( self , self .git .symbolic_ref ('HEAD' ).strip () )
598610
599611 def __repr__ (self ):
600612 return '<git.Repo "%s">' % self .path
0 commit comments