Reputation: 114815
Edit: I'm changing the question to suit my current understanding of the problem which has changed significantly.
Original Title: Nodegit seems to be asking for wrong credentials on push
When trying to push
using nodegit nothing seems to work on Windows (while they work fine on Linux).
sshKeyFromAgent
- error authenticating: failed connecting agentsshKeyNew
- credentials
callback is repeatedly (looks like an infinite loop
but I can't be sure)sshKeyMemoryNew
: credentials
is called twice and then node exits with no diagnostic (the exit
and beforeExit
events on process
aren't signalled)userpassPlaintextNew
: [Error: unknown certificate check failure] errno: -17Original question follows.
I'm trying to get nodegit
to push
and the following question seems to address this situation. However I'm not able to get it to work.
I've cloned a repository using SSH and when I try to push, my credentials
callback is being called with user git and not motti (which is the actual git user).
try {
const remote = await repository.getRemote("origin");
await remote.push(["refs/head/master:refs/heads/master"], {
callbacks: {
credentials: (url, user) => {
console.log(`Push asked for credentials for '${user}' on ${url}`);
return git.Cred.sshKeyFromAgent(user);
}
}
});
}
catch(err) {
console.log("Error:", err);
}
I get the following output:
Push asked for credentials for 'git' on git@github.[redacted].net:motti/tmp.git
Error: { Error: error authenticating: failed connecting agent errno: -1, errorFunction: 'Remote.push' }
If I try to hardcode motti to the sshKeyFromAgent
function the error changes to:
Error: { Error: username does not match previous request errno: -1, errorFunction: 'Remote.push' }
This my first time trying to programmatically use git so I may be missing something basic...
Answer for some questions from comments:
Upvotes: 1
Views: 2364
Reputation: 306
You need to run an ssh agent locally and save your password there. Follow these steps to make it work:
I hope this helps because I also struggled a lot with it and it can be very frustrating.
Upvotes: -1
Reputation: 16611
Instead of using git.Cred.sshKeyFromAgent
- you could use git.Cred.sshKeyNew
and pass your username / keys along.
const fs = require('fs');
// ...
const username = "git";
const publickey = fs.readFileSync("PATH TO PUBLIC KEY").toString();
const privatekey = fs.readFileSync("PATH TO PRIVATE KEY").toString();
const passphrase = "YOUR PASSPHRASE IF THE KEY HAS ONE";
const cred = await Git.Cred.sshKeyMemoryNew(username, publickey, privatekey, passphrase);
const remote = await repository.getRemote("origin");
await remote.push(["refs/head/master:refs/heads/master"], {
callbacks: {
credentials: (url, user) => cred
}
});
Upvotes: 1