git-next/crates/core/src/git/push.rs
Paul Campbell 5d9915bdbd
All checks were successful
Rust / build (push) Successful in 14m16s
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Release Please / Release-plz (push) Successful in 1m3s
feat(tui): (experimental) show repo state, messages and git log
2024-08-25 15:59:42 +01:00

66 lines
1.7 KiB
Rust

//
use crate::{git, git::repository::open::OpenRepositoryLike, BranchName};
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Force {
No,
From(git::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>),
}
/// Resets the position of a branch in the remote repo
///
/// Performs a 'git fetch' first to ensure we have up-to-date branch positions before
/// performing `git push`.
///
/// # Errors
///
/// Will return an `Err` if their is no remote fetch defined in .git/config, or
/// if there are any network connectivity issues with the remote server.
pub fn reset(
open_repository: &dyn OpenRepositoryLike,
repo_details: &git::RepoDetails,
branch_name: &BranchName,
to_commit: &git::GitRef,
force: &git::push::Force,
) -> Result<()> {
open_repository.fetch()?;
open_repository.push(repo_details, branch_name, to_commit, force)
}