forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff-commits.js
More file actions
35 lines (29 loc) · 1.2 KB
/
diff-commits.js
File metadata and controls
35 lines (29 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var git = require('../'),
path = require('path');
// This code examines the diffs between a particular commit and all of its
// parents. Since this commit is not a merge, it only has one parent. This is
// similar to doing `git show`.
git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
if (error) throw error;
repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) {
if (error) throw error;
console.log('commit ' + commit.sha());
console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>');
console.log('Date:', commit.date());
console.log('\n ' + commit.message());
commit.getDiff(function(error, diffList) {
if (error) throw error;
diffList.forEach(function(diff) {
diff.patches().forEach(function(patch) {
console.log("diff", patch.oldFile().path(), patch.newFile().path());
patch.hunks().forEach(function(hunk) {
console.log(hunk.header().trim());
hunk.lines().forEach(function(line) {
console.log(String.fromCharCode(line.lineOrigin) + line.content.trim());
});
});
});
});
});
});
});