Skip to content

Revert "mkdir errors on already-created dir" - #19008

Merged
fdncred merged 1 commit into
mainfrom
revert-19006-mkdir-existing
Sep 10, 2026
Merged

fdncred merged 1 commit into
mainfrom
revert-19006-mkdir-existing

Conversation

@fdncred

@fdncred fdncred commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Reverts #19006

@pickx if you want to implement a new flag for this functionality instead of having it as default, have at it.

@fdncred
fdncred merged commit 0ffb26c into main Sep 10, 2026
15 checks passed
@fdncred
fdncred deleted the revert-19006-mkdir-existing branch September 10, 2026 14:57
@github-actions github-actions Bot added this to the v0.116.0 milestone Sep 10, 2026
@pickx

pickx commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

sure it's a breaking change, but...
the --verbose behavior is a bug. and is asserting dir existence really the main usecase for mkdir, such that "check the dir already exists" is the behavior that becomes special-cased? there's path type, path exists, etc.

anyway, if that's what has been decided, then sure, I'll make a quick PR 👍

@fdncred

fdncred commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@weirdan any thoughts about how to move forward considering @pickx's comments above and yours in #19006 ?

@weirdan

weirdan commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Agree with the --verbose part, it would be nice if it told which directories existed.

As for the whether the error should be default, it's not a new decision. It's explicitly documented, e.g. here https://www.nushell.sh/book/moving_around.html#creating-a-directory. In REPL it doesn't matter that much, as you can just ignore the error, but in scripts it's quite convenient, as you don't have to wrap it in try. And if you really want to get an error (which, in my experience is rare) then an opt-in via the switch looks like the best way to achieve that to me.

Jorge-Polanco-Roque added a commit to Jorge-Polanco-Roque/nushell that referenced this pull request Sep 15, 2026
The default mkdir stays -p-like/idempotent (making it error by default was
reverted in nushell#19008 as a breaking change). Per the maintainer's suggestion on
already exists ("<path>: File exists", matching coreutils) while still
creating non-existing targets in the same call. Default behavior unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
fdncred pushed a commit that referenced this pull request Sep 16, 2026
…#19021)

# Description

Follow-up to #19003. The default `mkdir` behavior (idempotent,
`-p`-like) stays exactly as-is — #19006 tried making it error by default
and was reverted in #19008, since people rely on `mkdir foo` to just
ensure a directory exists (and `^mkdir -p` doesn't error either). Per
@fdncred's suggestion in the thread, this instead adds an **opt-in**
flag.

With `--fail-if-exists`, `mkdir` errors on a target that already exists
(message `<path>: File exists`, matching coreutils), while still
creating any non-existing targets passed in the same call. Without the
flag, nothing changes.

The `--verbose` `created: true` half of the issue was already fixed in
#19017, so this covers the remaining piece.

# User-Facing Changes

New opt-in switch: `mkdir --fail-if-exists <dir>` (short: none) errors
if the directory already exists instead of silently succeeding. Default
`mkdir` is unchanged.

# Tests + Formatting

Added `commands::umkdir` tests: errors on an existing dir with the flag,
still creates new dirs with the flag, and `-v --fail-if-exists` reports
`created: false`. Existing default-behavior tests (idempotent mkdir,
intermediary dirs) still pass. `cargo fmt --all --check`, `cargo clippy
-p nu-command`, and the `nu-command` test suite are clean.

# After Submitting

Nothing needed (no doc/`std` changes).

---
_Disclosure: I use AI assistance for code review and for drafting text
(English isn't my first language); I review and verify every change
myself before sending it._

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
@cptpiepmatz cptpiepmatz added the notes:hide Noted only in "Full Changelog" section label Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:hide Noted only in "Full Changelog" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants