Skip to content

Commit

Permalink
feat(update): Include a Locking message
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 15, 2024
1 parent 9f8adff commit e772fc9
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 19 deletions.
6 changes: 5 additions & 1 deletion src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,12 @@ fn print_lockfile_updates(
resolve: &Resolve,
registry: &mut PackageRegistry<'_>,
) -> CargoResult<()> {
let diff = PackageDiff::diff(&previous_resolve, &resolve);
let num_pkgs: usize = diff.iter().map(|d| d.added.len()).sum();
status_locking(ws, num_pkgs)?;

let mut unchanged_behind = 0;
for diff in PackageDiff::diff(&previous_resolve, &resolve) {
for diff in diff {
fn format_latest(version: semver::Version) -> String {
let warn = style::WARN;
format!(" {warn}(latest: v{version}){warn:#}")
Expand Down
59 changes: 42 additions & 17 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,10 @@ fn recompilation() {

p.cargo("update")
.with_stderr(&format!(
"[UPDATING] git repository `{}`",
"\
[UPDATING] git repository `{}`
[LOCKING] 0 packages to latest compatible versions
",
git_project.url()
))
.run();
Expand All @@ -636,9 +639,11 @@ fn recompilation() {
// Update the dependency and carry on!
p.cargo("update")
.with_stderr(&format!(
"[UPDATING] git repository `{}`\n\
[UPDATING] bar v0.5.0 ([..]) -> #[..]\n\
",
"\
[UPDATING] git repository `{}`
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.5.0 ([..]) -> #[..]
",
git_project.url()
))
.run();
Expand Down Expand Up @@ -766,6 +771,7 @@ fn update_with_shared_deps() {
.with_stderr(
"\
[UPDATING] git repository [..]
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.5.0 [..]
",
)
Expand All @@ -791,16 +797,22 @@ Caused by:
println!("bar precise update");
p.cargo("update bar --precise")
.arg(&old_head.to_string())
.with_stderr("[UPDATING] bar v0.5.0 [..]")
.with_stderr(
"\
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.5.0 [..]",
)
.run();

// Updating recursively should, however, update the repo.
println!("dep1 recursive update");
p.cargo("update dep1 --recursive")
.with_stderr(&format!(
"[UPDATING] git repository `{}`\n\
[UPDATING] bar v0.5.0 ([..]) -> #[..]\n\
",
"\
[UPDATING] git repository `{}`
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.5.0 ([..]) -> #[..]
",
git_project.url()
))
.run();
Expand All @@ -822,7 +834,10 @@ Caused by:
// We should be able to update transitive deps
p.cargo("update bar")
.with_stderr(&format!(
"[UPDATING] git repository `{}`",
"\
[UPDATING] git repository `{}`
[LOCKING] 0 packages to latest compatible versions
",
git_project.url()
))
.run();
Expand Down Expand Up @@ -1223,9 +1238,11 @@ fn two_deps_only_update_one() {

p.cargo("update dep1")
.with_stderr(&format!(
"[UPDATING] git repository `{}`\n\
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
",
"\
[UPDATING] git repository `{}`
[LOCKING] 1 package to latest compatible version
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]
",
git1.url()
))
.run();
Expand Down Expand Up @@ -1411,10 +1428,12 @@ fn dep_with_changed_submodule() {
p.cargo("update")
.with_stderr("")
.with_stderr(&format!(
"[UPDATING] git repository `{}`\n\
[UPDATING] git submodule `file://[..]/dep3`\n\
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
",
"\
[UPDATING] git repository `{}`
[UPDATING] git submodule `file://[..]/dep3`
[LOCKING] 1 package to latest compatible version
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]
",
git_project.url()
))
.run();
Expand Down Expand Up @@ -1993,7 +2012,13 @@ fn update_one_dep_in_repo_with_many_deps() {

p.cargo("generate-lockfile").run();
p.cargo("update bar")
.with_stderr(&format!("[UPDATING] git repository `{}`", bar.url()))
.with_stderr(&format!(
"\
[UPDATING] git repository `{}`
[LOCKING] 0 packages to latest compatible versions
",
bar.url()
))
.run();
}

Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/global_cache_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,7 @@ fn clean_max_git_age() {
.with_stderr(
"\
[UPDATING] git repository [..]
[LOCKING] 1 package to latest compatible version
[UPDATING] git_a v1.0.0 [..]
",
)
Expand Down Expand Up @@ -1562,6 +1563,7 @@ fn clean_max_src_crate_age() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v1.0.0 -> v1.0.1
",
)
Expand Down
6 changes: 5 additions & 1 deletion tests/testsuite/local_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ fn multiple_versions() {
.publish();

p.cargo("update")
.with_stderr("[UPDATING] bar v0.1.0 -> v0.2.0")
.with_stderr(
"\
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.1.0 -> v0.2.0",
)
.run();
}

Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ fn main(){
.with_status(0)
.with_stderr(
"\
[LOCKING] 1 package to latest compatible version
[DOWNGRADING] present_dep v1.2.9 -> v1.2.3
",
)
Expand All @@ -725,6 +726,7 @@ fn main(){
.with_status(0)
.with_stderr(
"\
[LOCKING] 1 package to latest compatible version
[UPDATING] present_dep v1.2.3 -> v1.2.9
",
)
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,7 @@ fn update_unused_new_version() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[ADDING] bar v0.1.6 ([..]/bar)
[REMOVING] bar v0.1.5
",
Expand All @@ -2073,6 +2074,7 @@ fn update_unused_new_version() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[ADDING] bar v0.1.6 ([..]/bar)
[REMOVING] bar v0.1.5
",
Expand Down Expand Up @@ -2542,6 +2544,7 @@ fn can_update_with_alt_reg() {
"\
[UPDATING] `alternative` index
[UPDATING] `dummy-registry` index
[LOCKING] 0 packages to latest compatible versions
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
",
)
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/precise_pre_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fn update_pre_release() {
.masquerade_as_nightly_cargo(&["precise-pre-release"])
.with_stderr(
r#"[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[UPDATING] my-dependency v0.1.1 -> v0.1.2-pre.0
"#,
)
Expand Down Expand Up @@ -98,6 +99,7 @@ fn update_pre_release_differ() {
.masquerade_as_nightly_cargo(&["precise-pre-release"])
.with_stderr(
r#"[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[DOWNGRADING] my-dependency v0.1.2 -> v0.1.2-pre.0
"#,
)
Expand All @@ -107,6 +109,7 @@ fn update_pre_release_differ() {
.masquerade_as_nightly_cargo(&["precise-pre-release"])
.with_stderr(
r#"[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[UPDATING] my-dependency v0.1.2-pre.0 -> v0.1.2-pre.1
"#,
)
Expand Down
10 changes: 10 additions & 0 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ required by package `foo v0.0.1 ([..])`
.with_stderr_contains(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] baz v0.0.1 -> v0.0.2
",
)
Expand Down Expand Up @@ -995,6 +996,7 @@ fn update_lockfile() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.0.1 -> v0.0.2
",
)
Expand All @@ -1018,6 +1020,7 @@ fn update_lockfile() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.0.2 -> v0.0.3
",
)
Expand All @@ -1043,6 +1046,7 @@ fn update_lockfile() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 2 packages to latest compatible versions
[UPDATING] bar v0.0.3 -> v0.0.4
[ADDING] spam v0.2.5
",
Expand All @@ -1055,6 +1059,7 @@ fn update_lockfile() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.0.4 -> v0.0.5
[REMOVING] spam v0.2.5
",
Expand Down Expand Up @@ -1493,6 +1498,7 @@ fn update_transitive_dependency() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] b v0.1.0 -> v0.1.1
",
)
Expand Down Expand Up @@ -1565,6 +1571,7 @@ fn update_backtracking_ok() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 2 packages to latest compatible versions
[UPDATING] hyper v0.6.5 -> v0.6.6
[UPDATING] openssl v0.1.0 -> v0.1.1
",
Expand Down Expand Up @@ -1617,6 +1624,7 @@ fn update_multiple_packages() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 2 packages to latest compatible versions
[UPDATING] a v0.1.0 -> v0.1.1
[UPDATING] b v0.1.0 -> v0.1.1
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
Expand All @@ -1628,6 +1636,7 @@ fn update_multiple_packages() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] c v0.1.0 -> v0.1.1
",
)
Expand Down Expand Up @@ -3767,6 +3776,7 @@ fn differ_only_by_metadata_with_lockfile() {
.with_stderr(
"\
[UPDATING] [..] index
[LOCKING] 1 package to latest compatible version
[..] baz v0.0.1+c -> v0.0.1+b
",
)
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ fn override_adds_some_deps() {
"\
[UPDATING] git repository `file://[..]`
[UPDATING] `dummy-registry` index
[LOCKING] 0 packages to latest compatible versions
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
",
)
Expand All @@ -568,6 +569,7 @@ fn override_adds_some_deps() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 0 packages to latest compatible versions
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
",
)
Expand Down Expand Up @@ -901,6 +903,7 @@ fn update() {
"\
[UPDATING] `[..]` index
[UPDATING] git repository `[..]`
[LOCKING] 0 packages to latest compatible versions
",
)
.run();
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ See https://github.com/rust-lang/cargo/issues/9930 for more information about th
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v1.5.0 -> v1.6.0
",
)
Expand Down
Loading

0 comments on commit e772fc9

Please sign in to comment.