From d39d0ac7de95b65db2a2a81e7e803ae47ec3dd07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabor=20K=C3=B6rber?= Date: Sat, 23 May 2026 20:02:00 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=87=20export=20from=20upstream=20(cd2f?= =?UTF-8?q?702)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/sandcage/src/setup.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/sandcage/src/setup.rs b/crates/sandcage/src/setup.rs index 14435f8..66d9bf7 100644 --- a/crates/sandcage/src/setup.rs +++ b/crates/sandcage/src/setup.rs @@ -275,7 +275,7 @@ pub fn extract_git_remote_hosts(git_remote_output: &str) -> Vec { hosts.insert(host.to_string()); } } else if url.contains('@') && url.contains(':') { - // git@host:path format + // user@host:path format (e.g. git@github.com:user/repo.git) let after_at = match url.find('@') { Some(at) => &url[at + 1..], None => continue, @@ -288,6 +288,14 @@ pub fn extract_git_remote_hosts(git_remote_output: &str) -> Vec { if !host.is_empty() { hosts.insert(host.to_string()); } + } else if url.contains(':') && !url.contains('/') || url.find(':') < url.find('/') { + // SCP-style without user: host:path (e.g. git.g4b.org:user/repo.git) + if let Some(colon) = url.find(':') { + let host = url[..colon].trim(); + if !host.is_empty() && !host.contains(' ') { + hosts.insert(host.to_string()); + } + } } } @@ -1250,6 +1258,13 @@ https\thttps://gitlab.com/user/repo.git (push) assert!(hosts.is_empty()); } + #[test] + fn extract_hostnames_scp_without_user() { + let output = "origin\tgit.g4b.org:g4borg/sandcage.git (fetch)\norigin\tgit.g4b.org:g4borg/sandcage.git (push)\n"; + let hosts = extract_git_remote_hosts(output); + assert_eq!(hosts, vec!["git.g4b.org"]); + } + // -- Task 7: build_ssh_discovery tests -- #[test]