getTree causes crash on commits created by fileHistoryWalk

オープン
#1,851 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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 の回避策を比較します。fileHistoryWalk が返す commit に対して getTree が直接クラッシュせずに動作すれば完了です。

索引モデルが 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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nodegit/nodegit のほかの issue

nodegit/nodegit の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。