1use std::path::Path;
2
3use crate::CommandError;
4use crate::url::Remote;
5
6#[must_use]
8pub fn new() -> Fetch<'static> {
9 Fetch::new()
10}
11
12#[derive(Debug)]
16pub struct Fetch<'a> {
17 repo_path: Option<&'a Path>,
18 all: bool,
19 porcelain: bool,
20 remote: Option<&'a Remote>,
21}
22
23crate::impl_repo_path!(Fetch);
24crate::impl_porcelain!(Fetch);
25
26impl<'a> Fetch<'a> {
27 #[must_use]
28 fn new() -> Self {
29 Self {
30 repo_path: None,
31 all: false,
32 porcelain: false,
33 remote: None,
34 }
35 }
36
37 crate::flag_methods! {
38 pub fn all / all_if, all, "Conditionally fetch all remotes."
42 }
43
44 #[must_use]
46 pub fn remote(mut self, remote: &'a Remote) -> Self {
47 self.remote = Some(remote);
48 self
49 }
50
51 pub async fn status(self) -> Result<(), CommandError> {
53 crate::Build::build(self).status().await
54 }
55}
56
57impl Default for Fetch<'_> {
58 fn default() -> Self {
59 Self::new()
60 }
61}
62
63impl crate::Build for Fetch<'_> {
64 fn build(self) -> cmd_proc::Command {
65 crate::base_command(self.repo_path)
66 .argument("fetch")
67 .optional_flag(self.all, "--all")
68 .optional_flag(self.porcelain, "--porcelain")
69 .optional_argument(self.remote)
70 }
71}
72
73#[cfg(feature = "test-utils")]
74impl Fetch<'_> {
75 pub fn test_eq(&self, other: &cmd_proc::Command) {
77 let command = crate::Build::build(Self {
78 repo_path: self.repo_path,
79 all: self.all,
80 porcelain: self.porcelain,
81 remote: self.remote,
82 });
83 command.test_eq(other);
84 }
85}