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

opam switch create: better handling of already present local switch #6163

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
17 changes: 12 additions & 5 deletions src/client/opamSwitchCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,20 @@ let create
let simulate = OpamStateConfig.(!r.dryrun) || OpamClientConfig.(!r.show) in
if OpamGlobalState.switch_exists gt switch then
OpamConsole.error_and_exit `Bad_arguments
"There already is an installed switch named %s"
"There already is an installed switch named %s.\n\
Please see https://opam.ocaml.org/doc/FAQ.html#switch-already-present"
(OpamSwitch.to_string switch);
if Sys.file_exists (OpamFilename.Dir.to_string comp_dir) then
OpamConsole.error_and_exit `Bad_arguments
"Directory %S already exists, please choose a different name"
(OpamFilename.Dir.to_string comp_dir);
let gt, st =
if not (OpamFilename.dir_is_empty comp_dir) then
OpamConsole.error_and_exit `Bad_arguments
"Directory %S already exists, please choose a different name"
(OpamFilename.Dir.to_string comp_dir)
else
if not (OpamConsole.confirm
"Directory %S exitst and is empty, remove it?") then
OpamConsole.error_and_exit `Aborted "Remove %S directory and recreate switch"
else
let gt, st =
Comment on lines +302 to +311
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not (OpamFilename.dir_is_empty comp_dir) then
OpamConsole.error_and_exit `Bad_arguments
"Directory %S already exists, please choose a different name"
(OpamFilename.Dir.to_string comp_dir)
else
if not (OpamConsole.confirm
"Directory %S exitst and is empty, remove it?") then
OpamConsole.error_and_exit `Aborted "Remove %S directory and recreate switch"
else
let gt, st =
if not (OpamFilename.dir_is_empty comp_dir) then
OpamConsole.error_and_exit `Bad_arguments
"Directory %S already exists, please choose a different name"
(OpamFilename.Dir.to_string comp_dir)
else if not (OpamConsole.confirm
"Directory %S exists and is empty, remove it?") then
OpamConsole.error_and_exit `Aborted "Remove %S directory and recreate switch"
else
let gt, st =

if not simulate then
let gt =
OpamSwitchAction.create_empty_switch gt ?synopsis ?repos ~invariant
Expand Down
Loading