From d9feaeaa7b06f7bdbf5988199a283eb6a7b4a6d9 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 5 Jul 2024 19:23:12 +0100 Subject: [PATCH] chore: remove unused FakeOpenRepository --- crates/git/src/repository/open/mod.rs | 5 - crates/git/src/repository/open/ofake.rs | 121 ------------------------ 2 files changed, 126 deletions(-) delete mode 100644 crates/git/src/repository/open/ofake.rs diff --git a/crates/git/src/repository/open/mod.rs b/crates/git/src/repository/open/mod.rs index da471f4..3b3f978 100644 --- a/crates/git/src/repository/open/mod.rs +++ b/crates/git/src/repository/open/mod.rs @@ -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; diff --git a/crates/git/src/repository/open/ofake.rs b/crates/git/src/repository/open/ofake.rs deleted file mode 100644 index 148970d..0000000 --- a/crates/git/src/repository/open/ofake.rs +++ /dev/null @@ -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>>, - default_fetch_remote: Arc>>, - operations: Arc>>, -} -impl FakeOpenRepository { - pub fn new() -> Self { - Self::default() - } - pub fn given_has_default_remote( - &mut self, - direction: git::repository::Direction, - remote: Option, - ) { - #[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 { - 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> { - todo!("MockOpenRepository::remote_branched") - } - fn find_default_remote(&self, direction: git::repository::Direction) -> Option { - 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, git::commit::log::Error> { - todo!("MockOpenRepository::commit_log") - } - - fn read_file( - &self, - _branch_name: &git_next_config::BranchName, - _file_name: &Path, - ) -> git::file::Result { - todo!("MockOpenRepository::read_file") - } - - fn duplicate(&self) -> Box { - Box::new(self.clone()) - } -}