Skip to content

Commit

Permalink
Auto merge of #8297 - mjarkk:warn-when-using-hash-in-git-url, r=ehuss
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jun 1, 2020
2 parents 5847787 + 91f6617 commit 40ebd52
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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), _, _) => {
Expand Down
30 changes: 30 additions & 0 deletions tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 40ebd52

Please sign in to comment.