|
1 | | -var git = require( '../' ); |
2 | | - |
3 | | -git.repo( '../.git', function( err, repo ) { |
4 | | - if( err ) { throw new Error( err ); } |
5 | | - |
6 | | - repo.commit( '59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function( err, commit ) { |
7 | | - if( err ) { throw new Error( err ); } |
8 | | - |
9 | | - var history = commit.history(); |
10 | | - history.on( 'commit', function() { |
11 | | - // console.log(arguments); |
12 | | - }); |
13 | | - |
14 | | - history.on( 'end', function( commits ) { |
15 | | - // Read first commit tree |
16 | | - var tree = commits[0].tree(); |
17 | | - |
18 | | - // Synchronous |
19 | | - tree.walk().on('entry', function( i, entry ) { |
20 | | - console.log( entry.content ); |
21 | | - return false; |
22 | | - }); |
23 | | - |
24 | | - // Asynchronous - not yet implemented |
25 | | - //tree.walk().on( 'entry', function( err, i, entry ) { |
26 | | - // console.log( entry ); |
27 | | - //}); |
| 1 | +// Load in the module. |
| 2 | +var git = require('nodegit'), |
| 3 | + async = require('async'); |
| 4 | + |
| 5 | +// Open the repository in the current directory. |
| 6 | +git.repo('.git', function(error, repository) { |
| 7 | + if (error) { |
| 8 | + throw error; |
| 9 | + } |
| 10 | + |
| 11 | + // Use the master branch. |
| 12 | + repository.branch('master', function(error, branch) { |
| 13 | + if (error) { |
| 14 | + throw error; |
| 15 | + } |
| 16 | + |
| 17 | + // Iterate over the revision history. |
| 18 | + branch.history().on('commit', function(error, commit) { |
| 19 | + |
| 20 | + // Print out `git log` emulation. |
| 21 | + async.series([ |
| 22 | + function(callback) { |
| 23 | + commit.sha(callback); |
| 24 | + }, |
| 25 | + function(callback) { |
| 26 | + commit.time(callback); |
| 27 | + }, |
| 28 | + function(callback) { |
| 29 | + commit.author(function(error, author) { |
| 30 | + author.name(callback); |
| 31 | + }); |
| 32 | + }, |
| 33 | + function(callback) { |
| 34 | + commit.author(function(error, author) { |
| 35 | + author.email(callback); |
| 36 | + }); |
| 37 | + }, |
| 38 | + function(callback) { |
| 39 | + commit.message(callback); |
| 40 | + } |
| 41 | + ], function printCommit(error, results) { |
| 42 | + console.log('SHA ' + results[0]); |
| 43 | + console.log(new Date(results[1] * 1000)); |
| 44 | + console.log(results[2] + ' <' + results[3] + '>'); |
| 45 | + console.log(results[4]); |
| 46 | + }); |
28 | 47 | }); |
29 | 48 | }); |
30 | | - |
31 | | - //repo.branch( 'master', function( err, branch ) { |
32 | | - // if( err ) { throw new Error( err ); } |
33 | | - |
34 | | - // var history = branch.history(); |
35 | | - // console.log( history ); |
36 | | - |
37 | | - // //branch.tree().each( function( i, entry ) { |
38 | | - // // console.log( entry.name ); |
39 | | - // // console.log( entry.contents ); |
40 | | - |
41 | | - // //}); |
42 | | - //}); |
43 | 49 | }); |
0 commit comments