Nodegit - how to get lines added / removed in a filewise file?
I am new to nodegit. I want to see the last 10 commits for a repo, file changes, and changes made to the corresponding commits.
I have a list of the 10 most recent commits, but I'm stuck getting the details of the commit.
Here is the code I am using
var nodegit = require('nodegit');
var repoPath = "some_repo_path";
//open branch
nodegit.Repository.open(repoPath).then(function(repo){
//get branch
return repo.getCurrentBranch().then(function(ref) {
console.log("On " + ref.shorthand() + " (" + ref.target() + ")");
//get commit
return repo.getBranchCommit(ref.shorthand());
}).then(function(commit) {
//get commit history
var history = commit.history();
p = new Promise(function(resolve, reject) {
history.on("end", resolve);
history.on("error", reject);
});
history.start();
return p;
}).then(function(commits){
//iterate through last 10 commits
for (var i = 0; i < 10; i++) {
var sha = commits[i].sha().substr(0,7),
msg = commits[i].message().split('\n')[0];
console.log(sha + " " + msg + " " + commits[i].author() + " " + commits[i].time());
//get details for this commit
//number of lines added/removed
//list of files changed/deleted
//for each changed file number of lines added/removed
//for each changes file actual lines added/removed
}
});
});
+3
source to share
No one has answered this question yet
Check out similar questions: