diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 7cb2240e71f..6367a12e410 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1661,6 +1661,17 @@ impl DetailedTomlDependency { .or_else(|| self.rev.clone().map(GitReference::Rev)) .unwrap_or_else(|| GitReference::Branch("master".to_string())); let loc = git.into_url()?; + + if let Some(fragment) = loc.fragment() { + let msg = format!( + "URL fragment `#{}` in git URL is ignored for dependency ({}). \ + If you were trying to specify a specific git revision, \ + use `rev = \"{}\"` in the dependency declaration.", + fragment, name_in_toml, fragment + ); + cx.warnings.push(msg) + } + SourceId::for_git(&loc, reference)? } (None, Some(path), _, _) => { diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 1e0b6546466..dc339da7291 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -861,6 +861,36 @@ This will be considered an error in future versions .run(); } +#[cargo_test] +fn fragment_in_git_url() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.0" + authors = [] + + [dependencies.bar] + git = "http://127.0.0.1#foo" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build -v") + .with_status(101) + .with_stderr_contains( + "\ +[WARNING] URL fragment `#foo` in git URL is ignored for dependency (bar). \ +If you were trying to specify a specific git revision, \ +use `rev = \"foo\"` in the dependency declaration. +", + ) + .run(); +} + #[cargo_test] fn bad_source_config1() { let p = project()