mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Make default for mv safer, require -f
to overwrite (#6904)
* fix: ✨ "saner" default for mv fixes #6747 As highlighted in the issue, the default behavior of nu currently is to overwrite the destination file without notice. This is not a "standard" expectation users that want this behavior can create a dedicated alias. * fix: 📝 edit the comment * fix: ✨ updated the tests * fix: 🚧 use --force for case test
This commit is contained in:
@ -23,7 +23,7 @@ fn moves_a_file() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overwrites_if_moving_to_existing_file() {
|
||||
fn overwrites_if_moving_to_existing_file_and_force_provided() {
|
||||
Playground::setup("mv_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("andres.txt"), EmptyFile("jonathan.txt")]);
|
||||
|
||||
@ -32,7 +32,7 @@ fn overwrites_if_moving_to_existing_file() {
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv andres.txt jonathan.txt"
|
||||
"mv andres.txt -f jonathan.txt"
|
||||
);
|
||||
|
||||
assert!(!original.exists());
|
||||
@ -207,6 +207,19 @@ fn errors_if_source_doesnt_exist() {
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_if_moving_to_existing_file_without_force() {
|
||||
Playground::setup("mv_test_10_0", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![EmptyFile("andres.txt"), EmptyFile("jonathan.txt")]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"mv andres.txt jonathan.txt"
|
||||
);
|
||||
assert!(actual.err.contains("file already exists"))
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_destination_doesnt_exist() {
|
||||
Playground::setup("mv_test_10_1", |dirs, sandbox| {
|
||||
@ -438,7 +451,7 @@ fn mv_change_case_of_file() {
|
||||
|
||||
nu!(
|
||||
cwd: dirs.test(),
|
||||
format!("mv {original_file_name} {new_file_name}")
|
||||
format!("mv {original_file_name} -f {new_file_name}")
|
||||
);
|
||||
|
||||
// Doing this instead of `Path::exists()` because we need to check file existence in
|
||||
|
Reference in New Issue
Block a user