◐ Shell
clean mode source ↗

`getTree` fails on result of `commit.parent(0)`

System information

  • node version: v8.12.0
  • yarn version: 1.5.1
  • OS/version/architecture: darwin/18.2.0/x64
  • Applicable nodegit version: nodegit@0.25.0-alpha.9 (also repros in 0.24.1 and 0.23.0)

Repro

Here's a repro that runs against the nodegit git repo:

const nodegit = require('nodegit');

nodegit.Repository.open('../nodegit').then(repo => {
  return repo.getCommit('977251b4aae52eef75cf4f188b4d5a63ba98fa7b')
}).then(commit => {
  return commit.parent(0);
}).then(parentCommit => {
  return parentCommit.getTree();
}).then(parentTree => {
  console.log('parentTree: ' + parentTree);
}).then(null, err => {
  console.log('Error encountered\n');
  console.log(err);
});

Expected output: parentTree: [object Tree]

Actual output:

Error encountered

TypeError: Cannot read property 'getTree' of undefined
    at Commit.getTree (node_modules/nodegit/dist/commit.js:302:20)
    at nodegit.Repository.open.then.then.then.parentCommit (main.js:11:23)
    at tryCallOne (node_modules/nodegit-promise/lib/core.js:37:12)
    at node_modules/nodegit-promise/lib/core.js:103:15
    at flush (node_modules/asap/raw.js:50:29)
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickCallback (internal/process/next_tick.js:181:9)

It looks like this line throws an exception because this.repo is undefined.