diff --git a/crates/git/src/branch.rs b/crates/git/src/branch.rs deleted file mode 100644 index cfa7100..0000000 --- a/crates/git/src/branch.rs +++ /dev/null @@ -1,37 +0,0 @@ -// -use crate as git; -use git_next_config as config; - -pub type Result = core::result::Result; - -#[derive(Debug, thiserror::Error)] -pub enum Error { - #[error("network: {0}")] - Network(#[from] kxio::network::NetworkError), - - #[error("fetch: {0}")] - Fetch(#[from] git::fetch::Error), - - #[error("push: {0}")] - Push(#[from] git::push::Error), - - #[error("lock")] - Lock, - - #[error("gix iter: {0}")] - GixIter(#[from] gix::reference::iter::Error), - - #[error("gix iter init: {0}")] - GixIterInit(#[from] gix::reference::iter::init::Error), -} - -pub fn reset( - repository: &git::OpenRepository, - repo_details: &git::RepoDetails, - branch_name: config::BranchName, - to_commit: git::GitRef, - force: git::push::Force, -) -> Result<()> { - repository.fetch()?; - Ok(repository.push(repo_details, branch_name, to_commit, force)?) -} diff --git a/crates/git/src/lib.rs b/crates/git/src/lib.rs index 739a11e..db926a5 100644 --- a/crates/git/src/lib.rs +++ b/crates/git/src/lib.rs @@ -1,5 +1,4 @@ // -pub mod branch; pub mod commit; pub mod common; pub mod fetch; diff --git a/crates/git/src/push.rs b/crates/git/src/push.rs index a4eb3ed..4490ff3 100644 --- a/crates/git/src/push.rs +++ b/crates/git/src/push.rs @@ -1,4 +1,6 @@ use super::GitRef; +use crate as git; +use git_next_config as config; #[derive(Debug)] pub enum Force { @@ -14,16 +16,39 @@ impl std::fmt::Display for Force { } } +pub type Result = core::result::Result; + #[derive(Debug, thiserror::Error)] pub enum Error { - #[error("gix open: {0}")] - Open(#[from] Box), + #[error("io")] + Io(#[from] std::io::Error), - #[error("io: {0}")] - Push(#[from] std::io::Error), + #[error("network: {0}")] + Network(#[from] kxio::network::NetworkError), + + #[error("fetch: {0}")] + Fetch(#[from] git::fetch::Error), #[error("lock")] Lock, + + #[error("gix open: {0}")] + Open(#[from] Box), + + #[error("gix iter: {0}")] + GixIter(#[from] gix::reference::iter::Error), + + #[error("gix iter init: {0}")] + GixIterInit(#[from] gix::reference::iter::init::Error), } -pub type Result = core::result::Result; +pub fn reset( + repository: &git::OpenRepository, + repo_details: &git::RepoDetails, + branch_name: config::BranchName, + to_commit: git::GitRef, + force: git::push::Force, +) -> Result<()> { + repository.fetch()?; + repository.push(repo_details, branch_name, to_commit, force) +} diff --git a/crates/git/src/repository/mock.rs b/crates/git/src/repository/mock.rs index da53d19..53110d6 100644 --- a/crates/git/src/repository/mock.rs +++ b/crates/git/src/repository/mock.rs @@ -109,7 +109,7 @@ impl InnerMockOpenRepository { #[allow(clippy::unwrap_used)] impl OpenRepositoryLike for MockOpenRepository { - fn remote_branches(&self) -> git::branch::Result> { + fn remote_branches(&self) -> git::push::Result> { self.inner .lock() .map(|inner| inner.remote_branches()) @@ -162,7 +162,7 @@ impl OpenRepositoryLike for MockOpenRepository { } } impl OpenRepositoryLike for InnerMockOpenRepository { - fn remote_branches(&self) -> git::branch::Result> { + fn remote_branches(&self) -> git::push::Result> { todo!(); } fn find_default_remote(&self, direction: Direction) -> Option { diff --git a/crates/git/src/repository/open/mod.rs b/crates/git/src/repository/open/mod.rs index 4d1c267..c440b37 100644 --- a/crates/git/src/repository/open/mod.rs +++ b/crates/git/src/repository/open/mod.rs @@ -28,7 +28,7 @@ impl OpenRepository { } } pub trait OpenRepositoryLike { - fn remote_branches(&self) -> git::branch::Result>; + fn remote_branches(&self) -> git::push::Result>; fn find_default_remote(&self, direction: Direction) -> Option; fn fetch(&self) -> Result<(), git::fetch::Error>; fn push( diff --git a/crates/git/src/repository/open/oreal.rs b/crates/git/src/repository/open/oreal.rs index 7206947..0dd8b42 100644 --- a/crates/git/src/repository/open/oreal.rs +++ b/crates/git/src/repository/open/oreal.rs @@ -10,11 +10,11 @@ use tracing::{info, warn}; #[derive(Clone, Debug, derive_more::Constructor)] pub struct RealOpenRepository(Arc>); impl super::OpenRepositoryLike for RealOpenRepository { - fn remote_branches(&self) -> git::branch::Result> { + fn remote_branches(&self) -> git::push::Result> { let refs = self .0 .lock() - .map_err(|_| git::branch::Error::Lock) + .map_err(|_| git::push::Error::Lock) .and_then(|repo| { Ok(repo.references()?).and_then(|refs| { Ok(refs.remote_branches().map(|rb| { diff --git a/crates/git/src/validation/positions.rs b/crates/git/src/validation/positions.rs index 70610b0..af29a66 100644 --- a/crates/git/src/validation/positions.rs +++ b/crates/git/src/validation/positions.rs @@ -66,7 +66,7 @@ pub fn validate_positions( let next_is_ancestor_of_dev = commit_histories.dev.iter().any(|dev| dev == &next); if !next_is_ancestor_of_dev { info!("Next is not an ancestor of dev - resetting next to main"); - if let Err(err) = git::branch::reset( + if let Err(err) = git::push::reset( repository, repo_details, repo_config.branches().next(), @@ -96,7 +96,7 @@ pub fn validate_positions( repo_config.branches().main(), repo_config.branches().next() ); - if let Err(err) = git::branch::reset( + if let Err(err) = git::push::reset( repository, repo_details, repo_config.branches().next(), diff --git a/crates/repo-actor/src/branch.rs b/crates/repo-actor/src/branch.rs index 5ca7084..9efbf73 100644 --- a/crates/repo-actor/src/branch.rs +++ b/crates/repo-actor/src/branch.rs @@ -30,7 +30,7 @@ pub async fn advance_next( return; } info!("Advancing next to commit '{}'", commit); - if let Err(err) = git::branch::reset( + if let Err(err) = git::push::reset( &repository, &repo_details, repo_config.branches().next(), @@ -84,7 +84,7 @@ pub async fn advance_main( repository: &git::OpenRepository, ) { info!("Advancing main to next"); - if let Err(err) = git::branch::reset( + if let Err(err) = git::push::reset( repository, repo_details, repo_config.branches().main(), diff --git a/crates/repo-actor/src/load.rs b/crates/repo-actor/src/load.rs index e24e14d..510db4a 100644 --- a/crates/repo-actor/src/load.rs +++ b/crates/repo-actor/src/load.rs @@ -42,7 +42,7 @@ pub enum Error { File(git::file::Error), Config(config::server::Error), Toml(toml::de::Error), - Branch(git::branch::Error), + Branch(git::push::Error), BranchNotFound(config::BranchName), }