1use std::path::Path;
2
3use crate::CommandError;
4use crate::url::GitUrl;
5
6#[must_use]
8pub fn new(url: &GitUrl) -> Clone<'_> {
9 Clone::new(url)
10}
11
12#[derive(Debug)]
16pub struct Clone<'a> {
17 url: &'a GitUrl,
18 directory: Option<&'a Path>,
19 bare: bool,
20}
21
22impl<'a> Clone<'a> {
23 #[must_use]
24 fn new(url: &'a GitUrl) -> Self {
25 Self {
26 url,
27 directory: None,
28 bare: false,
29 }
30 }
31
32 #[must_use]
34 pub fn directory(mut self, path: &'a Path) -> Self {
35 self.directory = Some(path);
36 self
37 }
38
39 crate::flag_methods! {
40 pub fn bare / bare_if, bare, "Conditionally make a bare clone."
44 }
45
46 pub async fn status(self) -> Result<(), CommandError> {
48 crate::Build::build(self).status().await
49 }
50}
51
52impl crate::Build for Clone<'_> {
53 fn build(self) -> cmd_proc::Command {
54 cmd_proc::Command::new("git")
55 .argument("clone")
56 .optional_flag(self.bare, "--bare")
57 .argument(self.url)
58 .optional_argument(self.directory)
59 }
60}
61
62#[cfg(feature = "test-utils")]
63impl Clone<'_> {
64 pub fn test_eq(&self, other: &cmd_proc::Command) {
66 let command = crate::Build::build(Self {
67 url: self.url,
68 directory: self.directory,
69 bare: self.bare,
70 });
71 command.test_eq(other);
72 }
73}