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 12, 2024
1 parent 3a45d6e commit 2de4c24
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
18 changes: 15 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,14 @@ 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()
&& spec
.version()
.map_or(true, |v| dependency.version_req().matches(&v))
})
{
trace!("skipping dependency `{}` not selected for upgrading", name);
return Ok(dependency);
}
Expand Down
21 changes: 19 additions & 2 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2244,11 +2244,29 @@ fn update_breaking_spec_version() {

Package::new("incompatible", "2.0.0").publish();

p.cargo("update -Zunstable-options --breaking incompatible@foo")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_status(101)
.with_stderr(
"\
[ERROR] expected a version like \"1.32\"
",
)
.run();

p.cargo("update -Zunstable-options --breaking [email protected]")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr("")
.run();

p.cargo("update -Zunstable-options --breaking [email protected]")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr(
// FIXME: This is wrong.
"\
[UPDATING] `[..]` index
[UPGRADING] incompatible ^1.0 -> ^2.0
[LOCKING] 1 package to latest compatible version
[UPDATING] incompatible v1.0.0 -> v2.0.0
",
)
.run();
Expand All @@ -2259,7 +2277,6 @@ fn update_breaking_spec_version() {
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] compatible v1.0.0 -> v1.0.1
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
",
)
.run();
Expand Down

0 comments on commit 2de4c24

Please sign in to comment.