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

Simplified Update Multiple Crate Output Formats #9884

Closed
wants to merge 4 commits into from
Closed
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
18 changes: 18 additions & 0 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
format!("{} -> v{}", removed[0], added[0].version())
};
print_change("Updating", msg, Green)?;
} else if removed.len() == added.len() {
for (pre_package, tar_package) in removed.iter().zip(added.iter()) {
let msg = if pre_package.source_id().is_git() {
format!(
"{} -> #{}",
pre_package,
&tar_package.source_id().precise().unwrap()[..8]
)
} else {
format!(
"{} v{} -> v{}",
pre_package.name(),
pre_package.version(),
tar_package.version()
)
};
print_change("Updating", msg, Green)?;
}
} else {
for package in removed.iter() {
print_change("Removing", format!("{}", package), Red)?;
Expand Down
57 changes: 57 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,3 +678,60 @@ fn workspace_only() {
assert!(!lock1.contains("0.0.2"));
assert!(!lock2.contains("0.0.1"));
}

#[cargo_test]
fn update_mulit_dependence_after_precise() {
Package::new("serde", "0.1.0").publish();
Package::new("serde", "0.2.0").publish();
Package::new("serde", "0.1.5").publish();
Package::new("serde", "0.2.5").publish();

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

[dependencies]
serde_1 = { package = "serde", version = "0.1.0" }
serde_2 = { package = "serde", version = "0.2.0" }
"#,
)
.file(
"src/main.rs",
r#"
fn main() {}
"#,
)
.build();

p.cargo("generate-lockfile").run();

p.cargo("update -p serde:0.1.5 --precise 0.1.0")
.with_stderr(
"\
[UPDATING] `[..]` index
[UPDATING] serde v0.1.5 -> v0.1.0",
)
.run();

p.cargo("update -p serde:0.2.5 --precise 0.2.0")
.with_stderr(
"\
[UPDATING] `[..]` index
[UPDATING] serde v0.2.5 -> v0.2.0",
)
.run();

p.cargo("update")
.with_stderr(
"\
[UPDATING] `[..]` index
[UPDATING] serde v0.1.0 -> v0.1.5
[UPDATING] serde v0.2.0 -> v0.2.5",
)
.run();
}