Skip to content

Commit

Permalink
fix: update --breaking now understands package@version.
Browse files Browse the repository at this point in the history
  • Loading branch information
torhovland committed Jun 20, 2024
1 parent f80dbad commit 0d59dfc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
22 changes: 19 additions & 3 deletions src/cargo/ops/cargo_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ pub fn upgrade_manifests(
let mut upgrades = HashMap::new();
let mut upgrade_messages = HashSet::new();

let to_update = to_update
.iter()
.map(|s| PackageIdSpec::parse(s))
.collect::<Result<Vec<_>, _>>()?;

// Updates often require a lot of modifications to the registry, so ensure
// that we're synchronized against other Cargos.
let _lock = gctx.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
Expand All @@ -239,7 +244,7 @@ pub fn upgrade_manifests(
.try_map_dependencies(|d| {
upgrade_dependency(
&gctx,
to_update,
&to_update,
&mut registry,
&mut upgrades,
&mut upgrade_messages,
Expand All @@ -253,7 +258,7 @@ pub fn upgrade_manifests(

fn upgrade_dependency(
gctx: &GlobalContext,
to_update: &Vec<String>,
to_update: &Vec<PackageIdSpec>,
registry: &mut PackageRegistry<'_>,
upgrades: &mut UpgradeMap,
upgrade_messages: &mut HashSet<String>,
Expand All @@ -271,7 +276,18 @@ fn upgrade_dependency(
return Ok(dependency);
}

if !to_update.is_empty() && !to_update.contains(&name.to_string()) {
if !to_update.is_empty()
&& !to_update.iter().any(|spec| {
spec.name() == name.as_str()
&& dependency.source_id().is_registry()
&& spec
.url()
.map_or(true, |url| url == dependency.source_id().url())
&& spec
.version()
.map_or(true, |v| dependency.version_req().matches(&v))
})
{
trace!("skipping dependency `{}` not selected for upgrading", name);
return Ok(dependency);
}
Expand Down
31 changes: 27 additions & 4 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,12 @@ fn update_breaking_spec_version() {
// Invalid spec
p.cargo("update -Zunstable-options --breaking incompatible@foo")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr("")
.with_status(101)
.with_stderr(
"\
[ERROR] expected a version like \"1.32\"
",
)
.run();

// Spec version not matching our current dependencies
Expand All @@ -2265,20 +2270,38 @@ fn update_breaking_spec_version() {
// Accepted spec
p.cargo("update -Zunstable-options --breaking [email protected]")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr("")
.with_stderr(
"\
[UPDATING] `[..]` index
[UPGRADING] incompatible ^1.0 -> ^2.0
[LOCKING] 1 package to latest compatible version
[UPDATING] incompatible v1.0.0 -> v2.0.0
",
)
.run();

// Accepted spec, full format
Package::new("incompatible", "3.0.0").publish();
p.cargo("update -Zunstable-options --breaking https://github.com/rust-lang/crates.io-index#[email protected]")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr("")
.with_stderr(
"\
[UPDATING] `[..]` index
[UPGRADING] incompatible ^2.0 -> ^3.0
[LOCKING] 1 package to latest compatible version
[UPDATING] incompatible v2.0.0 -> v3.0.0
",
)
.run();

// Spec matches a dependency that will not be upgraded
p.cargo("update -Zunstable-options --breaking [email protected]")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr("")
.with_stderr(
"\
[UPDATING] `[..]` index
",
)
.run();

// Non-existing versions
Expand Down

0 comments on commit 0d59dfc

Please sign in to comment.