examples/walk-history-for-file.js
function compileHistory(resultingArrayOfCommits) {
  var lastSha;
  if (historyCommits.length > 0) {
    lastSha = historyCommits[historyCommits.length - 1].commit.sha();
    if (
      resultingArrayOfCommits.length == 1 &&
      resultingArrayOfCommits[0].commit.sha() == lastSha
    ) {
      return;
    }
  }

  resultingArrayOfCommits.forEach(function(entry) {
    historyCommits.push(entry);
  });

  lastSha = historyCommits[historyCommits.length - 1].commit.sha();

  walker = repo.createRevWalk();
  walker.push(lastSha);
  walker.sorting(nodegit.Revwalk.SORT.TIME);

  return walker.fileHistoryWalk(historyFile, 500)
    .then(compileHistory);
}
function compileHistory(resultingArrayOfCommits) {
  var lastSha;
  if (historyCommits.length > 0) {
    lastSha = historyCommits[historyCommits.length - 1].commit.sha();
    if (
      resultingArrayOfCommits.length == 1 &&
      resultingArrayOfCommits[0].commit.sha() == lastSha
    ) {
      return;
    }
  }

  resultingArrayOfCommits.forEach(function(entry) {
    historyCommits.push(entry);
  });

  lastSha = historyCommits[historyCommits.length - 1].commit.sha();

  walker = repo.createRevWalk();
  walker.push(lastSha);
  walker.sorting(nodegit.Revwalk.SORT.TIME);

  return walker.fileHistoryWalk(historyFile, 500)
    .then(compileHistory);
}
function compileHistory ( resultingArrayOfCommits ) { var lastSha ; if ( historyCommits . length > 0 ) { lastSha = historyCommits [ historyCommits . length - 1 ] . commit . sha ( ) ; if ( resultingArrayOfCommits . length == 1 && resultingArrayOfCommits [ 0 ] . commit . sha ( ) == lastSha ) { return ; } } resultingArrayOfCommits . forEach ( function ( entry ) { historyCommits . push ( entry ) ; } ) ; lastSha = historyCommits [ historyCommits . length - 1 ] . commit . sha ( ) ; walker = repo . createRevWalk ( ) ; walker . push ( lastSha ) ; walker . sorting ( nodegit . Revwalk . SORT . TIME ) ; return walker . fileHistoryWalk ( historyFile , 500 ) . then ( compileHistory ) ; }
This code walks the history of the master branch and prints results that look very similar to calling `git log` from the command line
This code walks the history of the master branch and prints results that look very similar to calling git log from the command line