From f61d42d5ef97fe1b0fdaacc7603e465bdc2bbb06 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 10 Sep 2023 12:07:49 -0700 Subject: [PATCH] Add a warning to `cargo clean --dry-run` This makes it more consistent with other `--dry-run` commands, and makes it clearer to the user that cargo did not do anything. --- src/cargo/ops/cargo_clean.rs | 8 +++++++- tests/testsuite/clean.rs | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 84ecc5dbf..2a7d359f9 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -417,7 +417,13 @@ impl<'cfg> CleanContext<'cfg> { }; self.config .shell() - .status(status, format!("{file_count}{byte_count}")) + .status(status, format!("{file_count}{byte_count}"))?; + if self.dry_run { + self.config + .shell() + .warn("no files deleted due to --dry-run")?; + } + Ok(()) } /// Deletes all of the given paths, showing a progress bar as it proceeds. diff --git a/tests/testsuite/clean.rs b/tests/testsuite/clean.rs index 9474e3996..14a891368 100644 --- a/tests/testsuite/clean.rs +++ b/tests/testsuite/clean.rs @@ -817,13 +817,19 @@ fn clean_dry_run() { // Start with no files. p.cargo("clean --dry-run") .with_stdout("") - .with_stderr("[SUMMARY] 0 files") + .with_stderr( + "[SUMMARY] 0 files\n\ + [WARNING] no files deleted due to --dry-run", + ) .run(); p.cargo("check").run(); let before = ls_r(); p.cargo("clean --dry-run") .with_stdout("[CWD]/target") - .with_stderr("[SUMMARY] [..] files, [..] total") + .with_stderr( + "[SUMMARY] [..] files, [..] total\n\ + [WARNING] no files deleted due to --dry-run", + ) .run(); // Verify it didn't delete anything. let after = ls_r(); @@ -833,7 +839,10 @@ fn clean_dry_run() { // Verify the verbose output. p.cargo("clean --dry-run -v") .with_stdout_unordered(expected) - .with_stderr("[SUMMARY] [..] files, [..] total") + .with_stderr( + "[SUMMARY] [..] files, [..] total\n\ + [WARNING] no files deleted due to --dry-run", + ) .run(); }