Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning when precise or aggressive without -p flag #10988

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ pub fn generate_lockfile(ws: &Workspace<'_>) -> CargoResult<()> {
}

pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoResult<()> {
// Currently this is only a warning, but after a transition period this will become
// a hard error.
// See https://github.com/rust-lang/cargo/issues/10919#issuecomment-1214464756.
// We should declare the `precise` and `aggressive` arguments
// require the `package` argument in the clap.
if opts.aggressive && opts.to_update.is_empty() {
Rustin170506 marked this conversation as resolved.
Show resolved Hide resolved
ws.config().shell().warn(
"aggressive is only supported with \"--package <SPEC>\", \
this will become a hard error in a future release.",
)?;
}

if opts.precise.is_some() && opts.to_update.is_empty() {
ws.config().shell().warn(
"precise is only supported with \"--package <SPEC>\", \
this will become a hard error in a future release.",
)?;
}

if opts.aggressive && opts.precise.is_some() {
anyhow::bail!("cannot specify both aggressive and precise simultaneously")
}
Expand Down
71 changes: 71 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,77 @@ fn update_precise() {
.run();
}

#[cargo_test]
fn update_precise_without_package() {
Package::new("serde", "0.2.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []

[dependencies]
serde = "0.2"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("build").run();

Package::new("serde", "0.2.1").publish();
Package::new("serde", "0.3.0").publish();

p.cargo("update --precise 0.3.0")
.with_stderr(
"\
[WARNING] precise is only supported with \"--package <SPEC>\", this will become a hard error in a future release.
Rustin170506 marked this conversation as resolved.
Show resolved Hide resolved
[UPDATING] `[..]` index
[UPDATING] serde v0.2.0 -> v0.2.1
",
)
.run();
}

#[cargo_test]
fn update_aggressive_without_package() {
Package::new("serde", "0.2.0").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []

[dependencies]
serde = "0.2"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("build").run();

Package::new("serde", "0.2.1").publish();

p.cargo("update --aggressive")
.with_stderr(
"\
[WARNING] aggressive is only supported with \"--package <SPEC>\", this will become a hard error in a future release.
[UPDATING] `[..]` index
[UPDATING] serde v0.2.0 -> v0.2.1
",
)
.run();
}

// cargo update should respect its arguments even without a lockfile.
// See issue "Running cargo update without a Cargo.lock ignores arguments"
// at <https://github.com/rust-lang/cargo/issues/6872>.
Expand Down