Skip to content

Commit 40ebd52

Browse files
committed
Auto merge of #8297 - mjarkk:warn-when-using-hash-in-git-url, r=ehuss
Warn if using hash in git URL, Fixes #8241 This fixes an issue where if the user wants to set the git rev but doesn't know how and as results tries to set the ref in the url hash as also shown when downloading the dependency. Now cargo returns a warning notifying the user about the correct way to set the ref. Fixes #8241
2 parents 5847787 + 91f6617 commit 40ebd52

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,17 @@ impl DetailedTomlDependency {
16611661
.or_else(|| self.rev.clone().map(GitReference::Rev))
16621662
.unwrap_or_else(|| GitReference::Branch("master".to_string()));
16631663
let loc = git.into_url()?;
1664+
1665+
if let Some(fragment) = loc.fragment() {
1666+
let msg = format!(
1667+
"URL fragment `#{}` in git URL is ignored for dependency ({}). \
1668+
If you were trying to specify a specific git revision, \
1669+
use `rev = \"{}\"` in the dependency declaration.",
1670+
fragment, name_in_toml, fragment
1671+
);
1672+
cx.warnings.push(msg)
1673+
}
1674+
16641675
SourceId::for_git(&loc, reference)?
16651676
}
16661677
(None, Some(path), _, _) => {

tests/testsuite/bad_config.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,36 @@ This will be considered an error in future versions
861861
.run();
862862
}
863863

864+
#[cargo_test]
865+
fn fragment_in_git_url() {
866+
let p = project()
867+
.file(
868+
"Cargo.toml",
869+
r#"
870+
[package]
871+
name = "foo"
872+
version = "0.0.0"
873+
authors = []
874+
875+
[dependencies.bar]
876+
git = "http://127.0.0.1#foo"
877+
"#,
878+
)
879+
.file("src/lib.rs", "")
880+
.build();
881+
882+
p.cargo("build -v")
883+
.with_status(101)
884+
.with_stderr_contains(
885+
"\
886+
[WARNING] URL fragment `#foo` in git URL is ignored for dependency (bar). \
887+
If you were trying to specify a specific git revision, \
888+
use `rev = \"foo\"` in the dependency declaration.
889+
",
890+
)
891+
.run();
892+
}
893+
864894
#[cargo_test]
865895
fn bad_source_config1() {
866896
let p = project()

0 commit comments

Comments
 (0)