简体   繁体   English

如何使用ssh使用nodegit克隆git存储库

[英]How to clone git repository with nodegit using ssh

I'm trying to clone git repository from our teamforge server in node.js using library nodegit (version 0.2.4) and ssh. 我正在尝试使用库nodegit(版本0.2.4)和ssh从node.js中的teamforge服务器克隆git存储库。 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". 我们的服务器请求用户进行身份验证,当我尝试仅使用克隆方法而不传递选项时,我收到错误:“回调无法初始化SSH凭据”。

I have private and public key in files private.key and public.key. 我在private.key和public.key文件中有私钥和公钥。 They're in directory which I have set to working directory in web storm, so location shouldn't be a problem. 它们位于我在web风暴中设置为工作目录的目录中,因此位置应该不是问题。

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://user@teamforgeserver.net/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? 您是否暗示可能出现的问题或一般如何做?

This is a bug with creating a new ssh key. 这是创建新ssh密钥的错误。 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. 与此同时,如果您正在运行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;
    }
);

That works for me in v0.2.4. 这在v0.2.4中对我有用。 If you need more realtime support feel free to come chat with us over in our gitter channel . 如果您需要更多实时支持,请随时在我们的gitter频道与我们聊天。

UPDATE: I just added a fix for this on Pull Request #334 . 更新:我刚刚在Pull Request#334上添加了一个修复程序。 After tests pass I'll put this on master and then the code in the question should work fine. 测试通过后我将把它放在master上,然后问题中的代码应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM