Skip to content

Commit.lookupPrefix misses repo property #2008

Open
@lal12

Description

@lal12

The following code

import Nodegit from "nodegit";

const repo = await Nodegit.Repository.open("/home/user/git/linux");

const c = await Nodegit.Commit.lookupPrefix(repo, Nodegit.Oid.fromString("4387bfa605206b57451e6f77af1287960981ffa2"), 40);
console.log(c.sha(), c.getDiff());

leads to an exception:

/home/user/git/analysis/node_modules/nodegit/dist/commit.js:290
  return this.repo.getTree(this.treeId());
                   ^

TypeError: Cannot read properties of undefined (reading 'getTree')
    at Commit.getTree (/home/user/git/analysis/node_modules/nodegit/dist/commit.js:290:20)
    at Commit.getDiffWithOptions (/home/user/git/analysis/node_modules/nodegit/dist/commit.js:209:17)
    at Commit.getDiff (/home/user/git/analysis/node_modules/nodegit/dist/commit.js:195:15)
    at file:///home/user/git/analysis/test.mjs:6:24

The issue is analog to #1658, and can be fixed the same way.
However it might be better to have a generic wrapper for commit objects being returned by the raw api.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions