use git2::{Error, FetchOptions, Oid, Repository};
use crate::auth::auth_callbacks;
pub fn repo_fetch(
repo: &Repository,
remote_name: &str,
branch_name: &str,
username: &str,
password: &str,
) -> Result<Oid, Error> {
let mut remote = repo.find_remote(remote_name)?;
let mut fetch_options = FetchOptions::new();
let callbacks = auth_callbacks(username, password);
fetch_options.remote_callbacks(callbacks);
remote.fetch(
&[&format!("refs/heads/{branch_name}")],
Some(&mut fetch_options),
None,
)?;
let obj = repo.revparse_single(&format!("refs/remotes/{remote_name}/{branch_name}"))?;
Ok(obj.id())
}