From 0d4706a0f958b4f37954304dbca46db4a4f46e01 Mon Sep 17 00:00:00 2001 From: mjarkk Date: Sat, 30 May 2020 22:23:20 +0200 Subject: [PATCH 1/4] Warn if using hash in git url --- src/cargo/util/toml/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 7cb2240e71f..caafaf6f4bf 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1611,6 +1611,18 @@ impl DetailedTomlDependency { } } + if let Some(git) = self.git.clone() { + if let Ok(url) = git.into_url() { + if url.fragment().is_some() { + let msg = format!( + "hash in git url is ignored for dependency ({}). \ + if you were trying to specify a specific git revision, use rev = \"revision\".", + name_in_toml); + cx.warnings.push(msg) + } + } + } + let new_source_id = match ( self.git.as_ref(), self.path.as_ref(), From c403187d4ab9b6174eb602dae7c0a5952cfe3a25 Mon Sep 17 00:00:00 2001 From: Mark Kopenga Date: Mon, 1 Jun 2020 19:34:39 +0200 Subject: [PATCH 2/4] Update src/cargo/util/toml/mod.rs Co-authored-by: Eric Huss --- src/cargo/util/toml/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index caafaf6f4bf..b6c0571f4aa 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1616,7 +1616,7 @@ impl DetailedTomlDependency { if url.fragment().is_some() { let msg = format!( "hash in git url is ignored for dependency ({}). \ - if you were trying to specify a specific git revision, use rev = \"revision\".", + If you were trying to specify a specific git revision, use rev = \"revision\".", name_in_toml); cx.warnings.push(msg) } From c4e150b25e4ceb5a295309c3f52367a9b265a268 Mon Sep 17 00:00:00 2001 From: mjarkk Date: Mon, 1 Jun 2020 19:41:52 +0200 Subject: [PATCH 3/4] Fix review --- src/cargo/util/toml/mod.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index b6c0571f4aa..6367a12e410 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1611,18 +1611,6 @@ impl DetailedTomlDependency { } } - if let Some(git) = self.git.clone() { - if let Ok(url) = git.into_url() { - if url.fragment().is_some() { - let msg = format!( - "hash in git url is ignored for dependency ({}). \ - If you were trying to specify a specific git revision, use rev = \"revision\".", - name_in_toml); - cx.warnings.push(msg) - } - } - } - let new_source_id = match ( self.git.as_ref(), self.path.as_ref(), @@ -1673,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), _, _) => { From 91f6617457ce8e4a4d103baa1f12d0eb5d8152e3 Mon Sep 17 00:00:00 2001 From: mjarkk Date: Mon, 1 Jun 2020 19:50:33 +0200 Subject: [PATCH 4/4] Add test --- tests/testsuite/bad_config.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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()