#[cfg(test)]
mod tests;
pub mod oreal;
pub mod otest;
use crate::{
git,
git::repository::{
open::{oreal::RealOpenRepository, otest::TestOpenRepository},
Direction,
},
BranchName, GitDir, RemoteUrl,
};
use std::{
path::Path,
sync::{Arc, RwLock},
};
#[allow(clippy::module_name_repetitions)]
#[derive(Clone, Debug)]
pub enum OpenRepository {
Real(RealOpenRepository),
Test(TestOpenRepository),
}
#[cfg(not(tarpaulin_include))]
pub fn real(gix_repo: gix::Repository, forge_details: crate::ForgeDetails) -> OpenRepository {
OpenRepository::Real(oreal::RealOpenRepository::new(
Arc::new(RwLock::new(gix_repo.into())),
forge_details,
))
}
#[cfg(not(tarpaulin_include))] pub(crate) fn test(
gitdir: &GitDir,
fs: &kxio::fs::FileSystem,
on_fetch: Vec<otest::OnFetch>,
on_push: Vec<otest::OnPush>,
forge_details: crate::ForgeDetails,
) -> OpenRepository {
OpenRepository::Test(TestOpenRepository::new(
gitdir,
fs,
on_fetch,
on_push,
forge_details,
))
}
#[allow(clippy::module_name_repetitions)]
#[mockall::automock]
pub trait OpenRepositoryLike: std::fmt::Debug + Sync + Send {
fn duplicate(&self) -> Box<dyn OpenRepositoryLike>;
fn remote_branches(&self) -> git::push::Result<Vec<BranchName>>;
fn find_default_remote(&self, direction: Direction) -> Option<RemoteUrl>;
fn fetch(&self) -> Result<(), git::fetch::Error>;
fn push(
&self,
repo_details: &git::RepoDetails,
branch_name: &BranchName,
to_commit: &git::GitRef,
force: &git::push::Force,
) -> git::push::Result<()>;
fn commit_log(
&self,
branch_name: &BranchName,
find_commits: &[git::Commit],
) -> git::commit::log::Result<Vec<git::Commit>>;
fn read_file(&self, branch_name: &BranchName, file_name: &Path) -> git::file::Result<String>;
}
#[cfg(test)]
pub(crate) fn mock() -> Box<MockOpenRepositoryLike> {
Box::new(MockOpenRepositoryLike::new())
}
impl std::ops::Deref for OpenRepository {
type Target = dyn OpenRepositoryLike;
fn deref(&self) -> &Self::Target {
match self {
Self::Real(real) => real,
Self::Test(test) => test,
}
}
}