From 9ca6376f291c6c78a74cbd5ff6bd519c5df230df Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 14 Nov 2023 13:47:10 -0600 Subject: [PATCH] fix(resolver): Don't do git fetches when updating workspace members Before, when running `cargo update `, we'd not reuse the previous resolve result and when the resolver started walking into the dependencies, it would do a git fetch. Now, we won't even try to resolve the workspace members and so we won't look at those dependencies and do git fetch. This will make `cargo update ` match `cargo update --workspace`. I considered whether there were other ways of handling this but I figured aiming for consistency in approaches was the best way. We can investigate improving those approaches separately. There are other discrepancies in the different code paths (handling of patches, adding sources) but I'm deferring looking over those. Between this and #12602, this should finnally resolve #12599. Fixes #12599 --- src/cargo/ops/cargo_generate_lockfile.rs | 20 ++++++++++++++++++++ tests/testsuite/update.rs | 8 +------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index a16d6d40331..03c38630e92 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -122,6 +122,26 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes } } + // Mirror `--workspace` and never avoid workspace members. + // Filtering them out here so the above processes them normally + // so their dependencies can be updated as requested + to_avoid = to_avoid + .into_iter() + .filter(|id| { + for package in ws.members() { + let member_id = package.package_id(); + // Skip checking the `version` because `previous_resolve` might have a stale + // value. + // When dealing with workspace members, the other fields should be a + // sufficiently unique match. + if id.name() == member_id.name() && id.source_id() == member_id.source_id() { + return false; + } + } + true + }) + .collect(); + registry.add_sources(sources)?; } diff --git a/tests/testsuite/update.rs b/tests/testsuite/update.rs index fb740052a67..40bc0b476a0 100644 --- a/tests/testsuite/update.rs +++ b/tests/testsuite/update.rs @@ -1091,11 +1091,8 @@ rustdns.workspace = true p.cargo("update -p rootcrate") .with_stderr(&format!( "\ -[UPDATING] git repository `{}` [UPDATING] rootcrate v2.29.8 ([CWD]/rootcrate) -> v2.29.81 -[UPDATING] rustdns v0.5.0 ([..]) -> [..] [UPDATING] subcrate v2.29.8 ([CWD]/subcrate) -> v2.29.81", - git_project.url(), )) .run(); } @@ -1182,11 +1179,8 @@ rustdns.workspace = true p.cargo("update -p crate2") .with_stderr(&format!( "\ -[UPDATING] git repository `{}` [UPDATING] crate1 v2.29.8 ([CWD]/crate1) -> v2.29.81 -[UPDATING] crate2 v2.29.8 ([CWD]/crate2) -> v2.29.81 -[UPDATING] rustdns v0.5.0 ([..]) -> [..]", - git_project.url(), +[UPDATING] crate2 v2.29.8 ([CWD]/crate2) -> v2.29.81", )) .run(); }