Skip to content

Instantly share code, notes, and snippets.

@kyv
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyv/9b74c03a1a70e5e65770 to your computer and use it in GitHub Desktop.
Save kyv/9b74c03a1a70e5e65770 to your computer and use it in GitHub Desktop.
diff-commits with lodash
var _ = require("lodash");
var nodegit = require("nodegit");
var 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`.
nodegit.Repository.open(path.resolve(__dirname, "./"))
.then(function(repo) {
return repo.getCommit("59164d9202f12ab8293bbaaff1e9ccb48a422c84");
})
.then(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());
console.log(_.first([1,2,3,4]));
return commit.getDiff();
})
.done(function( _.first( diffList ) ) {
console.log(_.first( diffList) );
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.origin()) +
line.content().trim());
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment