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