From 238f4b1214dd5f54f5616d62a5696fc3675b63a0 Mon Sep 17 00:00:00 2001 From: xli-oai Date: Fri, 10 Apr 2026 12:20:27 -0700 Subject: [PATCH] Fix marketplace Git URL parsing --- codex-rs/cli/src/marketplace_cmd.rs | 33 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/codex-rs/cli/src/marketplace_cmd.rs b/codex-rs/cli/src/marketplace_cmd.rs index 48dc2e4c8e..e26f80638d 100644 --- a/codex-rs/cli/src/marketplace_cmd.rs +++ b/codex-rs/cli/src/marketplace_cmd.rs @@ -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");