Skip to content
Open
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
12 changes: 12 additions & 0 deletions src/alr/alr-commands-init.adb
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ package body Alr.Commands.Init is

Query_Crate_Name (Args, Info);

-- check if project name is already in use in dir
if Cmd.In_Place then
if Dirs.Exists ("alire.toml") then
Reportaise_Wrong_Arguments ("alire.toml already exists");
end if;
else
if Dirs.Exists (Dirs."/" (To_String (Info.Name), "alire.toml")) then
Reportaise_Wrong_Arguments
(To_String (Info.Name) & "/alire.toml already exists");
end if;
end if;

if Cmd.Bin then
Info.Is_Library := False;
elsif Cmd.Lib then
Expand Down
8 changes: 8 additions & 0 deletions testsuite/tests/init/crate-name-validation/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ def assert_that(name, fails_with):
for crate_type in CRATE_TYPES:
run_alr('init', f"--{crate_type}", f"{VALID_NAME}{crate_type}")

# Test if Project already exists
run_alr('init', 'foo')
p = run_alr('init', 'foo', complain_on_error=False)
assert_match("ERROR: foo/alire.toml already exists", p.out)

p = run_alr('--chdir=foo', 'init', '--in-place', 'foo', complain_on_error=False)
assert_match("ERROR: alire.toml already exists", p.out)

print('SUCCESS')