Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on "dune init" if dir exists named "dune" #6705

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Report an error if `dune init ...` would create a "dune" file in a location
which already contains a "dune" directory (#6705, @gridbugs)

- Fix the parsing of alerts. They will now show up in diagnostics correctly.
(#6678, @rginberg)

Expand Down
5 changes: 5 additions & 0 deletions bin/dune_init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ module File = struct
let full_path = Path.relative path name in
let content =
if not (Path.exists full_path) then []
else if Path.is_directory full_path then
User_error.raise
[ Pp.textf "\"%s\" already exists and is a directory"
(Path.to_absolute_filename full_path)
]
else
match Io.with_lexbuf_from_file ~f:Dune_lang.Format.parse full_path with
| Dune_lang.Format.Sexps content -> content
Expand Down
22 changes: 22 additions & 0 deletions test/blackbox-tests/test-cases/init-error-if-dune-is-directory.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Report an error if `dune init ...` would create a "dune" file in a location
which already has a "dune" directory.

$ mkdir dune

$ dune init exe foo
Error:
"$TESTCASE_ROOT/dune"
already exists and is a directory
[1]

$ dune init lib foo
Error:
"$TESTCASE_ROOT/dune"
already exists and is a directory
[1]

$ dune init test foo
Error:
"$TESTCASE_ROOT/dune"
already exists and is a directory
[1]