簡體   English   中英

git使用Nodegit推送遠程ssh,無法正常工作嗎?

[英]git push remote ssh using Nodegit, Not working?

嗨,我正嘗試在Nodegit的幫助下執行git push origin master命令,但這會導致錯誤,

var Git = require('nodegit');
function gitRemoteLookUp(repoPath) {
var open = Git.Repository.open;
var Remote = Git.Remote;    
open(repoPath).then(function(repo){
    return Remote.lookup(repo, "origin");
}).then(function(remote){       
    var ref = "refs/heads/master:remotes/origin/master";                
    var firstPass = true;
    var options = {
      callbacks: {
        credentials: function(url, userName) {
          if (firstPass) {
            firstPass = false;
            if (url.indexOf("https") === -1) {                  
              return Git.Cred.sshKeyFromAgent('XYZ');
            } else {                    
                return Git.Cred.userpassPlaintextNew('XYZ', "XYZ");
            }
          } else {
            return Git.Cred.defaultNew();
          }
        },
        certificateCheck: function() {
          return 1;
        }
      }
    };
    return remote.push(ref, options);
}).catch(function(err){
    console.log(err);
})
}

我正在使用我們的內部ssh github服務器,它來自git Bash,每次推送都要求輸入用戶名和密碼。

因此,在代碼中,我使用了github站點測試站點中提到的類似示例。

請幫助這個!!!!!!

我找到了自己問題的答案,

混亂之處在於SSH服務器和通用服務器,

我在過去的nodegit問題中發現了兩個很棒的帖子,

var remote;
var repository;
function gitRemoteLookUp(repoPath) {
    var open = Git.Repository.open;     
    open(repoPath).then(function(repo){
        repository = repo;
        return repo.getRemote('origin');
    }).then(function(remoteResult){
        remote = remoteResult;          
        remote.setCallbacks({
              credentials: function(url, userName) {
                  // return Git.Cred.sshKeyFromAgent(userName);
                  return Git.Cred.userpassPlaintextNew('XYZ', "XYZ");
              }
          });


        return remote.connect(Git.Enums.DIRECTION.PUSH);
    }).then(function() {
      console.log('remote Connected?', remote.connected())

      return remote.push(
                ["refs/heads/master:refs/heads/master"],
                null,
                repository.defaultSignature(),
                "Push to master")
    }).then(function() {
        console.log('remote Pushed!')
    })
    .catch(function(reason) {
        console.log(reason);
    });
}

主要問題在於在Nodegit庫中配置憑據。 請仔細檢查它是否是基於SSH密鑰的推送,或在常規userpassPainTestNow模式下是否工作正常。 我已經評論了兩種情況。 這些鏈接對於解決此問題確實非常有用。 Nodegit:如何修改文件並推送更改? https://github.com/nodegit/nodegit/issues/463

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM