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]