Skip to content

🐛 Fix silent overwrite of main.py and README.md in current directory mode - #148

Open
benjaminkincses wants to merge 2 commits into
fastapi:mainfrom
benjaminkincses:fix/no-silent-overwrite-current-dir
Open

benjaminkincses wants to merge 2 commits into
fastapi:mainfrom
benjaminkincses:fix/no-silent-overwrite-current-dir

Conversation

@benjaminkincses

Copy link
Copy Markdown

Running fastapi new with no arguments (or .) in a directory that already has a main.py and README.md but no pyproject.toml overwrites both files with the hello world template. No warning, no backup.

Subdirectory mode already refuses to touch an existing directory. Current directory mode had no check at all for the two files it writes.

Fix: in current directory mode, refuse to run when main.py or README.md already exist, with an error naming them.

Test: test_refuses_to_overwrite_existing_files_in_current_dir writes marker files, runs the CLI with no arguments, and asserts exit code 1 plus both files unchanged. It fails on current main (exit code 0, files replaced) and passes with this fix.

@benjaminkincses
benjaminkincses marked this pull request as ready for review October 23, 2026 05:24
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant