forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwalk-history.js
More file actions
23 lines (19 loc) · 869 Bytes
/
walk-history.js
File metadata and controls
23 lines (19 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var nodegit = require('../'),
path = require('path');
// This code walks the history of the master branch and prints results
// that look very similar to calling `git log` from the command line
nodegit.Repository.open(path.resolve(__dirname, '../.git')).then(function(repo) {
return repo.getMasterCommit();
}).then(function(firstCommitOnMaster){
// History returns an event.
var history = firstCommitOnMaster.history(nodegit.Revwalk.SORT.Time);
// History emits 'commit' event for each commit in the branch's history
history.on('commit', function(commit) {
console.log('commit ' + commit.sha());
console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>');
console.log('Date:', commit.date());
console.log('\n ' + commit.message());
});
// Don't forget to call `start()`!
history.start();
}).done();