Skip to content

Commit 9ca6376

Browse files
committed
fix(resolver): Don't do git fetches when updating workspace members
Before, when running `cargo update <member>`, 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 <workspace-member>` 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
1 parent 80225bb commit 9ca6376

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/cargo/ops/cargo_generate_lockfile.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
122122
}
123123
}
124124

125+
// Mirror `--workspace` and never avoid workspace members.
126+
// Filtering them out here so the above processes them normally
127+
// so their dependencies can be updated as requested
128+
to_avoid = to_avoid
129+
.into_iter()
130+
.filter(|id| {
131+
for package in ws.members() {
132+
let member_id = package.package_id();
133+
// Skip checking the `version` because `previous_resolve` might have a stale
134+
// value.
135+
// When dealing with workspace members, the other fields should be a
136+
// sufficiently unique match.
137+
if id.name() == member_id.name() && id.source_id() == member_id.source_id() {
138+
return false;
139+
}
140+
}
141+
true
142+
})
143+
.collect();
144+
125145
registry.add_sources(sources)?;
126146
}
127147

tests/testsuite/update.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,11 +1091,8 @@ rustdns.workspace = true
10911091
p.cargo("update -p rootcrate")
10921092
.with_stderr(&format!(
10931093
"\
1094-
[UPDATING] git repository `{}`
10951094
[UPDATING] rootcrate v2.29.8 ([CWD]/rootcrate) -> v2.29.81
1096-
[UPDATING] rustdns v0.5.0 ([..]) -> [..]
10971095
[UPDATING] subcrate v2.29.8 ([CWD]/subcrate) -> v2.29.81",
1098-
git_project.url(),
10991096
))
11001097
.run();
11011098
}
@@ -1182,11 +1179,8 @@ rustdns.workspace = true
11821179
p.cargo("update -p crate2")
11831180
.with_stderr(&format!(
11841181
"\
1185-
[UPDATING] git repository `{}`
11861182
[UPDATING] crate1 v2.29.8 ([CWD]/crate1) -> v2.29.81
1187-
[UPDATING] crate2 v2.29.8 ([CWD]/crate2) -> v2.29.81
1188-
[UPDATING] rustdns v0.5.0 ([..]) -> [..]",
1189-
git_project.url(),
1183+
[UPDATING] crate2 v2.29.8 ([CWD]/crate2) -> v2.29.81",
11901184
))
11911185
.run();
11921186
}

0 commit comments

Comments
 (0)