Skip to content

Commit b711736

Browse files
committed
fix(upgrade): Make --skip-compatible default
Fixes #552
1 parent e5279e6 commit b711736

File tree

5 files changed

+37
-34
lines changed

5 files changed

+37
-34
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ OPTIONS:
154154
--manifest-path <PATH> Path to the manifest to upgrade
155155
--offline Run without accessing the network
156156
-p, --package <PKGID> Package id of the crate to add this dependency to
157-
--skip-compatible Only update a dependency if the new version is semver incompatible
158157
--skip-pinned Only update a dependency if it is not currently pinned in the
159158
manifest. "Pinned" refers to dependencies with a '=' or '<' or
160159
'<=' version requirement

src/bin/upgrade/upgrade.rs

+32-28
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ pub struct UpgradeArgs {
6767
#[clap(long)]
6868
dry_run: bool,
6969

70-
/// Only update a dependency if the new version is semver incompatible.
71-
#[clap(long, conflicts_with = "to-lockfile")]
72-
skip_compatible: bool,
73-
7470
/// Only update a dependency if it is not currently pinned in the manifest.
7571
/// "Pinned" refers to dependencies with a '=' or '<' or '<=' version requirement
7672
#[clap(long)]
@@ -245,9 +241,18 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> {
245241
} else {
246242
// Not checking `selected_dependencies.is_empty`, it was checked earlier
247243
let new_version = if args.to_lockfile {
248-
find_locked_version(&dependency.name, &old_version_req, &locked).ok_or_else(
249-
|| anyhow::format_err!("{} is not in block file", dependency.name),
250-
)
244+
match find_locked_version(&dependency.name, &old_version_req, &locked) {
245+
Some(new_version) => new_version,
246+
None => {
247+
args.verbose(|| {
248+
shell_warn(&format!(
249+
"ignoring {}, could not find package: not in lock file",
250+
dependency.toml_key(),
251+
))
252+
})?;
253+
continue;
254+
}
255+
}
251256
} else {
252257
// Update indices for any alternative registries, unless
253258
// we're offline.
@@ -263,7 +268,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> {
263268
}
264269
}
265270
let is_prerelease = old_version_req.contains('-');
266-
get_latest_dependency(
271+
let new_version = get_latest_dependency(
267272
&dependency.name,
268273
is_prerelease,
269274
&manifest_path,
@@ -273,34 +278,33 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> {
273278
d.version()
274279
.expect("registry packages always have a version")
275280
.to_owned()
276-
})
277-
};
278-
let new_version = match new_version {
279-
Ok(new_version) => new_version,
280-
Err(err) => {
281+
});
282+
let new_version = match new_version {
283+
Ok(new_version) => new_version,
284+
Err(err) => {
285+
args.verbose(|| {
286+
shell_warn(&format!(
287+
"ignoring {}, could not find package: {}",
288+
dependency.toml_key(),
289+
err
290+
))
291+
})?;
292+
continue;
293+
}
294+
};
295+
if old_version_compatible(&old_version_req, &new_version) {
281296
args.verbose(|| {
282297
shell_warn(&format!(
283-
"ignoring {}, could not find package: {}",
298+
"ignoring {}, version ({}) is compatible with {}",
284299
dependency.toml_key(),
285-
err
300+
old_version_req,
301+
new_version
286302
))
287303
})?;
288304
continue;
289305
}
306+
new_version
290307
};
291-
if args.skip_compatible
292-
&& old_version_compatible(&old_version_req, &new_version)
293-
{
294-
args.verbose(|| {
295-
shell_warn(&format!(
296-
"ignoring {}, version ({}) is compatible with {}",
297-
dependency.toml_key(),
298-
old_version_req,
299-
new_version
300-
))
301-
})?;
302-
continue;
303-
}
304308
let mut new_version_req = new_version;
305309
let new_ver: semver::Version = new_version_req.parse()?;
306310
match cargo_edit::upgrade_requirement(&old_version_req, &new_ver) {

tests/cmd/upgrade/skip_compatible.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
bin.name = "cargo-upgrade"
2-
args = ["upgrade", "--skip-compatible", "--verbose"]
2+
args = ["upgrade", "--verbose"]
33
status = "success"
44
stdout = ""
55
stderr = """

tests/cmd/upgrade/skip_pinned.out/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ lessthan = "<0.4"
99
lessorequal = "<=3.0"
1010
caret = "^99999.0"
1111
tilde = "~99999.0.0"
12-
greaterthan = "99999.0.0"
13-
greaterorequal = "99999.0.0"
12+
greaterthan = ">2.0"
13+
greaterorequal = ">=2.1.0"
1414
wildcard = "99999.*"

tests/cmd/upgrade/skip_pinned.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ warning: ignoring lessthan, version (<0.4) is pinned
1010
warning: ignoring lessorequal, version (<=3.0) is pinned
1111
Upgrading caret: ^3.0 -> ^99999.0
1212
Upgrading tilde: ~4.1.0 -> ~99999.0.0
13-
Upgrading greaterthan: >2.0 -> v99999.0.0
14-
Upgrading greaterorequal: >=2.1.0 -> v99999.0.0
13+
warning: ignoring greaterthan, version (>2.0) is compatible with 99999.0.0
14+
warning: ignoring greaterorequal, version (>=2.1.0) is compatible with 99999.0.0
1515
Upgrading wildcard: v3.* -> v99999.*
1616
"""
1717
fs.sandbox = true

0 commit comments

Comments
 (0)