Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Check if additional git provider is not the original git provider (#26533)
Nils Koch910531bc333b
diff --git a/crates/git_hosting_providers/src/providers/github.rs b/crates/git_hosting_providers/src/providers/github.rsindex 7d2f20ff70e..eb6d606195e 100644--- a/crates/git_hosting_providers/src/providers/github.rs+++ b/crates/git_hosting_providers/src/providers/github.rs@@ -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 = "[email protected]: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 = "[email protected]:zed-industries/zed.git";diff --git a/crates/git_hosting_providers/src/providers/gitlab.rs b/crates/git_hosting_providers/src/providers/gitlab.rsindex abdfc491f41..8158b45444a 100644--- a/crates/git_hosting_providers/src/providers/gitlab.rs+++ b/crates/git_hosting_providers/src/providers/gitlab.rs@@ -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()