X Tutup
The Wayback Machine - https://web.archive.org/web/20200916183746/https://github.com/nodegit/nodegit/issues/1744
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodegit crashes when attempting to commit using repo.defaultSignature #1744

Open
iansan5653 opened this issue Dec 19, 2019 · 5 comments
Open

Nodegit crashes when attempting to commit using repo.defaultSignature #1744

iansan5653 opened this issue Dec 19, 2019 · 5 comments

Comments

@iansan5653
Copy link

@iansan5653 iansan5653 commented Dec 19, 2019

System information

  • node version: 12.31.1
  • npm or yarn version: 6.12.1
  • OS/version/architecture: Windows 10
  • Applicable nodegit version: 0.26.3

Whenever I attempt to commit the changes I've made to some files, nodegit throws a C++ error:
image

Here's the code I'm using:

  // filesToCommit is the array of file paths, relative to the repo root
  if (filesToCommit.length) {
    const index = await repo.refreshIndex();
    const indexPromises = filesToCommit.map(async (relativeFilePath) => {
      await index.addByPath(relativeFilePath);
    });
    await Promise.all(indexPromises);
    index.write();
    const oid = await index.writeTree();
    const signature = Signature.default(repo);
    const head = await Reference.nameToId(repo, "HEAD");
    const parent = await repo.getCommit(head);
    await repo.createCommit(
      "HEAD",
      signature,
      signature,
      "Format and lint files.",
      oid,
      [parent]
    );
    // This never runs:
    console.log(`Committed fixes to ${filesToCommit.length} file(s).`);
  }

My changes are staged, but the commit never happens.

@iansan5653
Copy link
Author

@iansan5653 iansan5653 commented Dec 19, 2019

This still occurs when attempting to use createCommitOnHead:

    const user = repo.defaultSignature();
    await repo.createCommitOnHead(
      filesToCommit.map((set) => set.rel),
      user,
      user,
      "Format and fix lint errors."
    );
@iansan5653
Copy link
Author

@iansan5653 iansan5653 commented Dec 20, 2019

It does not occur when I use Signature.now(name, email) as the user, so it appears to be directly linked to the repo.defaultSignature().

@iansan5653 iansan5653 changed the title Nodegit crashes when attempting to commit Nodegit crashes when attempting to commit using repo.defaultSignature Dec 20, 2019
@rcjsuen
Copy link
Member

@rcjsuen rcjsuen commented Dec 20, 2019

@iansan5653 Signature.default(repository) is an asynchronous function. You need an await.

Same applies for repo.defaultSignature().

@iansan5653
Copy link
Author

@iansan5653 iansan5653 commented Dec 20, 2019

Thanks, looks like this is a DefinitelyTyped issue then.

@iansan5653 iansan5653 closed this Dec 20, 2019
@iansan5653
Copy link
Author

@iansan5653 iansan5653 commented Dec 20, 2019

On second thought though - this error is extremely difficult to diagnose since it's a C++ error with no stack trace - maybe there is an issue present here in the error handling?

@iansan5653 iansan5653 reopened this Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.
X Tutup