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 <peter@zed.dev>
This commit is contained in:
Zachary Hamm 2025-07-24 17:25:21 -05:00 committed by GitHub
parent 707df51664
commit 66acc2698a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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";