Skip to content

Commit fe54c8f

Browse files
committed
Updated examples
1 parent 330cfb5 commit fe54c8f

2 files changed

Lines changed: 63 additions & 58 deletions

File tree

example/convenience-commit.js

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
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+
});
2847
});
2948
});
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-
//});
4349
});

example/convenience-tree.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
var git = require( '../' );
1+
// Load in the module.
2+
var git = require('nodegit');
23

3-
git.repo( '../.git', function( err, repo ) {
4-
if( err ) { throw err; }
4+
// Open the repository in the current directory.
5+
git.repo('.git', function(error, repository) {
6+
if (error) throw error;
57

6-
repo.branch( 'master', function( err, branch ) {
7-
if( err ) { throw err; }
8+
// Use the master branch.
9+
repository.branch('master', function(error, branch) {
10+
if (error) throw error;
811

9-
branch.tree().walk().on('entry', function( idx, entry ) {
10-
//console.log(entry.entry);
11-
console.log( entry.name, entry.attributes );
12-
//console.log( entry.content );
12+
// Iterate over the revision history.
13+
branch.tree(function(error, tree) {
14+
console.log(tree);
15+
if (error) throw error;
16+
tree.walk().on('entry', function(error, entry) {
17+
entry.name(function(error, name) {
18+
console.log(name);
19+
});
20+
});
1321
});
14-
15-
//branch.tree().entry('example/raw-blob.js', function( entry ) {
16-
// if( entry ) {
17-
// console.log(entry.name);
18-
// }
19-
// else {
20-
// console.log('not found');
21-
// }
22-
//});
2322
});
2423
});

0 commit comments

Comments
 (0)