chore: remove unused FakeOpenRepository

This commit is contained in:
Paul Campbell 2024-07-05 19:23:12 +01:00
parent 2e374d317a
commit d9feaeaa7b
2 changed files with 0 additions and 126 deletions

View file

@ -5,9 +5,6 @@ mod tests;
pub mod oreal;
pub mod otest;
#[cfg(test)]
pub mod ofake;
use std::{
path::Path,
sync::{Arc, RwLock},
@ -16,8 +13,6 @@ use std::{
use crate as git;
use git::repository::Direction;
use git_next_config as config;
#[cfg(test)]
pub use ofake::FakeOpenRepository;
pub use oreal::RealOpenRepository;
pub use otest::TestOpenRepository;

View file

@ -1,121 +0,0 @@
//
use crate::{self as git, repository::OpenRepositoryLike};
use git_next_config as config;
use std::{
path::Path,
sync::{Arc, RwLock},
};
#[derive(Clone, Debug, Default)]
pub struct FakeOpenRepository {
default_push_remote: Arc<RwLock<Option<git::GitRemote>>>,
default_fetch_remote: Arc<RwLock<Option<git::GitRemote>>>,
operations: Arc<RwLock<Vec<String>>>,
}
impl FakeOpenRepository {
pub fn new() -> Self {
Self::default()
}
pub fn given_has_default_remote(
&mut self,
direction: git::repository::Direction,
remote: Option<git::GitRemote>,
) {
#[allow(clippy::unwrap_used)]
match direction {
git::repository::Direction::Push => self
.default_push_remote
.write()
.map(|mut o| match remote {
Some(gr) => o.replace(gr),
None => o.take(),
})
.unwrap(),
git::repository::Direction::Fetch => self
.default_fetch_remote
.write()
.map(|mut o| match remote {
Some(gr) => o.replace(gr),
None => o.take(),
})
.unwrap(),
};
}
pub fn operations(&self) -> Vec<String> {
self.operations
.read()
.map(|operations| operations.clone())
.unwrap_or_default()
}
}
#[allow(clippy::unwrap_used)]
impl git::repository::OpenRepositoryLike for FakeOpenRepository {
fn remote_branches(&self) -> git::push::Result<Vec<config::BranchName>> {
todo!("MockOpenRepository::remote_branched")
}
fn find_default_remote(&self, direction: git::repository::Direction) -> Option<git::GitRemote> {
match direction {
git::repository::Direction::Push => self
.default_push_remote
.read()
.map(|r| r.clone())
.unwrap_or(None),
git::repository::Direction::Fetch => self
.default_fetch_remote
.read()
.map(|r| r.clone())
.unwrap_or(None),
}
}
fn fetch(&self) -> core::result::Result<(), crate::fetch::Error> {
self.operations
.write()
.map_err(|_| crate::fetch::Error::Lock)
.map(|mut operations| operations.push("fetch".to_string()))?;
Ok(())
}
fn push(
&self,
repo_details: &git::RepoDetails,
branch_name: &git_next_config::BranchName,
to_commit: &crate::GitRef,
force: &crate::push::Force,
) -> core::result::Result<(), crate::push::Error> {
let forge_alias = repo_details.forge.forge_alias();
let repo_alias = &repo_details.repo_alias;
self.operations
.write()
.map_err(|_| crate::fetch::Error::Lock)
.map(|mut operations| {
operations.push(format!(
"push fa:{forge_alias} ra:{repo_alias} bn:{branch_name} tc:{to_commit} f:{force}"
))
})?;
Ok(())
}
fn commit_log(
&self,
_branch_name: &git_next_config::BranchName,
_find_commits: &[git::Commit],
) -> core::result::Result<Vec<crate::Commit>, git::commit::log::Error> {
todo!("MockOpenRepository::commit_log")
}
fn read_file(
&self,
_branch_name: &git_next_config::BranchName,
_file_name: &Path,
) -> git::file::Result<String> {
todo!("MockOpenRepository::read_file")
}
fn duplicate(&self) -> Box<dyn OpenRepositoryLike> {
Box::new(self.clone())
}
}