2014-12-19 50 views
4

我试图在利用图书馆nodegit(版本0.2.4)和ssh的node.js我们TeamForge的服务器克隆的Git仓库克隆用nodegit的Git仓库。 我们的服务器请求来自用户的身份验证,并且当我试图仅使用克隆方法而未传递选项时,出现错误:“回调无法初始化SSH凭据”。如何使用ssh

我在文件private.key和public.key私钥和公钥。它们位于我在web风暴中设置为工作目录的目录中,因此位置不应该成为问题。

没有找到例子,如何做到这一点(也许我错过了),但下面的代码是我得到的最接近:

'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; 
    } 
); 

我得到这个错误:

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

你有暗示什么可能是错的,或者一般如何去做?

回答

4

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

在此期间,如果您有运行,就可以得到该证书的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://[email protected]/reponame", "localTmp", options) 
    .then(function(repo) { 
     var r = repo; 
    }, 
    function(err){ 
     var e = err; 
    } 
); 

在v0.2.4中适用于我。如果您需要更多的实时支持,请随时与我们联系,在our gitter channel

更新:我刚加入这个修复上Pull Request #334。测试通过后,我会把这个问题放在master上,然后问题中的代码应该可以正常工作。

+0

我跑这条线的线仅交换了SSH URL和目录名,并获得'错误:需要身份验证,但没有回调set' – TheEnvironmentalist 2017-09-14 16:05:21

+1

目前已经在nodegit API的变化。在选项中,只需用'callbacks'替换'remoteCallbacks',如下所示:http://www.nodegit.org/api/fetch_options/ – bumblebee 2017-11-09 15:07:59