diff --git a/src/cargo/util/into_url.rs b/src/cargo/util/into_url.rs index 26f365ee8..fa48cc31f 100644 --- a/src/cargo/util/into_url.rs +++ b/src/cargo/util/into_url.rs @@ -12,7 +12,18 @@ pub trait IntoUrl { impl<'a> IntoUrl for &'a str { fn into_url(self) -> CargoResult { - Url::parse(self).map_err(|s| anyhow::format_err!("invalid url `{}`: {}", self, s)) + Url::parse(self).map_err(|s| { + if self.starts_with("git@") { + anyhow::format_err!( + "invalid url `{}`: {}; try using `{}` instead", + self, + s, + format_args!("ssh://{}", self.replacen(':', "/", 1)) + ) + } else { + anyhow::format_err!("invalid url `{}`: {}", self, s) + } + }) } } diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index c63d355c4..8d00ecf18 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -528,6 +528,7 @@ this is dep1 this is dep2 #[cargo_test] fn cargo_compile_with_short_ssh_git() { let url = "git@github.com:a/dep"; + let well_formed_url = "ssh://git@github.com/a/dep"; let p = project() .file( @@ -565,9 +566,9 @@ fn cargo_compile_with_short_ssh_git() { [ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` Caused by: - invalid url `{}`: relative URL without a base + invalid url `{}`: relative URL without a base; try using `{}` instead ", - url + url, well_formed_url )) .run(); }