getTree causes crash on commits created by fileHistoryWalk

未关闭
#1,851 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
git, javascript, node.js
领域
devtools

调研方向

从 node_modules/nodegit/dist/commit.js 中所示的 getTree 实现开始,并在 issue 的 index.js 示例中通过 Revwalk.fileHistoryWalk 重现该故障。将失败的 entry.commit 与 Commit.lookup workaround 进行比较;当 getTree 可以直接作用于 fileHistoryWalk 返回的 commit 且不会崩溃时,即完成。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
JavaScript
星标
5.8k
派生
704
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nodegit/nodegit 的其他 Issue

查看 nodegit/nodegit 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。