diff --git a/crates/nu-command/src/filesystem/ucp.rs b/crates/nu-command/src/filesystem/ucp.rs index a8603295ed..b33480de2d 100644 --- a/crates/nu-command/src/filesystem/ucp.rs +++ b/crates/nu-command/src/filesystem/ucp.rs @@ -166,6 +166,17 @@ impl Command for UCp { if f.is_empty() { return Err(ShellError::FileNotFound(p.span)); } + let any_source_is_dir = f.iter().any(|f| matches!(f, f if f.is_dir())); + if any_source_is_dir && !recursive { + return Err(ShellError::GenericError( + "could_not_copy_directory".into(), + "resolves to a directory (not copied)".into(), + Some(p.span), + Some("Directories must be copied using \"--recursive\"".into()), + Vec::new(), + )); + } + Ok(f) } Err(e) => Err(ShellError::GenericError( diff --git a/crates/nu-command/tests/commands/ucp.rs b/crates/nu-command/tests/commands/ucp.rs index c359f542be..0b04152042 100644 --- a/crates/nu-command/tests/commands/ucp.rs +++ b/crates/nu-command/tests/commands/ucp.rs @@ -91,15 +91,8 @@ fn error_if_attempting_to_copy_a_directory_to_another_directory_impl(progress: b dirs.test().display() ); - // Changing to GNU error like error - // Slight bug since it should say formats, but its saying "." due to the `strip_prefix` - // that i do I think - // assert!(actual.err.contains("formats")); - // assert!(actual.err.contains("resolves to a directory (not copied)")); - assert!(actual.err.contains("omitting directory")); - - // directories must be copied using --recursive - // gnu says "omitting directory", vbecause -r was not given + assert!(actual.err.contains("formats")); + assert!(actual.err.contains("resolves to a directory (not copied)")); }); }