diff options
author | Cyborus <cyborus@noreply.codeberg.org> | 2024-08-30 18:19:19 +0200 |
---|---|---|
committer | Cyborus <cyborus@noreply.codeberg.org> | 2024-08-30 18:19:19 +0200 |
commit | e8e6d47743f8d2117658e8064e27ee2cfe02fda8 (patch) | |
tree | 8884990dcd8cf93af511af94e2de67aaffb28aec | |
parent | Merge pull request 'Squish clippy and audit errors/warnings' (#120) from Pi-C... (diff) | |
parent | fix: correctly parse ssh urls from git remotes (diff) | |
download | forgejo-cli-e8e6d47743f8d2117658e8064e27ee2cfe02fda8.tar.xz forgejo-cli-e8e6d47743f8d2117658e8064e27ee2cfe02fda8.zip |
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
-rw-r--r-- | src/main.rs | 12 | ||||
-rw-r--r-- | src/repo.rs | 6 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index 8e7ff0e..f224abd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); diff --git a/src/repo.rs b/src/repo.rs index 07370d3..e8f12d3 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -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)) |