1use git2::{Error, FetchOptions, Oid, Repository};
2
3use crate::auth::auth_callbacks;
4
5pub fn repo_fetch(
9 repo: &Repository,
10 remote_name: &str,
11 branch_name: &str,
12 username: &str,
13 password: &str,
14) -> Result<Oid, Error> {
15 let mut remote = repo.find_remote(remote_name)?;
16
17 let mut fetch_options = FetchOptions::new();
18 let callbacks = auth_callbacks(username, password);
19 fetch_options.remote_callbacks(callbacks);
20
21 remote.fetch(
24 &[&format!("refs/heads/{branch_name}")],
25 Some(&mut fetch_options),
26 None,
27 )?;
28
29 let obj = repo.revparse_single(&format!("refs/remotes/{remote_name}/{branch_name}"))?;
32
33 Ok(obj.id())
34}