nodegit / nodegit/nodegit

getTree causes crash on commits created by fileHistoryWalk

Open
#1,851 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.8k
Forks
704
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the getTree implementation shown in node_modules/nodegit/dist/commit.js and reproduce the failure through Revwalk.fileHistoryWalk in the issue's index.js example. Compare the failing entry.commit with the Commit.lookup workaround; done means getTree works directly on commits returned by fileHistoryWalk without crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, javascript, node.js
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.