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 fn status(self) -> Result<(), CommandError> {
48 self.build().status()
49 }
50
51 fn build(self) -> cmd_proc::Command {
52 cmd_proc::Command::new("git")
53 .argument("clone")
54 .optional_argument(self.bare.then_some("--bare"))
55 .argument(self.url)
56 .optional_argument(self.directory)
57 }
58}
59
60#[cfg(feature = "test-utils")]
61impl Clone<'_> {
62 pub fn test_eq(&self, other: &cmd_proc::Command) {
64 let command = Self {
65 url: self.url,
66 directory: self.directory,
67 bare: self.bare,
68 }
69 .build();
70 command.test_eq(other);
71 }
72}