|
1 | | -var nodegit = require("../"); |
2 | | -var path = require("path"); |
| 1 | +const nodegit = require("../"); |
| 2 | +const 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 | | -nodegit.Repository.open(path.resolve(__dirname, "../.git")) |
9 | | -.then(function(repo) { |
10 | | - return repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5"); |
11 | | -}) |
12 | | -.then(function(commit) { |
| 8 | +(async () => { |
| 9 | + const repo = await nodegit.Repository.open(path.resolve(__dirname, "../.git")) |
| 10 | + const commit = await repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5"); |
13 | 11 | console.log("commit " + commit.sha()); |
14 | | - console.log("Author:", commit.author().name() + |
15 | | - " <" + commit.author().email() + ">"); |
| 12 | + console.log( |
| 13 | + "Author:", commit.author().name() + |
| 14 | + " <" + commit.author().email() + ">" |
| 15 | + ); |
16 | 16 | console.log("Date:", commit.date()); |
17 | 17 | console.log("\n " + commit.message()); |
18 | 18 |
|
19 | | - return commit.getDiff(); |
20 | | -}) |
21 | | -.done(function(diffList) { |
22 | | - diffList.forEach(function(diff) { |
23 | | - diff.patches().then(function(patches) { |
24 | | - patches.forEach(function(patch) { |
25 | | - patch.hunks().then(function(hunks) { |
26 | | - hunks.forEach(function(hunk) { |
27 | | - hunk.lines().then(function(lines) { |
28 | | - console.log("diff", patch.oldFile().path(), |
29 | | - patch.newFile().path()); |
30 | | - console.log(hunk.header().trim()); |
31 | | - lines.forEach(function(line) { |
32 | | - console.log(String.fromCharCode(line.origin()) + |
33 | | - line.content().trim()); |
34 | | - }); |
35 | | - }); |
36 | | - }); |
37 | | - }); |
38 | | - }); |
39 | | - }); |
40 | | - }); |
41 | | -}); |
| 19 | + const diffList = await commit.getDiff(); |
| 20 | + for (const diff of diffList) { |
| 21 | + const patches = await diff.patches(); |
| 22 | + for (const patch of patches) { |
| 23 | + const hunks = await patch.hunks(); |
| 24 | + for (const hunk of hunks) { |
| 25 | + const lines = await hunk.lines(); |
| 26 | + console.log( |
| 27 | + "diff", |
| 28 | + patch.oldFile().path(), |
| 29 | + patch.newFile().path() |
| 30 | + ); |
| 31 | + console.log(hunk.header().trim()); |
| 32 | + for (const line of lines) { |
| 33 | + console.log( |
| 34 | + String.fromCharCode(line.origin()) + |
| 35 | + line.content().trim() |
| 36 | + ); |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | +})(); |
0 commit comments