use std::path::Path;
use crate::CommandError;
use crate::repository::Remote;
#[must_use]
pub fn new() -> Push<'static> {
Push::new()
}
#[derive(Debug)]
pub struct Push<'a> {
repo_path: Option<&'a Path>,
force: bool,
porcelain: bool,
remote: Option<&'a Remote>,
refspec: Option<&'a str>,
}
crate::impl_repo_path!(Push);
crate::impl_porcelain!(Push);
impl<'a> Push<'a> {
#[must_use]
fn new() -> Self {
Self {
repo_path: None,
force: false,
porcelain: false,
remote: None,
refspec: None,
}
}
crate::flag_methods! {
pub fn force / force_if, force, "Conditionally force push."
}
#[must_use]
pub fn remote(mut self, remote: &'a Remote) -> Self {
self.remote = Some(remote);
self
}
#[must_use]
pub fn refspec(mut self, refspec: &'a str) -> Self {
self.refspec = Some(refspec);
self
}
pub async fn status(self) -> Result<(), CommandError> {
crate::Build::build(self).status().await
}
}
impl Default for Push<'_> {
fn default() -> Self {
Self::new()
}
}
impl crate::Build for Push<'_> {
fn build(self) -> cmd_proc::Command {
crate::base_command(self.repo_path)
.argument("push")
.optional_flag(self.force, "--force")
.optional_flag(self.porcelain, "--porcelain")
.optional_argument(self.remote)
.optional_argument(self.refspec)
}
}
#[cfg(feature = "test-utils")]
impl Push<'_> {
pub fn test_eq(&self, other: &cmd_proc::Command) {
let command = crate::Build::build(Self {
repo_path: self.repo_path,
force: self.force,
porcelain: self.porcelain,
remote: self.remote,
refspec: self.refspec,
});
command.test_eq(other);
}
}