nodegit
nodegit copied to clipboard
getTree causes crash on commits created by fileHistoryWalk
System information
- node version: v14.17.4
- npm or yarn version: Yarn v1.22.11
- OS/version/architecture: Debian 10 Buster x86_64
- Applicable nodegit version: 0.27.0
Problem
The getTree commit class method crashes when the commit is created by fileHistoryWalk.
This is technically a duplicate of #1045 but that was all the way back in 2016 and this problem has yet to be resolved.
Output:
(node:16430) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getTree' of undefined
at Commit.getTree (/home/hampus/loltest/lmao/node_modules/nodegit/dist/commit.js:290:20)
at main (/home/hampus/loltest/lmao/index.js:16:34)
at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:96:32)
(node:16430) TypeError: Cannot read property 'getTree' of undefined
at Commit.getTree (/home/hampus/loltest/lmao/node_modules/nodegit/dist/commit.js:290:20)
at main (/home/hampus/loltest/lmao/index.js:16:34)
(node:16430) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:96:32)
Recreating the bug
const nodegit = require("nodegit");
async function main() {
const repository = await nodegit.Repository.openBare("{ repository }");
const revw = nodegit.Revwalk.create(repository);
revw.pushHead();
const cnt = (await revw.getCommitsUntil(() => true)).length;
revw.pushHead();
const history = await revw.fileHistoryWalk("{ any file or folder }", cnt);
for(const entry of history) {
console.log(await entry.commit.getTree());
}
}
main();
Workaround
A simple workaround for this is to create a new commit instance from the entry commit's sha.
const commit = await Commit.lookup(repository, entry.commit.sha());
// This will work
console.log(await commit.getTree());
Solution
#1110