mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-10 03:59:31 +01:00
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:
commit
e8e6d47743
2 changed files with 15 additions and 3 deletions
12
src/main.rs
12
src/main.rs
|
@ -211,6 +211,18 @@ async fn tempfile(ext: Option<&str>) -> tokio::io::Result<(tokio::fs::File, std:
|
||||||
Ok((file, path))
|
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;
|
use std::sync::OnceLock;
|
||||||
static SPECIAL_RENDER: OnceLock<SpecialRender> = OnceLock::new();
|
static SPECIAL_RENDER: OnceLock<SpecialRender> = OnceLock::new();
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ impl RepoInfo {
|
||||||
if let Some(host_url) = &host_url {
|
if let Some(host_url) = &host_url {
|
||||||
let remote = local_repo.find_remote(remote_name_s)?;
|
let remote = local_repo.find_remote(remote_name_s)?;
|
||||||
let url_s = std::str::from_utf8(remote.url_bytes())?;
|
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() {
|
if url.host_str() == host_url.host_str() {
|
||||||
name = Some(remote_name_s.to_owned());
|
name = Some(remote_name_s.to_owned());
|
||||||
|
@ -123,7 +123,7 @@ impl RepoInfo {
|
||||||
let remote = local_repo.find_remote(remote_name)?;
|
let remote = local_repo.find_remote(remote_name)?;
|
||||||
|
|
||||||
if let Some(url) = remote.url() {
|
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()
|
if url.host_str() == host_url.host_str()
|
||||||
&& url.path() == host_url.path()
|
&& url.path() == host_url.path()
|
||||||
{
|
{
|
||||||
|
@ -138,7 +138,7 @@ impl RepoInfo {
|
||||||
if let Some(name) = name {
|
if let Some(name) = name {
|
||||||
if let Ok(remote) = local_repo.find_remote(&name) {
|
if let Ok(remote) = local_repo.find_remote(&name) {
|
||||||
let url_s = std::str::from_utf8(remote.url_bytes())?;
|
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)?;
|
let (url, name) = url_strip_repo_name(url)?;
|
||||||
|
|
||||||
out = (Some(url), Some(name))
|
out = (Some(url), Some(name))
|
||||||
|
|
Loading…
Reference in a new issue