1

I'm getting a hard time using nodegit in an Angular 9 application running in an electron environment. It's not an installation problem nor a compilation problem because I can get it to work in some way...

When I execute all calls of nodegit in the main process (via IPC messages), my caller needs to access to the full class of, for example, Repository. When we send the response via IPC, it's getting serialized. So, at the other end of the line, I get just an empty object.

ipcMain.on(`GitService:clone`, (event, arg) => {
        const url = arg[0];
        const localPath = arg[1];
        let cloneOptions = arg[2];
        if (cloneOptions === undefined) {
            cloneOptions = {};
        }
        cloneOptions.fetchOpts = cloneOptions.fetchOpts || {};
        cloneOptions.fetchOpts.callbacks = cloneOptions.fetchOpts.callbacks || {};
        cloneOptions.fetchOpts.callbacks.credentials = () => this.credentialsCallback();

        console.log(`Cloning repo ${url}`, cloneOptions);
        const repo = await git.Clone.clone(url, localPath, cloneOptions).catch((err) => {
            console.log(err);
            return git.Repository.open(localPath);
        });
        event.sender.send(`GitService:clone`, repo);
    });

[...]

public credentialsCallback() {
   const creds = git.Cred.userpassPlaintextNew('mysuperusername', "myawsomepassword");
   return creds;
}

This works fine. It clones the repo, but the caller is not receiving the actual Repository class because it's being serialized.

What can I do?

I tried to use nodegit directly in the renderer, but it needs a callback for authentication and it looks like the callback is not properly called with it's in the renderer...

Here's the code I tried to move to the renderer process

public method() {
    const git = electron.remote.require('nodegit');
    const clonePath: string = 'the-path-to-clone-to';

    let cloneOptions = {};
    cloneOptions.fetchOpts = cloneOptions.fetchOpts || {};
    cloneOptions.fetchOpts.callbacks = cloneOptions.fetchOpts.callbacks || {};
    cloneOptions.fetchOpts.callbacks.credentials = function() {
        console.log('credentialsCallback');
        const creds = git.Cred.userpassPlaintextNew('mysuperuser', "myawsomepassword");
        return creds;
    };

    console.log(`Cloning repo`);
    const repo = await git.Clone('my-git-url', clonePath, cloneOptions);

    return repo;
}

The clone process starts (because I can see the project folder created), my credentials callback is called (because I see 'credentialsCallback' in the console), but I get this error:

Error: remote authentication required but no callback set

Despite my callback being called.

I'm using const git = electron.remote.require('nodegit'); because if I use require('nodegit') directly, I get this error in the main process console

WARNING in ./node_modules/promisify-node/index.js 107:14-27 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/nodegit/build/Release/nodegit.node 1:0 Module parse failed: Unexpected character '�' (1:0) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders (Source code omitted for this binary file)

So what am I doing wrong here?

I'm using Electron 6.0.7

I'm using nodegit 0.26.4

vIceBerg
  • 4,197
  • 5
  • 40
  • 53

0 Answers0