refactor: remove dead code
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful

This commit is contained in:
Paul Campbell 2024-06-28 20:40:34 +01:00
parent f918394703
commit 63ff626eab
7 changed files with 31 additions and 94 deletions

View file

@ -34,20 +34,10 @@ pub enum Repository {
Test(TestRepository), Test(TestRepository),
} }
#[deprecated(note = "use git::repository::real()")]
pub const fn new() -> Repository {
Repository::Real
}
pub const fn test(fs: kxio::fs::FileSystem) -> TestRepository { pub const fn test(fs: kxio::fs::FileSystem) -> TestRepository {
TestRepository::new(false, fs, vec![], vec![]) TestRepository::new(fs, vec![], vec![])
} }
// #[cfg(test)]
// pub const fn test_bare(fs: kxio::fs::FileSystem) -> TestRepository {
// TestRepository::new(true, fs, vec![], vec![])
// }
/// Opens a repository, cloning if necessary /// Opens a repository, cloning if necessary
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
#[cfg(not(tarpaulin_include))] // requires network access to either clone new and/or fetch. #[cfg(not(tarpaulin_include))] // requires network access to either clone new and/or fetch.
@ -86,6 +76,8 @@ pub fn mock() -> Box<MockRepositoryFactory> {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct RealRepositoryFactory; struct RealRepositoryFactory;
#[cfg(not(tarpaulin_include))] // requires network access to either clone new and/or fetch.
impl RepositoryFactory for RealRepositoryFactory { impl RepositoryFactory for RealRepositoryFactory {
fn open(&self, gitdir: &GitDir) -> Result<Box<dyn OpenRepositoryLike>> { fn open(&self, gitdir: &GitDir) -> Result<Box<dyn OpenRepositoryLike>> {
let gix_repo = gix::ThreadSafeRepository::open(gitdir.to_path_buf())?.to_thread_local(); let gix_repo = gix::ThreadSafeRepository::open(gitdir.to_path_buf())?.to_thread_local();
@ -115,16 +107,16 @@ pub trait RepositoryLike {
fn open(&self, gitdir: &GitDir) -> Result<OpenRepository>; fn open(&self, gitdir: &GitDir) -> Result<OpenRepository>;
fn git_clone(&self, repo_details: &RepoDetails) -> Result<OpenRepository>; fn git_clone(&self, repo_details: &RepoDetails) -> Result<OpenRepository>;
} }
impl std::ops::Deref for Repository { // impl std::ops::Deref for Repository {
type Target = dyn RepositoryLike; // type Target = dyn RepositoryLike;
//
fn deref(&self) -> &Self::Target { // fn deref(&self) -> &Self::Target {
match self { // match self {
Self::Real => &real::RealRepository, // Self::Real => &real::RealRepository,
Self::Test(test_repository) => test_repository, // Self::Test(test_repository) => test_repository,
} // }
} // }
} // }
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum Direction { pub enum Direction {

View file

@ -1,10 +1,8 @@
// //
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub mod oreal; pub mod oreal;
pub mod otest; pub mod otest;
#[cfg(test)] #[cfg(test)]
@ -39,6 +37,7 @@ pub enum OpenRepository {
Test(TestOpenRepository), Test(TestOpenRepository),
} }
#[cfg(not(tarpaulin_include))]
pub fn real(gix_repo: gix::Repository) -> OpenRepository { pub fn real(gix_repo: gix::Repository) -> OpenRepository {
OpenRepository::Real(oreal::RealOpenRepository::new(Arc::new(Mutex::new( OpenRepository::Real(oreal::RealOpenRepository::new(Arc::new(Mutex::new(
gix_repo, gix_repo,
@ -55,16 +54,6 @@ pub fn test(
OpenRepository::Test(TestOpenRepository::new(gitdir, fs, on_fetch, on_push)) OpenRepository::Test(TestOpenRepository::new(gitdir, fs, on_fetch, on_push))
} }
#[cfg(not(tarpaulin_include))] // don't test mocks
pub fn test_bare(
gitdir: &config::GitDir,
fs: kxio::fs::FileSystem,
on_fetch: Vec<otest::OnFetch>,
on_push: Vec<otest::OnPush>,
) -> OpenRepository {
OpenRepository::Test(TestOpenRepository::new_bare(gitdir, fs, on_fetch, on_push))
}
#[mockall::automock] #[mockall::automock]
pub trait OpenRepositoryLike: std::fmt::Debug + Sync { pub trait OpenRepositoryLike: std::fmt::Debug + Sync {
fn duplicate(&self) -> Box<dyn OpenRepositoryLike>; fn duplicate(&self) -> Box<dyn OpenRepositoryLike>;

View file

@ -156,24 +156,6 @@ impl TestOpenRepository {
real: git::repository::RealOpenRepository::new(Arc::new(Mutex::new(gix))), real: git::repository::RealOpenRepository::new(Arc::new(Mutex::new(gix))),
} }
} }
pub fn new_bare(
gitdir: &config::GitDir,
fs: kxio::fs::FileSystem,
on_fetch: Vec<OnFetch>,
on_push: Vec<OnPush>,
) -> Self {
let pathbuf = fs.base().join(gitdir.to_path_buf());
#[allow(clippy::expect_used)]
let gix = gix::init_bare(pathbuf).expect("git init bare");
Self::write_origin(gitdir, &fs);
Self {
on_fetch,
fetch_counter: Arc::new(RwLock::new(0)),
on_push,
push_counter: Arc::new(RwLock::new(0)),
real: git::repository::RealOpenRepository::new(Arc::new(Mutex::new(gix))),
}
}
fn write_origin(gitdir: &config::GitDir, fs: &kxio::fs::FileSystem) { fn write_origin(gitdir: &config::GitDir, fs: &kxio::fs::FileSystem) {
let config_file = fs.base().join(gitdir.to_path_buf()).join(".git/config"); let config_file = fs.base().join(gitdir.to_path_buf()).join(".git/config");

View file

@ -287,27 +287,6 @@ mod forge_config {
} }
} }
// mod remote_branches {
// use super::*;
// #[test]
// // assumes running in the git-next repo which should have main, next and dev as remote branches
// fn should_return_remote_branches() -> TestResult {
// let_assert!(Ok(fs) = kxio::fs::temp());
// let gitdir: config::GitDir = fs.base().to_path_buf().into();
// let test_repository = git::repository::test(fs.clone());
// let_assert!(Ok(open_repository) = test_repository.open(&gitdir));
// let repo_config = &given::a_repo_config();
// let branches = repo_config.branches();
// then::create_a_commit_on_branch(&fs, &gitdir, &branches.main())?;
// then::create_a_commit_on_branch(&fs, &gitdir, &branches.next())?;
// then::create_a_commit_on_branch(&fs, &gitdir, &branches.dev())?;
// let_assert!(Ok(remote_branches) = open_repository.remote_branches());
// assert!(remote_branches.contains(&branches.main()));
// assert!(remote_branches.contains(&branches.next()));
// assert!(remote_branches.contains(&branches.dev()));
// Ok(())
// }
// }
mod find_default_remote { mod find_default_remote {
use super::*; use super::*;

View file

@ -1,4 +1,5 @@
// //
#![cfg(not(tarpaulin_include))]
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use crate as git; use crate as git;
@ -13,7 +14,6 @@ impl git::repository::RepositoryLike for RealRepository {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
#[cfg(not(tarpaulin_include))] // requires external server
fn git_clone( fn git_clone(
&self, &self,
repo_details: &git::RepoDetails, repo_details: &git::RepoDetails,

View file

@ -7,7 +7,6 @@ use git_next_config as config;
#[derive(Clone, Debug, Constructor)] #[derive(Clone, Debug, Constructor)]
pub struct TestRepository { pub struct TestRepository {
is_bare: bool,
fs: kxio::fs::FileSystem, fs: kxio::fs::FileSystem,
on_fetch: Vec<git::repository::open::otest::OnFetch>, on_fetch: Vec<git::repository::open::otest::OnFetch>,
on_push: Vec<git::repository::open::otest::OnPush>, on_push: Vec<git::repository::open::otest::OnPush>,
@ -20,28 +19,15 @@ impl TestRepository {
pub fn on_push(&mut self, on_push: git::repository::OnPush) { pub fn on_push(&mut self, on_push: git::repository::OnPush) {
self.on_push.push(on_push); self.on_push.push(on_push);
} }
pub const fn fs(&self) -> &kxio::fs::FileSystem {
&self.fs
}
} }
impl RepositoryLike for TestRepository { impl RepositoryLike for TestRepository {
fn open(&self, gitdir: &config::GitDir) -> super::Result<crate::OpenRepository> { fn open(&self, gitdir: &config::GitDir) -> super::Result<crate::OpenRepository> {
if self.is_bare { Ok(git::repository::open::test(
Ok(git::repository::open::test_bare( gitdir,
gitdir, self.fs.clone(),
self.fs.clone(), self.on_fetch.clone(),
self.on_fetch.clone(), self.on_push.clone(),
self.on_push.clone(), ))
))
} else {
Ok(git::repository::open::test(
gitdir,
self.fs.clone(),
self.on_fetch.clone(),
self.on_push.clone(),
))
}
} }
fn git_clone( fn git_clone(

View file

@ -51,7 +51,16 @@ pub fn validate_positions(
}); });
} }
// verify that next is on main or at most one commit on top of main, else reset it back to main // verify that next is on main or at most one commit on top of main, else reset it back to main
if is_not_based_on(&commit_histories.next[0..=1], &main) { if is_not_based_on(
commit_histories
.next
.iter()
.take(2)
.cloned()
.collect::<Vec<_>>()
.as_slice(),
&main,
) {
tracing::info!("Main not on same commit as next, or it's parent - resetting next to main",); tracing::info!("Main not on same commit as next, or it's parent - resetting next to main",);
return reset_next_to_main(open_repository, repo_details, &main, &next, &next_branch); return reset_next_to_main(open_repository, repo_details, &main, &next, &next_branch);
} }