6

I'm trying to clone git repository from our teamforge server in node.js using library nodegit (version 0.2.4) and ssh. Our server requests authentication from user and when I was trying to use only clone method without passing options I was getting error: "Callback failed to initialize SSH credentials".

I have private and public key in files private.key and public.key. They're in directory which I have set to working directory in web storm, so location shouldn't be a problem.

Didn't find example how to do it (maybe I missed it), but below code is the closest which I got:

'use strict'; var nodegit = require("nodegit"), Clone = nodegit.Clone, cred = nodegit.Cred; var options = { remoteCallbacks: { credentials: function () { return cred.sshKeyNew('user', 'public.key', 'private.key', ''); } } }; Clone.clone("ssh://[email protected]/reponame", "localTmp", options) .then(function(repo) { var r = repo; }, function(err){ var e = err; } ); 

I'm getting this error:

TypeError: Object #<Object> has no method 'isFulfilled' at value (c:\...\proj\node_modules\nodegit\node_modules\nodegit-promise\lib\core.js:36:15) 

Do you have hint what could be wrong or how to do it in general?

1 Answer 1

5

This is a bug with creating a new ssh key. I've created an issue here to track it.

In the meantime if you have an SSH agent running you can get the credentials from that.

'use strict'; var nodegit = require("nodegit"), Clone = nodegit.Clone, cred = nodegit.Cred; var options = { fetchOpts: { remoteCallbacks: { credentials: function (url, userName) { // this is changed from sshKeyNew to sshKeyFromAgent return cred.sshKeyFromAgent(userName); } } } }; Clone.clone("ssh://[email protected]/reponame", "localTmp", options) .then(function(repo) { var r = repo; }, function(err){ var e = err; } ); 

That works for me in v0.2.4. If you need more realtime support feel free to come chat with us over in our gitter channel.

UPDATE: I just added a fix for this on Pull Request #334. After tests pass I'll put this on master and then the code in the question should work fine.

Sign up to request clarification or add additional context in comments.

2 Comments

I ran this line for line only switching out the ssh url and the directory name and got Error: authentication required but no callback set
There has been a change in the nodegit api. Within the option, just replace remoteCallbacks with callbacks as defined here: nodegit.org/api/fetch_options

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.