git_next_core/config/
remote_url.rs

1//
2use std::borrow::ToOwned;
3
4use crate::{newtype, s};
5
6newtype!(
7    RemoteUrl,
8    git_url_parse::GitUrl,
9    derive_more::Display,
10    "The URL of a remote repository"
11);
12impl RemoteUrl {
13    pub fn parse(url: impl Into<String>) -> Option<Self> {
14        Some(Self::new(::git_url_parse::GitUrl::parse(&url.into()).ok()?))
15    }
16}
17impl TryFrom<gix::Url> for RemoteUrl {
18    type Error = ();
19
20    fn try_from(url: gix::Url) -> Result<Self, Self::Error> {
21        let pass = url.password().map(ToOwned::to_owned);
22        let mut parsed = ::git_url_parse::GitUrl::parse(&s!(url)).map_err(|_| ())?;
23        parsed.token = pass;
24        Ok(Self(parsed))
25    }
26}
27impl RemoteUrl {
28    pub fn matches(&self, other: &Self) -> bool {
29        tracing::debug!(host = ?self.host, fullname = ?self.fullname, token = ?self.token, "a");
30        tracing::debug!(host = ?other.host,  fullname = ?other.fullname, token = ?other.token,"b");
31        self.host.eq(&other.host)
32            && self.fullname.eq(&other.fullname)
33            && self.token.eq(&other.token)
34    }
35}