#[cfg(test)]
mod tests;
pub mod oreal;
pub mod otest;
use std::{
path::Path,
sync::{Arc, RwLock},
};
use crate as git;
use git::repository::Direction;
use git_next_config::{self as config, RemoteUrl};
pub use oreal::RealOpenRepository;
pub use otest::TestOpenRepository;
#[derive(Clone, Debug)]
pub enum OpenRepository {
Real(RealOpenRepository),
Test(TestOpenRepository),
}
#[cfg(not(tarpaulin_include))]
pub fn real(gix_repo: gix::Repository) -> OpenRepository {
OpenRepository::Real(oreal::RealOpenRepository::new(Arc::new(RwLock::new(
gix_repo.into(),
))))
}
#[cfg(not(tarpaulin_include))] pub fn test(
gitdir: &config::GitDir,
fs: kxio::fs::FileSystem,
on_fetch: Vec<otest::OnFetch>,
on_push: Vec<otest::OnPush>,
) -> OpenRepository {
OpenRepository::Test(TestOpenRepository::new(gitdir, fs, on_fetch, on_push))
}
#[mockall::automock]
pub trait OpenRepositoryLike: std::fmt::Debug + Sync {
fn duplicate(&self) -> Box<dyn OpenRepositoryLike>;
fn remote_branches(&self) -> git::push::Result<Vec<config::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: &config::BranchName,
to_commit: &git::GitRef,
force: &git::push::Force,
) -> git::push::Result<()>;
fn commit_log(
&self,
branch_name: &config::BranchName,
find_commits: &[git::Commit],
) -> git::commit::log::Result<Vec<git::Commit>>;
fn read_file(
&self,
branch_name: &config::BranchName,
file_name: &Path,
) -> git::file::Result<String>;
}
pub 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,
}
}
}