[英]How to use credentials to work with nodegit.push on Windows
编辑:我正在更改问题以适应我目前对已发生重大变化的问题的理解。
原标题: Nodegit 似乎在推送时要求提供错误的凭据
当尝试使用nodegit push
,Windows 上似乎没有任何效果(而它们在 Linux 上工作正常)。
sshKeyFromAgent
-验证错误:连接代理失败sshKeyNew
- credentials
回调是重复的(看起来像一个无限循环,但我不能确定)sshKeyMemoryNew
: credentials
被调用两次,然后节点在没有诊断的情况下exit
( process
上的exit
和beforeExit
事件没有发出信号)userpassPlaintextNew
: [错误: 未知证书检查失败] errno: -17原始问题如下。
我正在尝试让nodegit
push
,以下问题似乎解决了这种情况。 但是我无法让它工作。
我已经使用 SSH 克隆了一个存储库,当我尝试推送时,我的credentials
回调是使用用户git而不是motti (这是实际的 git 用户)调用的。
try {
const remote = await repository.getRemote("origin");
await remote.push(["refs/head/master:refs/heads/master"], {
callbacks: {
credentials: (url, user) => {
console.log(`Push asked for credentials for '${user}' on ${url}`);
return git.Cred.sshKeyFromAgent(user);
}
}
});
}
catch(err) {
console.log("Error:", err);
}
我得到以下输出:
Push 要求在 git@github 上提供“git”的凭据。 [编辑] .net:motti/tmp.git
错误:{ 错误:错误验证:连接代理失败 errno:-1,errorFunction:'Remote.push'}
如果我尝试将motti硬编码到sshKeyFromAgent
函数,错误将更改为:
错误:{ 错误:用户名与之前的请求不匹配 errno: -1, errorFunction: 'Remote.push' }
这是我第一次尝试以编程方式使用 git 所以我可能会遗漏一些基本的东西......
回答评论中的一些问题:
而不是使用git.Cred.sshKeyFromAgent
- 您可以使用git.Cred.sshKeyNew
并传递您的用户名/密钥。
const fs = require('fs');
// ...
const username = "git";
const publickey = fs.readFileSync("PATH TO PUBLIC KEY").toString();
const privatekey = fs.readFileSync("PATH TO PRIVATE KEY").toString();
const passphrase = "YOUR PASSPHRASE IF THE KEY HAS ONE";
const cred = await Git.Cred.sshKeyMemoryNew(username, publickey, privatekey, passphrase);
const remote = await repository.getRemote("origin");
await remote.push(["refs/head/master:refs/heads/master"], {
callbacks: {
credentials: (url, user) => cred
}
});
您需要在本地运行 ssh 代理并将您的密码保存在那里。 请按照以下步骤使其工作:
我希望这会有所帮助,因为我也为此付出了很多努力,这可能会非常令人沮丧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.