Check if additional git provider is not the original git provider (#26533)

Release Notes:

- N/A

Yesterday I worked on https://github.com/zed-industries/zed/pull/26482
and noticed afterwards that we have duplicated hosting providers if the
git remote host is "gitlab.com" and after the PR also for "github.com".
This is not a big problem, since the original providers are registered
first and therefore we first find a match with the original providers,
but I think we should address this nevertheless.

We initialize every hosting provider with the defaults here:

b008b2863e/crates/git_hosting_providers/src/git_hosting_providers.rs (L15-L24)

After that, we also register additional hosting providers:

b008b2863e/crates/git_hosting_providers/src/git_hosting_providers.rs (L30-L43)

If we do not check if the additional provider is not the original
provider, we will register the same provider twice.

---------

Co-authored-by: Marshall Bowers <git@maxdeviant.com>
This commit is contained in:
Nils Koch 2025-03-12 14:25:31 +00:00 committed by GitHub
parent 690f26cf8b
commit 910531bc33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View file

@ -60,6 +60,9 @@ impl Github {
pub fn from_remote_url(remote_url: &str) -> Result<Self> {
let host = get_host_from_git_remote_url(remote_url)?;
if host == "github.com" {
bail!("the GitHub instance is not self-hosted");
}
// TODO: detecting self hosted instances by checking whether "github" is in the url or not
// is not very reliable. See https://github.com/zed-industries/zed/issues/26393 for more
@ -236,6 +239,13 @@ mod tests {
use super::*;
#[test]
fn test_invalid_self_hosted_remote_url() {
let remote_url = "git@github.com:zed-industries/zed.git";
let github = Github::from_remote_url(remote_url);
assert!(github.is_err());
}
#[test]
fn test_from_remote_url_ssh() {
let remote_url = "git@github.my-enterprise.com:zed-industries/zed.git";

View file

@ -26,6 +26,9 @@ impl Gitlab {
pub fn from_remote_url(remote_url: &str) -> Result<Self> {
let host = get_host_from_git_remote_url(remote_url)?;
if host == "gitlab.com" {
bail!("the GitLab instance is not self-hosted");
}
// TODO: detecting self hosted instances by checking whether "gitlab" is in the url or not
// is not very reliable. See https://github.com/zed-industries/zed/issues/26393 for more
@ -123,6 +126,13 @@ mod tests {
use super::*;
#[test]
fn test_invalid_self_hosted_remote_url() {
let remote_url = "https://gitlab.com/zed-industries/zed.git";
let github = Gitlab::from_remote_url(remote_url);
assert!(github.is_err());
}
#[test]
fn test_parse_remote_url_given_ssh_url() {
let parsed_remote = Gitlab::new()