// mod mock; mod open; mod real; #[cfg(test)] mod tests; use git_next_config::GitDir; pub use open::OpenRepository; use crate::repository::mock::MockRepository; use super::RepoDetails; #[derive(Clone, Debug)] pub enum Repository { Real, Mock(MockRepository), } pub const fn new() -> Repository { Repository::Real } pub fn mock() -> (Repository, MockRepository) { let mock_repository = MockRepository::new(); (Repository::Mock(mock_repository.clone()), mock_repository) } pub trait RepositoryLike { fn open(&self, gitdir: &GitDir) -> Result; fn git_clone(&self, repo_details: &RepoDetails) -> Result; } impl std::ops::Deref for Repository { type Target = dyn RepositoryLike; fn deref(&self) -> &Self::Target { match self { Self::Real => &real::RealRepository, Self::Mock(mock_repository) => mock_repository, } } } #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Direction { /// Push local changes to the remote. Push, /// Fetch changes from the remote to the local repository. Fetch, } impl From for gix::remote::Direction { fn from(value: Direction) -> Self { match value { Direction::Push => Self::Push, Direction::Fetch => Self::Fetch, } } } pub type Result = core::result::Result; #[derive(Debug, derive_more::Display)] pub enum Error { InvalidGitDir(git_next_config::GitDir), Io(std::io::Error), Wait(std::io::Error), Spawn(std::io::Error), Validation(String), Clone(String), Open(String), Fetch(String), MockLock, } impl std::error::Error for Error {} mod gix_errors { #![cfg(not(tarpaulin_include))] // third-party library errors use super::Error; impl From for Error { fn from(value: gix::clone::Error) -> Self { Self::Clone(value.to_string()) } } impl From for Error { fn from(value: gix::open::Error) -> Self { Self::Open(value.to_string()) } } impl From for Error { fn from(value: gix::clone::fetch::Error) -> Self { Self::Fetch(value.to_string()) } } }