Skip to content

Commit 1745dc9

Browse files
committed
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.
1 parent 0e1c2c7 commit 1745dc9

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/cargo/ops/cargo_clean.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,13 @@ impl<'cfg> CleanContext<'cfg> {
417417
};
418418
self.config
419419
.shell()
420-
.status(status, format!("{file_count}{byte_count}"))
420+
.status(status, format!("{file_count}{byte_count}"))?;
421+
if self.dry_run {
422+
self.config
423+
.shell()
424+
.warn("no files deleted due to --dry-run")?;
425+
}
426+
Ok(())
421427
}
422428

423429
/// Deletes all of the given paths, showing a progress bar as it proceeds.

tests/testsuite/clean.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,19 @@ fn clean_dry_run() {
707707
// Start with no files.
708708
p.cargo("clean --dry-run")
709709
.with_stdout("")
710-
.with_stderr("[SUMMARY] 0 files")
710+
.with_stderr(
711+
"[SUMMARY] 0 files\n\
712+
[WARNING] no files deleted due to --dry-run",
713+
)
711714
.run();
712715
p.cargo("check").run();
713716
let before = ls_r();
714717
p.cargo("clean --dry-run")
715718
.with_stdout("[CWD]/target")
716-
.with_stderr("[SUMMARY] [..] files, [..] total")
719+
.with_stderr(
720+
"[SUMMARY] [..] files, [..] total\n\
721+
[WARNING] no files deleted due to --dry-run",
722+
)
717723
.run();
718724
// Verify it didn't delete anything.
719725
let after = ls_r();
@@ -723,7 +729,10 @@ fn clean_dry_run() {
723729
// Verify the verbose output.
724730
p.cargo("clean --dry-run -v")
725731
.with_stdout_unordered(expected)
726-
.with_stderr("[SUMMARY] [..] files, [..] total")
732+
.with_stderr(
733+
"[SUMMARY] [..] files, [..] total\n\
734+
[WARNING] no files deleted due to --dry-run",
735+
)
727736
.run();
728737
}
729738

0 commit comments

Comments
 (0)