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