1use std::path::Path;
2
3use crate::url::Remote;
4
5#[must_use]
7pub fn new() -> LsRemote<'static> {
8 LsRemote::new()
9}
10
11#[derive(Debug)]
15pub struct LsRemote<'a> {
16 repo_path: Option<&'a Path>,
17 heads: bool,
18 symref: bool,
19 remote: Option<&'a Remote>,
20 pattern: Option<&'a str>,
21}
22
23crate::impl_repo_path!(LsRemote);
24
25impl<'a> LsRemote<'a> {
26 #[must_use]
27 fn new() -> Self {
28 Self {
29 repo_path: None,
30 heads: false,
31 symref: false,
32 remote: None,
33 pattern: None,
34 }
35 }
36
37 crate::flag_methods! {
38 pub fn heads / heads_if, heads, "Conditionally limit to refs/heads."
42 }
43
44 crate::flag_methods! {
45 pub fn symref / symref_if, symref, "Conditionally show underlying ref."
49 }
50
51 #[must_use]
53 pub fn remote(mut self, remote: &'a Remote) -> Self {
54 self.remote = Some(remote);
55 self
56 }
57
58 #[must_use]
60 pub fn pattern(mut self, pattern: &'a str) -> Self {
61 self.pattern = Some(pattern);
62 self
63 }
64}
65
66impl Default for LsRemote<'_> {
67 fn default() -> Self {
68 Self::new()
69 }
70}
71
72impl crate::Build for LsRemote<'_> {
73 fn build(self) -> cmd_proc::Command {
74 crate::base_command(self.repo_path)
75 .argument("ls-remote")
76 .optional_flag(self.heads, "--heads")
77 .optional_flag(self.symref, "--symref")
78 .optional_argument(self.remote)
79 .optional_argument(self.pattern)
80 }
81}
82
83#[cfg(feature = "test-utils")]
84impl LsRemote<'_> {
85 pub fn test_eq(&self, other: &cmd_proc::Command) {
87 let command = crate::Build::build(Self {
88 repo_path: self.repo_path,
89 heads: self.heads,
90 symref: self.symref,
91 remote: self.remote,
92 pattern: self.pattern,
93 });
94 command.test_eq(other);
95 }
96}