11// Load in the module.
22var git = require ( 'nodegit' ) ,
3- async = require ( 'async' ) ;
3+ async = require ( 'async' ) ;
44
55// Open the repository in the current directory.
66git . repo ( '.git' , function ( error , repository ) {
7- if ( error ) {
8- throw error ;
9- }
7+ if ( error ) throw error ;
108
11- // Use the master branch.
9+ // Use the master branch (a branch is the HEAD commit)
1210 repository . branch ( 'master' , function ( error , branch ) {
13- if ( error ) {
14- throw error ;
15- }
11+ if ( error ) throw error ;
1612
17- // Iterate over the revision history.
18- branch . history ( ) . on ( 'commit' , function ( error , commit ) {
13+ // History returns an event, and begins walking the history
14+ var history = branch . history ( ) ;
1915
16+ // History emits 'commit' event for each commit in the branch's history
17+ history . on ( 'commit' , function ( error , commit ) {
2018 // Print out `git log` emulation.
2119 async . series ( [
2220 function ( callback ) {
2321 commit . sha ( callback ) ;
2422 } ,
2523 function ( callback ) {
26- commit . time ( callback ) ;
24+ commit . date ( callback ) ;
2725 } ,
2826 function ( callback ) {
2927 commit . author ( function ( error , author ) {
@@ -39,8 +37,9 @@ git.repo('.git', function(error, repository) {
3937 commit . message ( callback ) ;
4038 }
4139 ] , function printCommit ( error , results ) {
40+ if ( error ) throw error ;
4241 console . log ( 'SHA ' + results [ 0 ] ) ;
43- console . log ( new Date ( results [ 1 ] * 1000 ) ) ;
42+ console . log ( results [ 1 ] * 1000 ) ;
4443 console . log ( results [ 2 ] + ' <' + results [ 3 ] + '>' ) ;
4544 console . log ( results [ 4 ] ) ;
4645 } ) ;
0 commit comments