Skip to content
This repository was archived by the owner on Dec 2, 2026. It is now read-only.
This repository was archived by the owner on Dec 2, 2026. It is now read-only.

Git.Merge.trees seems to be unusable #1504

Closed

Description

@tniessen

I am trying to follow these instructions to perform a cherry-pick in a bare repository. This is what I ended up with:

async cherryPickWithMessage(localBranch: string, commit: string, message: string) {
  const theirCommit = await this.repo.getCommit(commit);
  const ourCommit = await this.repo.getBranchCommit(localBranch);
  const base = await Git.Merge.base(this.repo, theirCommit.id(), ourCommit.id());

  // nodegit has a bug that causes .parent() to return a "partial" commit that
  // cannot be used for subsequent operations such as .getTree(). See
  // https://github.com/nodegit/nodegit/pull/1110.
  const baseTreeId = await theirCommit.parent(0).then(c => c.treeId());
  const baseTree = await this.repo.getTree(baseTreeId);
  const theirTree = await theirCommit.getTree();
  const ourTree = await ourCommit.getTree();
  // This does not work.
  const index = await Git.Merge.trees(this.repo, baseTree, ourTree, theirTree, null);
  const newTreeId = await index.writeTree();

  const ownCommitterSignature = theirCommit.committer(); // TODO
  return await this.repo.createCommit(localBranch, theirCommit.author(), ownCommitterSignature, message, newTreeId, [ourCommit]).then(id => id.tostrS());
}

The critical point is calling Git.Merge.trees. The documentation says that the fifth parameter is optional:

the merge tree options (or null for defaults)

However, when passing the options as described above, this error is thrown (which might be a bug):

Error: MergeOptions opts is required.
    at F:\node-cq\node_modules\nodegit-promise\lib\node-extensions.js:24:20
    at tryCallTwo (F:\node-cq\node_modules\nodegit-promise\lib\core.js:45:5)
    at doResolve (F:\node-cq\node_modules\nodegit-promise\lib\core.js:173:13)
    at new Promise (F:\node-cq\node_modules\nodegit-promise\lib\core.js:65:3)
    at Function.trees (F:\node-cq\node_modules\nodegit-promise\lib\node-extensions.js:19:12)
    at LG2Repository.<anonymous> (F:\node-cq\lib\local-git\libgit2.ts:42:35)
    at Generator.next (<anonymous>)
    at fulfilled (F:\node-cq\lib\local-git\libgit2.ts:4:58)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)

I tried passing an empty object {} as the opts parameter, which causes a CRT assertion (which - I assume - is definitely a bug):

clipboard01

Is there a proper way to use this API without triggering an assertion or error?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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