Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何使用ssh克隆带有nodegit的git存储库_Node.js_Git_Ssh_Libgit2_Nodegit - Fatal编程技术网

Node.js 如何使用ssh克隆带有nodegit的git存储库

Node.js 如何使用ssh克隆带有nodegit的git存储库,node.js,git,ssh,libgit2,nodegit,Node.js,Git,Ssh,Libgit2,Nodegit,我正在尝试使用库nodegit(版本0.2.4)和ssh从node.js中的teamforge服务器克隆git存储库。 我们的服务器请求用户进行身份验证,当我尝试只使用clone方法而不传递选项时,出现了错误:“Callback无法初始化SSH凭据” 我在private.key和public.key文件中有私钥和公钥。它们位于我在WebStorm中设置为工作目录的目录中,所以位置应该不会有问题 没有找到如何执行的示例(可能我错过了),但下面的代码是我得到的最接近的代码: 'use strict'

我正在尝试使用库nodegit(版本0.2.4)和ssh从node.js中的teamforge服务器克隆git存储库。 我们的服务器请求用户进行身份验证,当我尝试只使用clone方法而不传递选项时,出现了错误:“Callback无法初始化SSH凭据”

我在private.key和public.key文件中有私钥和公钥。它们位于我在WebStorm中设置为工作目录的目录中,所以位置应该不会有问题

没有找到如何执行的示例(可能我错过了),但下面的代码是我得到的最接近的代码:

'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://user@teamforgeserver.net/reponame", "localTmp", options)
  .then(function(repo) {
        var r = repo;
    },
    function(err){
        var e = err;
    }
);
我得到了这个错误:

TypeError: Object #<Object> has no method 'isFulfilled' at value
(c:\...\proj\node_modules\nodegit\node_modules\nodegit-promise\lib\core.js:36:15)
TypeError:对象#在值处没有方法“IsCompleted”
(c:\…\proj\node\u modules\nodegit\node\u modules\nodegit promise\lib\core.js:36:15)

你有没有提示什么地方可能会出错,或者通常如何做?

这是一个创建新ssh密钥的错误。我创建了一个问题来跟踪它

同时,如果您有一个正在运行的SSH代理,您可以从该代理获取凭据

'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://user@teamforgeserver.net/reponame", "localTmp", options)
  .then(function(repo) {
        var r = repo;
    },
    function(err){
        var e = err;
    }
);
这在v0.2.4中对我有效。如果您需要更多的实时支持,请随时与我们聊天


更新:我刚刚在上添加了一个修复程序。测试通过后,我将把它放在master上,然后问题中的代码应该可以正常工作。

我运行这一行,只切换出ssh url和目录名,得到了
错误:需要身份验证,但没有回调集
nodegit api发生了更改。在该选项中,只需将
remoteCallbacks
替换为
callbacks
,如下所述: