Skip to content

fix: ✨ "saner" default for mv#6904

Merged
sholderbach merged 5 commits intonushell:mainfrom
melMass:mel/fix/6747
Oct 29, 2022
Merged

fix: ✨ "saner" default for mv#6904
sholderbach merged 5 commits intonushell:mainfrom
melMass:mel/fix/6747

Conversation

@melMass
Copy link
Copy Markdown
Contributor

@melMass melMass commented Oct 25, 2022

Description

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.

Tests

Make sure you've done the following:

  • I did not find any tests for mv Add tests that cover your changes, either in the command examples, the crate/tests folder, or in the /tests folder.
  • Try to think about corner cases and various ways how your changes could break. Cover them with tests.
  • If adding tests is not possible, please document in the PR body a minimal example with steps on how to reproduce so one can verify your change works.

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace --features=extra to check that all the tests pass

Documentation

Yes, see nushell/nushell.github.io/pull/648

fixes nushell#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.
@melMass melMass changed the title Mel/fix/6747 fix: ✨ "saner" default for mv Oct 25, 2022
@melMass
Copy link
Copy Markdown
Contributor Author

melMass commented Oct 25, 2022

Oops the CI did catch errors, not sure why I did not see those tests locally my bad
image

@melMass
Copy link
Copy Markdown
Contributor Author

melMass commented Oct 25, 2022

Im not sure why but locally I can't get to trigger those errors, looking closer into it it seems to silently fail

image

image

@rgwood
Copy link
Copy Markdown
Contributor

rgwood commented Oct 26, 2022

Thank you! Looks good to me, I agree that this is much safer+saner behaviour than before. Just going to discuss with the rest of the team before merging.

If you have time, would you mind documenting this breaking change in the blog post/release notes for the upcoming v0.71 release? nushell/nushell.github.io#647

@rgwood
Copy link
Copy Markdown
Contributor

rgwood commented Oct 26, 2022

I think we generally like this change but it might be good to add some more tests. @sholderbach had some ideas/requests for testing, @sholderbach do you mind elaborating here?

@webbedspace
Copy link
Copy Markdown
Contributor

webbedspace commented Oct 27, 2022

I just had a thought… maybe not in this PR, but do you think you could add a similar flag for save, that if absent stops overwrites when it also doesn't have -a? I looked up the zsh NOCLOBBER setting, and not only does it protect mv, but also piping to a file (Nushell equivalent being save).

@melMass
Copy link
Copy Markdown
Contributor Author

melMass commented Oct 27, 2022

Nice! @rgwood , yes I can PR the change in the 0.71 release branch, I guess this should be listed in "breaking changes" ?

@melMass
Copy link
Copy Markdown
Contributor Author

melMass commented Oct 27, 2022

also piping to a file (Nushell equivalent being save).

This sound like something I can handle! Can you open a dedicated issue ?

@sholderbach
Copy link
Copy Markdown
Member

I like the change and being more defensive is definitely a good default. GNU coreutils mv file fileexists will allow overwriting regular files but they don't seem to document their rules publicly. (The comments in #6920 hint to me that after landing this change we might still want to provide the people who want to live dangerous with a config option to go silent in some common cases)

The only question for testing I would have, are we safely prohibiting overwriting non-empty directories after this change? Generally I think in this case for testing it is more important that we test, that we don't cause unintended data loss for the users. I think for files you got us covered.

@sholderbach sholderbach added the notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes label Oct 27, 2022
@melMass
Copy link
Copy Markdown
Contributor Author

melMass commented Oct 28, 2022

Nice!
I'll check this case and if it's needs an extra test later today!

@melMass
Copy link
Copy Markdown
Contributor Author

melMass commented Oct 29, 2022

After trying to come up with a new test I'm actually unsure what you meant Sholder?
mv to an existing folder moves it inside it, I'm not sure of the case you had in mind.

@sholderbach
Copy link
Copy Markdown
Member

