@@ -277,19 +277,23 @@ def commit_count(self, start='master', path=''):
277
277
"""
278
278
return Commit .count (self , start , path )
279
279
280
- def commit (self , id , path = '' ):
280
+ def commit (self , id = None , path = '' ):
281
281
"""
282
282
The Commit object for the specified id
283
283
284
284
``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
+
286
288
287
289
``path``
288
290
is an optional path, if set the returned commit must contain the path.
289
291
290
292
Returns
291
293
``git.Commit``
292
294
"""
295
+ if id is None :
296
+ id = self .active_branch
293
297
options = {'max_count' : 1 }
294
298
295
299
commits = Commit .find_all (self , id , path , ** options )
@@ -311,22 +315,34 @@ def commit_deltas_from(self, other_repo, ref='master', other_ref='master'):
311
315
diff_refs = list (set (other_repo_refs ) - set (repo_refs ))
312
316
return map (lambda ref : Commit .find_all (other_repo , ref , max_count = 1 )[0 ], diff_refs )
313
317
314
- def tree (self , treeish = 'master' ):
318
+ def tree (self , treeish = None ):
315
319
"""
316
320
The Tree object for the given treeish reference
317
321
318
322
``treeish``
319
- is the reference (default 'master')
323
+ is a Ref instance defaulting to the active_branch if None.
320
324
321
325
Examples::
322
326
323
- repo.tree('master')
324
-
327
+ repo.tree(repo.heads[0])
325
328
326
329
Returns
327
330
``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.
328
337
"""
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 )
330
346
331
347
def blob (self , id ):
332
348
"""
@@ -588,13 +604,9 @@ def active_branch(self):
588
604
The name of the currently active branch.
589
605
590
606
Returns
591
- str ( the branch name)
607
+ Head to the active branch
592
608
"""
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 () )
598
610
599
611
def __repr__ (self ):
600
612
return '<git.Repo "%s">' % self .path
0 commit comments