git_spawn/command/
fetch.rs1use crate::command::{CommandExecutor, CommandOutput, GitCommand};
4use crate::error::Result;
5use async_trait::async_trait;
6
7#[derive(Debug, Clone, Default)]
9pub struct FetchCommand {
10 pub executor: CommandExecutor,
12 pub remote: Option<String>,
14 pub refspec: Option<String>,
16 pub all: bool,
18 pub tags: bool,
20 pub no_tags: bool,
22 pub prune: bool,
24 pub depth: Option<u32>,
26 pub unshallow: bool,
28 pub quiet: bool,
30}
31
32impl FetchCommand {
33 #[must_use]
35 pub fn new() -> Self {
36 Self::default()
37 }
38 pub fn remote(&mut self, r: impl Into<String>) -> &mut Self {
40 self.remote = Some(r.into());
41 self
42 }
43 pub fn refspec(&mut self, r: impl Into<String>) -> &mut Self {
45 self.refspec = Some(r.into());
46 self
47 }
48 pub fn all(&mut self) -> &mut Self {
50 self.all = true;
51 self
52 }
53 pub fn tags(&mut self) -> &mut Self {
55 self.tags = true;
56 self
57 }
58 pub fn no_tags(&mut self) -> &mut Self {
60 self.no_tags = true;
61 self
62 }
63 pub fn prune(&mut self) -> &mut Self {
65 self.prune = true;
66 self
67 }
68 pub fn depth(&mut self, d: u32) -> &mut Self {
70 self.depth = Some(d);
71 self
72 }
73 pub fn unshallow(&mut self) -> &mut Self {
75 self.unshallow = true;
76 self
77 }
78 pub fn quiet(&mut self) -> &mut Self {
80 self.quiet = true;
81 self
82 }
83}
84
85#[async_trait]
86impl GitCommand for FetchCommand {
87 type Output = CommandOutput;
88 fn get_executor(&self) -> &CommandExecutor {
89 &self.executor
90 }
91 fn get_executor_mut(&mut self) -> &mut CommandExecutor {
92 &mut self.executor
93 }
94 fn build_command_args(&self) -> Vec<String> {
95 let mut args = vec!["fetch".to_string()];
96 if self.all {
97 args.push("--all".into());
98 }
99 if self.tags {
100 args.push("--tags".into());
101 }
102 if self.no_tags {
103 args.push("--no-tags".into());
104 }
105 if self.prune {
106 args.push("--prune".into());
107 }
108 if let Some(d) = self.depth {
109 args.push(format!("--depth={d}"));
110 }
111 if self.unshallow {
112 args.push("--unshallow".into());
113 }
114 if self.quiet {
115 args.push("--quiet".into());
116 }
117 if let Some(r) = &self.remote {
118 args.push(r.clone());
119 }
120 if let Some(r) = &self.refspec {
121 args.push(r.clone());
122 }
123 args
124 }
125 async fn execute(&self) -> Result<CommandOutput> {
126 self.execute_raw().await
127 }
128}