Skip to content

Commit f61d42d

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 ebee726 commit f61d42d

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
@@ -817,13 +817,19 @@ fn clean_dry_run() {
817817
// Start with no files.
818818
p.cargo("clean --dry-run")
819819
.with_stdout("")
820-
.with_stderr("[SUMMARY] 0 files")
820+
.with_stderr(
821+
"[SUMMARY] 0 files\n\
822+
[WARNING] no files deleted due to --dry-run",
823+
)
821824
.run();
822825
p.cargo("check").run();
823826
let before = ls_r();
824827
p.cargo("clean --dry-run")
825828
.with_stdout("[CWD]/target")
826-
.with_stderr("[SUMMARY] [..] files, [..] total")
829+
.with_stderr(
830+
"[SUMMARY] [..] files, [..] total\n\
831+
[WARNING] no files deleted due to --dry-run",
832+
)
827833
.run();
828834
// Verify it didn't delete anything.
829835
let after = ls_r();
@@ -833,7 +839,10 @@ fn clean_dry_run() {
833839
// Verify the verbose output.
834840
p.cargo("clean --dry-run -v")
835841
.with_stdout_unordered(expected)
836-
.with_stderr("[SUMMARY] [..] files, [..] total")
842+
.with_stderr(
843+
"[SUMMARY] [..] files, [..] total\n\
844+
[WARNING] no files deleted due to --dry-run",
845+
)
837846
.run();
838847
}
839848

0 commit comments

Comments
 (0)