简体   繁体   English

git使用Nodegit推送远程ssh,无法正常工作吗?

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

Hi I am trying to do a git push origin master command with the help of Nodegit , but it is resulting in an error, 嗨,我正尝试在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);
})
}

I am using our internal ssh github server, which from the git Bash, for each push is asking for Username and Password. 我正在使用我们的内部ssh github服务器,它来自git Bash,每次推送都要求输入用户名和密码。

Hence in hence in the code I have used the similar example as mentioned in the github site and also in the test site . 因此,在代码中,我使用了github站点测试站点中提到的类似示例。

Pls help on this !!!!!! 请帮助这个!!!!!!

I have found the answer to my own question, 我找到了自己问题的答案,

The confusion lies in the SSH server and generic server, 混乱之处在于SSH服务器和通用服务器,

i found two awesome post in the past nodegit questions, 我在过去的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);
    });
}

The main issue lies in configuring the credentials in the Nodegit Library. 主要问题在于在Nodegit库中配置凭据。 Pls be careful in checking whether it is a SSH key based push or whether it works well with generic userpassPainTestNow mode. 请仔细检查它是否是基于SSH密钥的推送,或在常规userpassPainTestNow模式下是否工作正常。 I have commented both the scenarios out there. 我已经评论了两种情况。 These links turned out to be really useful for troubleshooting this. 这些链接对于解决此问题确实非常有用。 Nodegit: How to modify a file and push the changes? Nodegit:如何修改文件并推送更改? https://github.com/nodegit/nodegit/issues/463 https://github.com/nodegit/nodegit/issues/463

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

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