use std::ops::Deref; use tracing::{debug, info}; use crate::server::config::RepoDetails; #[derive(Debug, derive_more::From, derive_more::Display)] pub enum Error { UnableToOpenRepo(Box), NoFetchRemoteFound, Connect(Box), Fetch(String), } impl std::error::Error for Error {} #[tracing::instrument(skip_all, fields(repo = %repo_details))] pub fn fetch(repo_details: &RepoDetails) -> Result<(), Error> { // INFO: gitdir validate tests that the default fetch remote matches the configured remote let repository = gix::ThreadSafeRepository::open(repo_details.gitdir.deref()) .map_err(Box::new)? .to_thread_local(); debug!(?repository, "opened repo"); let Some(remote) = repository.find_default_remote(gix::remote::Direction::Fetch) else { return Err(Error::NoFetchRemoteFound); }; debug!(?remote, "fetch remote"); remote .map_err(|e| Error::Fetch(e.to_string()))? .connect(gix::remote::Direction::Fetch) .map_err(Box::new)? .prepare_fetch(gix::progress::Discard, Default::default()) .map_err(|e| Error::Fetch(e.to_string()))? .receive(gix::progress::Discard, &Default::default()) .map_err(|e| Error::Fetch(e.to_string()))?; info!("fetched"); Ok(()) }