crate::newtype!(RemoteUrl: git_url_parse::GitUrl, derive_more::Display: "The URL of a remote repository");
impl RemoteUrl {
pub fn parse(url: impl Into<String>) -> Option<Self> {
Some(Self::new(::git_url_parse::GitUrl::parse(&url.into()).ok()?))
}
}
impl TryFrom<gix::Url> for RemoteUrl {
type Error = ();
fn try_from(url: gix::Url) -> Result<Self, Self::Error> {
let pass = url.password().map(|p| p.to_owned());
let mut parsed = ::git_url_parse::GitUrl::parse(&url.to_string()).map_err(|_| ())?;
parsed.token = pass;
Ok(Self(parsed))
}
}
impl RemoteUrl {
pub fn matches(&self, other: &Self) -> bool {
tracing::debug!(host = ?self.host, fullname = ?self.fullname, token = ?self.token, "a");
tracing::debug!(host = ?other.host, fullname = ?other.fullname, token = ?other.token,"b");
self.host.eq(&other.host)
&& self.fullname.eq(&other.fullname)
&& self.token.eq(&other.token)
}
}