I have built this function in NodeJs,
var Git = require('nodegit');
var fse = require('fs-extra');
var path = require('path');
var fs = require('fs');
var repoPath = 'D:\\sample'
function gitCommitHistory(repoPath, callbackGitCommitHistory) {
try {
    var open = Git.Repository.open;
    var commitList = [];
    open(repoPath)
      .then(function(repo) {              
        return repo.getMasterCommit();
      })
      .then(function(firstCommitOnMaster) {
        var history = firstCommitOnMaster.history();            
        history.on("commit", function(commit) {
            if (commit === 'undefined') {
                callbackGitCommitHistory(null, commitList);
            }
          var author = commit.author();
          commitList.push({commitAuthor:author.name(),commitAuthorEmail:author.email(), 
              commitMessage:commit.message(), commitSha:commit.sha(), commitDate:commit.date()});
        });
        history.on("error", function(err){
            console.log(err)
        })
        history.on("end", function(){               
            callbackGitCommitHistory(null, commitList);
        });
        history.start();
      });   
} catch (error) {
    callbackGitCommitHistory(error);
}
};
I have built this function using module "Nodegit". They are using promises as the callback handler.
In the function I am retrieving all the commits Done by a user on a repository and sending it as a response to the calling webservice.
The function works fine if there is atleast one commit, (i.e) the repo.getMasterCommit returns the commit history. But if I give the repoPath to a new repo with zero commits then, nothing is returned from that function, hence i cannot send any response to the calling web service. Pls help on how to handle this situation!!!!!!!!
 
    