@melMass you are correct, all other cases I was wondering about (moving a folder on a file etc.) are covered by tests and protected.
So I am happy to merge it and get ready for user feedback.
Would you mind adding the breaking change to the release notes branch of our documentation/blog?
https://github.com/nushell/nushell.github.io/blob/release-notes-0.71/blog/2022-11-08-nushell-0.71.md

@sholderbach sholderbach merged commit 843d8c2 into nushell:main Oct 29, 2022
@melMass
Copy link
Copy Markdown
Contributor Author

melMass commented Oct 29, 2022

Would you mind adding the breaking change to the release notes branch of our documentation/blog?

@sholderbach I usually leave that out to better PR people 😅 as english is not my main language, but I drafted it here:
https://github.com/nushell/nushell.github.io/pull/653/files

@sholderbach
Copy link
Copy Markdown
Member

Thanks! Looks perfectly understandable! and people on the internet will be happy to correct any mistakes :P

@dandavison
Copy link
Copy Markdown
Contributor

"saner" default
This is not a "standard" expectation users that want this behavior

I'm a bit confused by this PR. UNIX and Linux behavior has always been for commands such as mv and cp to overwrite destination files with the same name.

@webbedspace
Copy link
Copy Markdown
Contributor

Every zsh guide I've seen tells you to turn the NOCLOBBER setting on (which is the equivalent to this) so if that isn't demand, I don't know what is.

@dandavison
Copy link
Copy Markdown
Contributor

For people who've been using Unix/Linux for a long time, this is very unexpected behavior. There is another argument against this default: for people whose jobs require them to use command-line interfaces in critical production contexts, it is important that they do NOT get accustomed to NOCLOBBER behavior.

As @sholderbach mentioned above, I think we really want a config option controlling this, since it's a bit awkward in Nushell currently to override a default while retaining control over the rest of the command, i.e. there's no way to do the equivalent of

def mv(**kwargs):
    stdlib.mv(force=True, **kwargs)

@webbedspace
Copy link
Copy Markdown
Contributor

Well, rm does have those two flags and one config setting that control trashing vs. erasing… so it's not unprecedented…

@dandavison
Copy link
Copy Markdown
Contributor

Also we should bring cp into line with mv -- currently cp clobbers by default and lacks a --force option.

Well, rm does have those two flags and one config setting that control trashing vs. erasing

I didn't quite follow what you were saying here.

@webbedspace
Copy link
Copy Markdown
Contributor

Y'know, this:

  rm: {
    always_trash: true # always act as if -t was given. Can be overridden with -p
  }

Hofer-Julian pushed a commit to Hofer-Julian/nushell that referenced this pull request Jan 27, 2023
* Release notes for nushell 0.71

Please add your important new features and breaking changes to the release notes by commiting to/opening a PR against the `release-notes-0.71` branch! Thanks for helping out!

* add right prompt release notes (nushell#650)

* add right prompt release notes

* add a comparison image

* docs: documents the changes from nushell#6904 (nushell#653)

* docs: document changes from nushell#7007 (nushell#659)

Co-authored-by: David Matos <david@track32.nl>

* Update breaking changes

* Breaking change in `format filesize`

* Stubs for themes of the release

Listed some important improvements that might be worth telling the user about.

* mention Reilly's changes for this release

* Update 2022-11-08-nushell-0.71.md (nushell#664)

* finish up blog post

Co-authored-by: nibon7 <nibon7@163.com>
Co-authored-by: Mel Massadian <melmassadian@gmail.com>
Co-authored-by: David Matos <dmatos2012@users.noreply.github.com>
Co-authored-by: David Matos <david@track32.nl>
Co-authored-by: Reilly Wood <26268125+rgwood@users.noreply.github.com>
Co-authored-by: Jakub Žádník <kubouch@gmail.com>
Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mv -f switch highly desired, so as to not overwrite files by default

5 participants