nodegit - 如何在文件提交中添加/删除行?

时间:2017-06-26 11:20:14

标签: node.js git git-commit nodegit

我是nodegit的新手。我想查看最近10次提交的回购,文件已更改以及各个提交中引入的更改。

我已经获得了10个最近提交的列表,但我仍然坚持获取提交详细信息。

以下是我正在使用的代码

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
    }
});

});

0 个答案:

没有答案