2014-12-19 48 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