Skip to content

Commit

Permalink
Accurately show status when downgrading dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Mar 13, 2023
1 parent d4249c9 commit 20a5d2b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ fn substitute_macros(input: &str) -> String {
("[CHECKING]", " Checking"),
("[COMPLETED]", " Completed"),
("[CREATED]", " Created"),
("[DOWNGRADING]", " Downgrading"),
("[FINISHED]", " Finished"),
("[ERROR]", "error:"),
("[WARNING]", "warning:"),
Expand Down
9 changes: 7 additions & 2 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::util::CargoResult;
use anyhow::Context;
use log::debug;
use std::collections::{BTreeMap, HashSet};
use termcolor::Color::{self, Cyan, Green, Red};
use termcolor::Color::{self, Cyan, Green, Red, Yellow};

pub struct UpdateOptions<'a> {
pub config: &'a Config,
Expand Down Expand Up @@ -142,7 +142,12 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
} else {
format!("{} -> v{}", removed[0], added[0].version())
};
print_change("Updating", msg, Green)?;

if removed[0].version() > added[0].version() {
print_change("Downgrading", msg, Yellow)?;
} else {
print_change("Updating", msg, Green)?;
}
} else {
for package in removed.iter() {
print_change("Removing", format!("{}", package), Red)?;
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ fn main(){
.with_status(0)
.with_stderr(
"\
[UPDATING] present_dep v1.2.9 -> v1.2.3
[DOWNGRADING] present_dep v1.2.9 -> v1.2.3
",
)
.run();
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ fn update_precise() {
.with_stderr(
"\
[UPDATING] `[..]` index
[UPDATING] serde v0.2.1 -> v0.2.0
[DOWNGRADING] serde v0.2.1 -> v0.2.0
",
)
.run();
Expand Down Expand Up @@ -492,7 +492,7 @@ fn update_precise_first_run() {
.with_stderr(
"\
[UPDATING] `[..]` index
[UPDATING] serde v0.2.1 -> v0.2.0
[DOWNGRADING] serde v0.2.1 -> v0.2.0
",
)
.run();
Expand Down

0 comments on commit 20a5d2b

Please sign in to comment.