git_spawn/command/
push.rs1use crate::command::{CommandExecutor, CommandOutput, GitCommand};
4use crate::error::Result;
5use async_trait::async_trait;
6
7#[derive(Debug, Clone, Default)]
9pub struct PushCommand {
10 pub executor: CommandExecutor,
12 pub remote: Option<String>,
14 pub refspecs: Vec<String>,
16 pub all: bool,
18 pub tags: bool,
20 pub follow_tags: bool,
22 pub force: bool,
24 pub force_with_lease: bool,
26 pub delete: bool,
28 pub set_upstream: bool,
30 pub dry_run: bool,
32 pub atomic: bool,
34 pub quiet: bool,
36}
37
38impl PushCommand {
39 #[must_use]
41 pub fn new() -> Self {
42 Self::default()
43 }
44 pub fn remote(&mut self, r: impl Into<String>) -> &mut Self {
46 self.remote = Some(r.into());
47 self
48 }
49 pub fn refspec(&mut self, r: impl Into<String>) -> &mut Self {
51 self.refspecs.push(r.into());
52 self
53 }
54 pub fn all(&mut self) -> &mut Self {
56 self.all = true;
57 self
58 }
59 pub fn tags(&mut self) -> &mut Self {
61 self.tags = true;
62 self
63 }
64 pub fn follow_tags(&mut self) -> &mut Self {
66 self.follow_tags = true;
67 self
68 }
69 pub fn force(&mut self) -> &mut Self {
71 self.force = true;
72 self
73 }
74 pub fn force_with_lease(&mut self) -> &mut Self {
76 self.force_with_lease = true;
77 self
78 }
79 pub fn delete(&mut self) -> &mut Self {
81 self.delete = true;
82 self
83 }
84 pub fn set_upstream(&mut self) -> &mut Self {
86 self.set_upstream = true;
87 self
88 }
89 pub fn dry_run(&mut self) -> &mut Self {
91 self.dry_run = true;
92 self
93 }
94 pub fn atomic(&mut self) -> &mut Self {
96 self.atomic = true;
97 self
98 }
99 pub fn quiet(&mut self) -> &mut Self {
101 self.quiet = true;
102 self
103 }
104}
105
106#[async_trait]
107impl GitCommand for PushCommand {
108 type Output = CommandOutput;
109 fn get_executor(&self) -> &CommandExecutor {
110 &self.executor
111 }
112 fn get_executor_mut(&mut self) -> &mut CommandExecutor {
113 &mut self.executor
114 }
115 fn build_command_args(&self) -> Vec<String> {
116 let mut args = vec!["push".to_string()];
117 if self.all {
118 args.push("--all".into());
119 }
120 if self.tags {
121 args.push("--tags".into());
122 }
123 if self.follow_tags {
124 args.push("--follow-tags".into());
125 }
126 if self.force {
127 args.push("--force".into());
128 }
129 if self.force_with_lease {
130 args.push("--force-with-lease".into());
131 }
132 if self.delete {
133 args.push("--delete".into());
134 }
135 if self.set_upstream {
136 args.push("--set-upstream".into());
137 }
138 if self.dry_run {
139 args.push("--dry-run".into());
140 }
141 if self.atomic {
142 args.push("--atomic".into());
143 }
144 if self.quiet {
145 args.push("--quiet".into());
146 }
147 if let Some(r) = &self.remote {
148 args.push(r.clone());
149 }
150 args.extend(self.refspecs.iter().cloned());
151 args
152 }
153 async fn execute(&self) -> Result<CommandOutput> {
154 self.execute_raw().await
155 }
156}