Jacob Schoen
Jacob Schoen

Reputation: 14202

How do I list the paths of the files that were changed in a commit?

I can currently walk a particular branch to get the details of the commits (i.e. author, timestamp, etc.) but I would like to also get the files that were affected by the commit.

What I have tried:

commit.getDiff().then(function(arrayDiff) {
  arrayDiff.forEach(function(diff) {
    diff.patches().then(function(patches) {
      patches.forEach(function(patch) {
        console.log("diff", patch.oldFile().path(), patch.newFile().path());
      });
    });
  });
});

The problem seems to be at diff.patches().then(function(patches). I can add logging statements and see that the arrayDiff has items in it, that the foreach is working for it, but my code never reaches patches.forEach.

What am I doing wrong? Is there a better way to get the path of the files that were part of a commit?

Upvotes: 1

Views: 664

Answers (1)

johnhaley81
johnhaley81

Reputation: 1193

I think you're using the current version of NodeGit on NPM (0.4.1) but unfortunately the docs are pointed to the next version which normalized all of those calls to be promises.

Can you try this on master? If you need to stay on 0.4.1 then patches() should return the array of patches and not the promise.

Upvotes: 1

Related Questions