git_api/auth.rs
1use git2::{Cred, RemoteCallbacks};
2use macro_log::*;
3
4/// remote authentication required a callback
5pub fn auth_callbacks<'a>(username: &'a str, password: &'a str) -> RemoteCallbacks<'a> {
6 let mut callbacks = RemoteCallbacks::new();
7 callbacks.credentials(|url, username_from_url, allowed_types| {
8 d!("请求凭证: {url:?} {username_from_url:?} {allowed_types:?}");
9 // 替换成你的 Git 凭据(如果远程仓库需要认证)
10 Cred::userpass_plaintext(username, password)
11 });
12 callbacks
13}