diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 60cff5dfb..6642a2eb8 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -258,6 +258,16 @@ fn exec(files: &[OsString], b: &Behavior) -> UResult<()> { move_files_into_dir(&[source.clone()], target, b) } } else if target.exists() && source.is_dir() { + match b.overwrite { + OverwriteMode::NoClobber => return Ok(()), + OverwriteMode::Interactive => { + println!("{}: overwrite {}? ", uucore::util_name(), target.quote()); + if !read_yes() { + return Ok(()); + } + } + OverwriteMode::Force => {} + }; Err(MvError::NonDirectoryToDirectory( source.quote().to_string(), target.quote().to_string(), diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index a0bd0209d..fc0f9c18e 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -748,6 +748,19 @@ fn test_mv_errors() { .fails() .stderr_str() .is_empty()); + + // $ at.mkdir dir && at.touch file + // $ mv -i dir file + // err == mv: cannot overwrite non-directory 'file' with directory 'dir' + assert!(!scene + .ucmd() + .arg("-i") + .arg(dir) + .arg(file_a) + .pipe_in("y") + .fails() + .stderr_str() + .is_empty()); } #[test]