Cherry Pick: New File never overwrites a file the project panel does not list
Summary
New File in the embedded project panel could write over a file the panel does not list (a hidden or filtered file), emptying it. This is one of the 7 High defects Heal reported for Cherry Pick.
49a93a0d—Worktree::create_entry_withcreates a file exclusively (CreateOptions { overwrite: false, ignore_if_exists: false }). The parent folder is created only if it is missing. When the path already exists, it returns a typedEntryAlreadyExists. The project panel'sconfirm_edituses it for new entries and shows the existing-name error instead of writing.2fdc4700— a file created this way starts empty, on bothFakeFsandRealFs.c0874ab7— follow-up from review: a new folder is created exclusively too (a folder the panel does not list was recorded as newly created, so undo would trash it); only anAlreadyExistsfailure is reported as one, andFakeFsnow fails that way likeRealFs; the error names what was typed (vault/a.txt), not the last path component.a8a1a796— comments only: a new folder is looked for first (creating one that is there succeeds), so one made in the moment between is adopted; a new file is exclusive.911be980— follow-up from review: a failure to look at the parent or the target is reported as that failure instead of being read as "absent", andAlreadyExistsfrom the create itself is reported as a taken name (a unit test pins which errors count as one). The documentation says a folder that appears after the look is adopted.
Tests: project_panel_tests.rs (a hidden file and a hidden folder are not overwritten, the error names what was typed, a free name is created) and crates/worktree/tests/integration/worktree_tests.rs (exclusive creation of files and folders, missing parent, existing target), plus a unit test in crates/worktree/src/worktree.rs. test_creating_excluded_entries now expects what a real filesystem does when a folder is created over a file: an error, not a toast.
Merge order
Merge this first. The Cherry Pick PR that follows moves the cherrypick-zed pin to 911be980.
Not covered
- External drag-and-drop and paste into the project panel can still overwrite a hidden target. That is a separate, older path.
- A remote worktree (collab or SSH remote server) still overwrites:
proto::CreateProjectEntrycarries no flag. Cherry Pick opens local worktrees only, so the protocol is left alone; the flag's documentation says so.
Release Notes:
- N/A
Summary by CodeRabbit
- Bug Fixes
- Creating a file or folder in a local workspace now reports an “already exists” error if the name is already taken, even when the existing item is not shown in the project panel.
- Existing files and folders are preserved when a name is already in use.
- Creating entries with unused names continues to work as expected.