[英]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.