Fix marketplace Git URL parsing

This commit is contained in:
xli-oai
2026-04-10 12:20:27 -07:00
parent cdac5ef786
commit 238f4b1214
+24 -9
View File
@@ -229,6 +229,14 @@ fn parse_marketplace_source(
}
let source = expand_home(source);
let (base_source, parsed_ref) = split_source_ref(&source);
let ref_name = explicit_ref.or(parsed_ref);
if is_ssh_git_url(&base_source) || is_http_git_url(&base_source) {
let url = normalize_git_url(&base_source);
return Ok(MarketplaceSource::Git { url, ref_name });
}
let path = PathBuf::from(&source);
let path_exists = path.try_exists().with_context(|| {
format!(
@@ -273,14 +281,6 @@ fn parse_marketplace_source(
return Ok(MarketplaceSource::LocalDirectory { path });
}
let (base_source, parsed_ref) = split_source_ref(&source);
let ref_name = explicit_ref.or(parsed_ref);
if is_ssh_git_url(&base_source) || is_http_git_url(&base_source) {
let url = normalize_git_url(&base_source);
return Ok(MarketplaceSource::Git { url, ref_name });
}
if looks_like_github_shorthand(&base_source) {
let url = format!("https://github.com/{base_source}.git");
return Ok(MarketplaceSource::Git { url, ref_name });
@@ -335,7 +335,7 @@ fn expand_home(source: &str) -> String {
}
fn is_ssh_git_url(source: &str) -> bool {
source.starts_with("git@") && source.contains(':')
source.starts_with("ssh://") || source.starts_with("git@") && source.contains(':')
}
fn is_http_git_url(source: &str) -> bool {
@@ -535,6 +535,21 @@ mod tests {
);
}
#[test]
fn ssh_url_parses_as_git_url() {
assert_eq!(
parse_marketplace_source(
"ssh://git@github.com/owner/repo.git#main",
/* explicit_ref */ None,
)
.unwrap(),
MarketplaceSource::Git {
url: "ssh://git@github.com/owner/repo.git".to_string(),
ref_name: Some("main".to_string()),
}
);
}
#[test]
fn utc_timestamp_formats_unix_epoch_as_rfc3339_utc() {
assert_eq!(format_utc_timestamp(0), "1970-01-01T00:00:00Z");