nodegit: Segmentation Fault

I’m using NodeGit to setup multiple git repositories. When I do that I get the error:

[1]    7896 segmentation fault (core dumped)  node example.js

This error happens with NodeGit 0.5.0 and 0.6.0. Running on Ubuntu 15.10, on Node JS 5.2.0 and 4.3.2

Here is the code I am trying to run. This will work correctly with a single destination, but will SegFault with multiple. A version of this code previously worked with multiple destinations with NodeGit 0.4.0

'use strict';

const NodeGit = require('nodegit');
const path = require('path');

const temporaryFolder = path.join(__dirname, 'temp');
const branchReference = 'refs/heads/master:refs/heads/master';

// replace this with your own username and password
// seedRepository should have files already
// destinationRepositories should not have any files or commits yet
seedRepositories('testUser', 'password', 'https://github.com/ChristianMurphy/just-a-test-ignore-this', ['https://github.com/ChristianMurphy/please-work-1', 'https://github.com/ChristianMurphy/please-work-2'])

function seedRepositories (username, password, seedRepositoryURL, destinationRepositoryURLs) {
    const credentials = NodeGit.Cred.userpassPlaintextNew(username, password);

    // clone seed repo
    NodeGit.Clone(seedRepositoryURL, temporaryFolder, {
        callbacks: {
            credentials: function () {
                return credentials;
            }
        }
    })
    // open the repository
    .then(() => {
        return NodeGit.Repository.open(temporaryFolder);
    })
    // push the seed repository to all destination repositories
    .then((seedRepository) => {
        const promises = [];

        // for each destination
        for (let index = 0; index < destinationRepositoryURLs.length; index++) {
            // create a remote for destination
            NodeGit.Remote.create(seedRepository, index.toString(), destinationRepositoryURLs[index]);
            // open remote for destination and collect resulting promise
            promises.push(
                NodeGit.Remote.lookup(seedRepository, index.toString())
                .then((remote) => {
                    // push to destination remote
                    return remote.push([branchReference], {
                        callbacks: {
                            credentials: function () {
                                return credentials;
                            }
                        }
                    });
                })
            );
        }
        // wait for all pushes to complete
        return Promise.all(promises);
    })
    .catch((err) => {
        console.error(err);
    });
};

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 17 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Also faced this just now with the latest nodegit. Thanks for your hint @srajko! Originally, I had credentials: () => cred in my remote.push call, where cred was defined once in the beginning of the script:

const cred = Cred.sshKeyNew('git', pathPoPublicKey, pathToPrivateKey, '');

This resulted a crash with [1] 69758 segmentation fault npm start in bash and no exception thrown.

After replacing this with credentials: () => Cred.sshKeyNew(...) crashing stopped! Now the cred object is being created every time, but at least things work! šŸŽ‰

@ChristianMurphy can you please try to replace

return remote.push([branchReference], {
  callbacks: {
    credentials () {
      return credentials;
    }
  }
});

with

return remote.push([branchReference], {
  callbacks: {
    credentials () {
      return NodeGit.Cred.userpassPlaintextNew(username, password);
    }
  }
});

For me, this makes the difference between it segfaulting and completing. Does it resolve the problem for you as well?