1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

mv: show prompt for -u --interactive

This commit is contained in:
Daniel Hofstetter 2025-01-20 10:47:47 +01:00
parent 6c26b4c2df
commit 20eb5466c0
2 changed files with 24 additions and 7 deletions

View file

@ -576,13 +576,6 @@ fn rename(
let mut backup_path = None; let mut backup_path = None;
if to.exists() { if to.exists() {
if opts.update == UpdateMode::ReplaceIfOlder && opts.overwrite == OverwriteMode::Interactive
{
// `mv -i --update old new` when `new` exists doesn't move anything
// and exit with 0
return Ok(());
}
if opts.update == UpdateMode::ReplaceNone { if opts.update == UpdateMode::ReplaceNone {
if opts.debug { if opts.debug {
println!("skipped {}", to.quote()); println!("skipped {}", to.quote());

View file

@ -1119,6 +1119,30 @@ fn test_mv_arg_update_older_dest_older() {
assert_eq!(at.read(old), new_content); assert_eq!(at.read(old), new_content);
} }
#[test]
fn test_mv_arg_update_older_dest_older_interactive() {
let (at, mut ucmd) = at_and_ucmd!();
let old = "old";
let new = "new";
let old_content = "file1 content\n";
let new_content = "file2 content\n";
let mut f = at.make_file(old);
f.write_all(old_content.as_bytes()).unwrap();
f.set_modified(std::time::UNIX_EPOCH).unwrap();
at.write(new, new_content);
ucmd.arg(new)
.arg(old)
.arg("--interactive")
.arg("--update=older")
.fails()
.stderr_contains("overwrite 'old'?")
.no_stdout();
}
#[test] #[test]
fn test_mv_arg_update_short_overwrite() { fn test_mv_arg_update_short_overwrite() {
// same as --update=older // same as --update=older