Skip to main content

git_proc/
remote.rs

1use std::path::Path;
2
3use crate::url::RemoteName;
4
5/// Create a `git remote get-url` command builder.
6#[must_use]
7pub fn get_url(name: &RemoteName) -> Remote<'_> {
8    Remote::get_url(name)
9}
10
11/// Builder for `git remote` command.
12///
13/// See `git remote --help` for full documentation.
14#[derive(Debug)]
15pub struct Remote<'a> {
16    repo_path: Option<&'a Path>,
17    subcommand: RemoteSubcommand<'a>,
18}
19
20#[derive(Debug)]
21enum RemoteSubcommand<'a> {
22    GetUrl { name: &'a RemoteName },
23}
24
25crate::impl_repo_path!(Remote);
26
27impl<'a> Remote<'a> {
28    #[must_use]
29    fn get_url(name: &'a RemoteName) -> Self {
30        Self {
31            repo_path: None,
32            subcommand: RemoteSubcommand::GetUrl { name },
33        }
34    }
35}
36
37impl crate::Build for Remote<'_> {
38    fn build(self) -> cmd_proc::Command {
39        let RemoteSubcommand::GetUrl { name } = self.subcommand;
40
41        crate::base_command(self.repo_path)
42            .argument("remote")
43            .argument("get-url")
44            .argument(name)
45    }
46}
47
48#[cfg(feature = "test-utils")]
49impl Remote<'_> {
50    /// Compare the built command with another command using debug representation.
51    pub fn test_eq(&self, other: &cmd_proc::Command) {
52        let command = crate::Build::build(Self {
53            repo_path: self.repo_path,
54            subcommand: match &self.subcommand {
55                RemoteSubcommand::GetUrl { name } => RemoteSubcommand::GetUrl { name },
56            },
57        });
58        command.test_eq(other);
59    }
60}