refactor: remove dead code
All checks were successful
Rust / build (push) Successful in 1m16s
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 f460cd4b49
commit 6d9eb0ab86
7 changed files with 31 additions and 94 deletions

View file

@ -34,20 +34,10 @@ pub enum Repository {
Test(TestRepository),
}
#[deprecated(note = "use git::repository::real()")]
pub const fn new() -> Repository {
Repository::Real
}
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
#[tracing::instrument(skip_all)]
#[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)]
struct RealRepositoryFactory;
#[cfg(not(tarpaulin_include))] // requires network access to either clone new and/or fetch.
impl RepositoryFactory for RealRepositoryFactory {
fn open(&self, gitdir: &GitDir) -> Result<Box<dyn OpenRepositoryLike>> {
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 git_clone(&self, repo_details: &RepoDetails) -> Result<OpenRepository>;
}
impl std::ops::Deref for Repository {
type Target = dyn RepositoryLike;
fn deref(&self) -> &Self::Target {
match self {
Self::Real => &real::RealRepository,
Self::Test(test_repository) => test_repository,
}
}
}
// impl std::ops::Deref for Repository {
// type Target = dyn RepositoryLike;
//
// fn deref(&self) -> &Self::Target {
// match self {
// Self::Real => &real::RealRepository,
// Self::Test(test_repository) => test_repository,
// }
// }
// }
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum Direction {

View file

@ -1,10 +1,8 @@
//
#[cfg(test)]
mod tests;
pub mod oreal;
pub mod otest;
#[cfg(test)]
@ -39,6 +37,7 @@ pub enum OpenRepository {
Test(TestOpenRepository),
}
#[cfg(not(tarpaulin_include))]
pub fn real(gix_repo: gix::Repository) -> OpenRepository {
OpenRepository::Real(oreal::RealOpenRepository::new(Arc::new(Mutex::new(
gix_repo,
@ -55,16 +54,6 @@ pub fn test(
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]
pub trait OpenRepositoryLike: std::fmt::Debug + Sync {
fn duplicate(&self) -> Box<dyn OpenRepositoryLike>;

View file

@ -156,24 +156,6 @@ impl TestOpenRepository {
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) {
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 {
use super::*;

View file

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

View file

@ -7,7 +7,6 @@ use git_next_config as config;
#[derive(Clone, Debug, Constructor)]
pub struct TestRepository {
is_bare: bool,
fs: kxio::fs::FileSystem,
on_fetch: Vec<git::repository::open::otest::OnFetch>,
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) {
self.on_push.push(on_push);
}
pub const fn fs(&self) -> &kxio::fs::FileSystem {
&self.fs
}
}
impl RepositoryLike for TestRepository {
fn open(&self, gitdir: &config::GitDir) -> super::Result<crate::OpenRepository> {
if self.is_bare {
Ok(git::repository::open::test_bare(
gitdir,
self.fs.clone(),
self.on_fetch.clone(),
self.on_push.clone(),
))
} else {
Ok(git::repository::open::test(
gitdir,
self.fs.clone(),
self.on_fetch.clone(),
self.on_push.clone(),
))
}
Ok(git::repository::open::test(
gitdir,
self.fs.clone(),
self.on_fetch.clone(),
self.on_push.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
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",);
return reset_next_to_main(open_repository, repo_details, &main, &next, &next_branch);
}