“尝试使用git2-rs / libgit2推送到远程时,请求失败,状态代码:401”错误>> [

问题描述 投票:0回答:1
我有一个本地git仓库,该仓库通过git2-rs进行维护,这是C库libgit2周围几乎一对一的Rust包装器。我已经设法使用该库暂存并提交更改。但是,我无法将更改推送到远程存储库。当我尝试连接到遥控器时,出现以下错误:

request failed with status code: 401

这是我的代码:

let repo: Repository = /* get repository */; let mut remote = repo.find_remote("origin").unwrap(); // connect returns Err, and so this panics. remote.connect(Direction::Push).unwrap();

我也尝试传递各种凭据,但是发生相同的错误:

let mut callbacks = RemoteCallbacks::new(); callbacks.credentials(|str, str_opt, cred_type| { Ok(Cred::userpass_plaintext("natanfudge", env!("GITHUB_PASSWORD")).unwrap()) }); remote .connect_auth(Direction::Push, Some(callbacks), None) .unwrap();

let mut callbacks = RemoteCallbacks::new();
callbacks.credentials(|str, str_opt, cred_type| {
    // This line does not panic, only the connect_auth!
    Ok(Cred::ssh_key_from_agent("natanfudge").expect("Could not get ssh key from ssh agent"))
});
remote
    .connect_auth(Direction::Push, Some(callbacks), None)
    .unwrap();
我想念什么?

我有一个本地git仓库,该仓库通过git2-rs进行维护,这是C库libgit2的一对一Rust封装器。我已经设法使用该库来暂存和提交更改。...

git authentication rust push libgit2
1个回答
1
投票
好,我解决了这个问题。要使其正常工作,需要完成三件事:
© www.soinside.com 2019 - 2024. All rights reserved.