|
1 | | -var git = require('../'), |
2 | | - path = require('path'); |
| 1 | +var git = require('../'); |
| 2 | +var path = require('path'); |
3 | 3 |
|
4 | 4 | // This code examines the diffs between a particular commit and all of its |
5 | 5 | // parents. Since this commit is not a merge, it only has one parent. This is |
6 | 6 | // similar to doing `git show`. |
7 | 7 |
|
8 | | -git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) { |
9 | | - if (error) throw error; |
| 8 | +git.Repository.open(path.resolve(__dirname, '../.git')) |
| 9 | +.then(function(repo) { |
| 10 | + return repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5'); |
| 11 | +}) |
| 12 | +.then(function(commit) { |
| 13 | + console.log('commit ' + commit.sha()); |
| 14 | + console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>'); |
| 15 | + console.log('Date:', commit.date()); |
| 16 | + console.log('\n ' + commit.message()); |
10 | 17 |
|
11 | | - repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) { |
12 | | - if (error) throw error; |
13 | | - |
14 | | - console.log('commit ' + commit.sha()); |
15 | | - console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>'); |
16 | | - console.log('Date:', commit.date()); |
17 | | - console.log('\n ' + commit.message()); |
18 | | - |
19 | | - commit.getDiff(function(error, diffList) { |
20 | | - if (error) throw error; |
21 | | - |
22 | | - diffList.forEach(function(diff) { |
23 | | - diff.patches().forEach(function(patch) { |
24 | | - console.log("diff", patch.oldFile().path(), patch.newFile().path()); |
25 | | - patch.hunks().forEach(function(hunk) { |
26 | | - console.log(hunk.header().trim()); |
27 | | - hunk.lines().forEach(function(line) { |
28 | | - console.log(String.fromCharCode(line.lineOrigin) + line.content.trim()); |
29 | | - }); |
30 | | - }); |
| 18 | + return commit.getDiff(); |
| 19 | +}) |
| 20 | +.done(function(diffList) { |
| 21 | + diffList.forEach(function(diff) { |
| 22 | + diff.patches().forEach(function(patch) { |
| 23 | + console.log("diff", patch.oldFile().path(), patch.newFile().path()); |
| 24 | + patch.hunks().forEach(function(hunk) { |
| 25 | + console.log(hunk.header().trim()); |
| 26 | + hunk.lines().forEach(function(line) { |
| 27 | + console.log(String.fromCharCode(line.origin()) + line.content().trim()); |
31 | 28 | }); |
32 | 29 | }); |
33 | 30 | }); |
|
0 commit comments