1use crate::repository::Remote;
2
3#[must_use]
5pub fn new() -> Fetch<'static> {
6 Fetch::new()
7}
8
9#[derive(Debug)]
13pub struct Fetch<'a> {
14 base: crate::RepoBase<'a>,
15 all: bool,
16 porcelain: bool,
17 remote: Option<&'a Remote>,
18}
19
20crate::impl_repo_base!(Fetch);
21crate::impl_porcelain!(Fetch);
22
23impl<'a> Fetch<'a> {
24 #[must_use]
25 fn new() -> Self {
26 Self {
27 base: crate::RepoBase::default(),
28 all: false,
29 porcelain: false,
30 remote: None,
31 }
32 }
33
34 crate::flag_methods! {
35 pub fn all / all_if, all, "Conditionally fetch all remotes."
39 }
40
41 #[must_use]
43 pub fn remote(mut self, remote: &'a Remote) -> Self {
44 self.remote = Some(remote);
45 self
46 }
47
48 pub async fn status(self) -> Result<(), crate::Error> {
50 Ok(crate::Build::build(self)?.status().await?)
51 }
52}
53
54impl Default for Fetch<'_> {
55 fn default() -> Self {
56 Self::new()
57 }
58}
59
60impl crate::Build for Fetch<'_> {
61 fn build(self) -> Result<cmd_proc::Command, crate::EnvError> {
62 Ok(self
63 .base
64 .command()?
65 .argument("fetch")
66 .optional_flag(self.all, "--all")
67 .optional_flag(self.porcelain, "--porcelain")
68 .optional_argument(self.remote))
69 }
70}
71
72#[cfg(feature = "test-utils")]
73impl Fetch<'_> {
74 pub fn test_eq(&self, other: &cmd_proc::Command) {
76 let command = crate::Build::build(Self {
77 base: self.base,
78 all: self.all,
79 porcelain: self.porcelain,
80 remote: self.remote,
81 })
82 .unwrap();
83 command.test_eq(other);
84 }
85}