Skip to content

Commit 81ae2a7

Browse files
committed
Update diff-commits.js
1 parent fec768f commit 81ae2a7

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

examples/diff-commits.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
var nodegit = require("../");
2-
var path = require("path");
1+
const nodegit = require("../");
2+
const path = require("path");
33

44
// This code examines the diffs between a particular commit and all of its
55
// parents. Since this commit is not a merge, it only has one parent. This is
66
// similar to doing `git show`.
77

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");
1311
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+
);
1616
console.log("Date:", commit.date());
1717
console.log("\n " + commit.message());
1818

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

Comments
 (0)