git-next/crates/git/src/fetch.rs

37 lines
1.1 KiB
Rust
Raw Normal View History

use std::ops::Deref;
use tracing::{debug, info};
use super::{RepoDetails, Repository};
#[derive(Debug, derive_more::From, derive_more::Display)]
pub enum Error {
UnableToOpenRepo(Box<gix::open::Error>),
NoFetchRemoteFound,
Connect(Box<gix::remote::connect::Error>),
Fetch(String),
}
impl std::error::Error for Error {}
#[tracing::instrument(skip_all, fields(repo = %repo_details))]
pub fn fetch(repository: &Repository, repo_details: &RepoDetails) -> Result<(), Error> {
let repository = repository.deref().to_thread_local();
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(())
}