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.

Writing index after merge throws error #1128

Closed

Description

@highco

When running examples/merge-cleanly.js, the following error is thrown by index.write():
Uncaught Error: Failed to write index: The index is in-memory only
Either index.write() or the example is broken.

Activity

  1. alangpierce commented on Oct 22, 2016

    @alangpierce

    @highco I ran into this same issue and ended up solving by using the Merge.merge function instead of Merge.commits. One problem that took me a while to track down is that you need to specify Checkout.STRATEGY.FORCE (or some other non-default strategy) or else it won't change your working directory you'll end up with a completely empty merge commit.

    Here's a code snippet that hopefully is helpful:

    async function createMergeCommit(repo, otherCommit, mergeMessage) {
      const annotatedCommit = await nodegit.AnnotatedCommit.lookup(repo, otherCommit.id());
      await nodegit.Merge.merge(repo, annotatedCommit, null, {
        checkoutStrategy: nodegit.Checkout.STRATEGY.FORCE,
      });
      const index = await repo.refreshIndex();
      if (index.hasConflicts()) {
        throw new CLIError('Unexpected conflict when creating merge commit.');
      }
      await index.write();
      const treeOid = await index.writeTree();
      await repo.createCommit(
        'HEAD',
        repo.defaultSignature(),
        repo.defaultSignature(),
        mergeMessage,
        treeOid,
        [await repo.getHeadCommit(), otherCommit]
      );
      repo.stateCleanup();
    }

    Full example here:
    https://github.com/alangpierce/bulk-decaffeinate/blob/master/src/land.js

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