git_spawn/command/
pull.rs1use crate::command::{CommandExecutor, CommandOutput, GitCommand};
4use crate::error::Result;
5use async_trait::async_trait;
6
7#[derive(Debug, Clone, Default)]
9pub struct PullCommand {
10 pub executor: CommandExecutor,
12 pub remote: Option<String>,
14 pub refspec: Option<String>,
16 pub rebase: Option<String>,
18 pub no_rebase: bool,
20 pub ff_only: bool,
22 pub no_ff: bool,
24 pub all: bool,
26 pub tags: bool,
28 pub autostash: bool,
30 pub quiet: bool,
32}
33
34impl PullCommand {
35 #[must_use]
37 pub fn new() -> Self {
38 Self::default()
39 }
40 pub fn remote(&mut self, r: impl Into<String>) -> &mut Self {
42 self.remote = Some(r.into());
43 self
44 }
45 pub fn refspec(&mut self, r: impl Into<String>) -> &mut Self {
47 self.refspec = Some(r.into());
48 self
49 }
50 pub fn rebase(&mut self) -> &mut Self {
52 self.rebase = Some(String::new());
53 self
54 }
55 pub fn rebase_mode(&mut self, m: impl Into<String>) -> &mut Self {
57 self.rebase = Some(m.into());
58 self
59 }
60 pub fn no_rebase(&mut self) -> &mut Self {
62 self.no_rebase = true;
63 self
64 }
65 pub fn ff_only(&mut self) -> &mut Self {
67 self.ff_only = true;
68 self
69 }
70 pub fn no_ff(&mut self) -> &mut Self {
72 self.no_ff = true;
73 self
74 }
75 pub fn all(&mut self) -> &mut Self {
77 self.all = true;
78 self
79 }
80 pub fn tags(&mut self) -> &mut Self {
82 self.tags = true;
83 self
84 }
85 pub fn autostash(&mut self) -> &mut Self {
87 self.autostash = true;
88 self
89 }
90 pub fn quiet(&mut self) -> &mut Self {
92 self.quiet = true;
93 self
94 }
95}
96
97#[async_trait]
98impl GitCommand for PullCommand {
99 type Output = CommandOutput;
100 fn get_executor(&self) -> &CommandExecutor {
101 &self.executor
102 }
103 fn get_executor_mut(&mut self) -> &mut CommandExecutor {
104 &mut self.executor
105 }
106 fn build_command_args(&self) -> Vec<String> {
107 let mut args = vec!["pull".to_string()];
108 if let Some(r) = &self.rebase {
109 if r.is_empty() {
110 args.push("--rebase".into());
111 } else {
112 args.push(format!("--rebase={r}"));
113 }
114 }
115 if self.no_rebase {
116 args.push("--no-rebase".into());
117 }
118 if self.ff_only {
119 args.push("--ff-only".into());
120 }
121 if self.no_ff {
122 args.push("--no-ff".into());
123 }
124 if self.all {
125 args.push("--all".into());
126 }
127 if self.tags {
128 args.push("--tags".into());
129 }
130 if self.autostash {
131 args.push("--autostash".into());
132 }
133 if self.quiet {
134 args.push("--quiet".into());
135 }
136 if let Some(r) = &self.remote {
137 args.push(r.clone());
138 }
139 if let Some(r) = &self.refspec {
140 args.push(r.clone());
141 }
142 args
143 }
144 async fn execute(&self) -> Result<CommandOutput> {
145 self.execute_raw().await
146 }
147}