git-next/crates/git/src/push.rs
Paul Campbell ffab1986a7
Some checks failed
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
Rust / build (push) Has been cancelled
ci/woodpecker/push/tag-created Pipeline was successful
refactor: repo-actor: rewrite tests using mockall
2024-06-27 18:58:47 +01:00

58 lines
1.4 KiB
Rust

use super::GitRef;
use crate as git;
use git_next_config as config;
#[derive(Debug, PartialEq, Eq)]
pub enum Force {
No,
From(GitRef),
}
impl std::fmt::Display for Force {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::No => write!(f, "fast-forward"),
Self::From(from) => write!(f, "force-if-from:{}", from),
}
}
}
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("io")]
Io(#[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<gix::open::Error>),
#[error("gix iter: {0}")]
GixIter(#[from] gix::reference::iter::Error),
#[error("gix iter init: {0}")]
GixIterInit(#[from] gix::reference::iter::init::Error),
#[cfg(test)]
#[error("test")]
TestResult(#[from] Box<dyn std::error::Error>),
}
pub fn reset(
open_repository: &dyn git::repository::OpenRepositoryLike,
repo_details: &git::RepoDetails,
branch_name: &config::BranchName,
to_commit: &git::GitRef,
force: &git::push::Force,
) -> Result<()> {
open_repository.fetch()?;
open_repository.push(repo_details, branch_name, to_commit, force)
}