Merge pull request 'correctly parse ssh urls from git remotes' (#121) from ssh-remote-fix into main

Reviewed-on: https://codeberg.org/Cyborus/forgejo-cli/pulls/121
This commit is contained in:
Cyborus 2024-08-30 16:19:19 +00:00
commit e8e6d47743
2 changed files with 15 additions and 3 deletions

View file

@ -211,6 +211,18 @@ async fn tempfile(ext: Option<&str>) -> tokio::io::Result<(tokio::fs::File, std:
Ok((file, path))
}
fn ssh_url_parse(s: &str) -> Result<url::Url, url::ParseError> {
url::Url::parse(s).or_else(|_| {
let mut new_s = String::new();
new_s.push_str("ssh://");
let auth_end = s.find("@").unwrap_or(0);
new_s.push_str(&s[..auth_end]);
new_s.push_str(&s[..auth_end].replacen(":", "/", 1));
url::Url::parse(&new_s)
})
}
use std::sync::OnceLock;
static SPECIAL_RENDER: OnceLock<SpecialRender> = OnceLock::new();

View file

@ -97,7 +97,7 @@ impl RepoInfo {
if let Some(host_url) = &host_url {
let remote = local_repo.find_remote(remote_name_s)?;
let url_s = std::str::from_utf8(remote.url_bytes())?;
let url = Url::parse(url_s)?;
let url = crate::ssh_url_parse(url_s)?;
if url.host_str() == host_url.host_str() {
name = Some(remote_name_s.to_owned());
@ -123,7 +123,7 @@ impl RepoInfo {
let remote = local_repo.find_remote(remote_name)?;
if let Some(url) = remote.url() {
let (url, _) = url_strip_repo_name(Url::parse(url)?)?;
let (url, _) = url_strip_repo_name(crate::ssh_url_parse(url)?)?;
if url.host_str() == host_url.host_str()
&& url.path() == host_url.path()
{
@ -138,7 +138,7 @@ impl RepoInfo {
if let Some(name) = name {
if let Ok(remote) = local_repo.find_remote(&name) {
let url_s = std::str::from_utf8(remote.url_bytes())?;
let url = Url::parse(url_s)?;
let url = crate::ssh_url_parse(url_s)?;
let (url, name) = url_strip_repo_name(url)?;
out = (Some(url), Some(name))