From 66acc2698aa39468ea9a0beecc8892cc57f1a91f Mon Sep 17 00:00:00 2001 From: Zachary Hamm Date: Thu, 24 Jul 2025 17:25:21 -0500 Subject: [PATCH] git_hosting_providers: Support GitHub remote URLs that start with a slash (#34134) Remote URLs like `git@github.com:/zed-industries/zed` are valid git remotes, but currently Zed does not parse them correctly. The result is invalid "permalink" generation, and presumably other bugs anywhere that git remote urls are required for the current repository. This ensures Zed will parse those URLs correctly. Release Notes: - Improved support for GitHub remote urls where the username/organization is preceded by an extra `/` to match the behavior of `git`, `gh` and `github.com`. Co-authored-by: Peter Tripp --- .../src/providers/github.rs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/git_hosting_providers/src/providers/github.rs b/crates/git_hosting_providers/src/providers/github.rs index 649b2f30ae..30f8d058a7 100644 --- a/crates/git_hosting_providers/src/providers/github.rs +++ b/crates/git_hosting_providers/src/providers/github.rs @@ -159,7 +159,11 @@ impl GitHostingProvider for Github { } let mut path_segments = url.path_segments()?; - let owner = path_segments.next()?; + let mut owner = path_segments.next()?; + if owner.is_empty() { + owner = path_segments.next()?; + } + let repo = path_segments.next()?.trim_end_matches(".git"); Some(ParsedGitRemote { @@ -244,6 +248,22 @@ mod tests { use super::*; + #[test] + fn test_remote_url_with_root_slash() { + let remote_url = "git@github.com:/zed-industries/zed"; + let parsed_remote = Github::public_instance() + .parse_remote_url(remote_url) + .unwrap(); + + assert_eq!( + parsed_remote, + ParsedGitRemote { + owner: "zed-industries".into(), + repo: "zed".into(), + } + ); + } + #[test] fn test_invalid_self_hosted_remote_url() { let remote_url = "git@github.com:zed-industries/zed.git";