Skip to content

Commit

Permalink
admin: add an upgrade advice if repo prior to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Feb 19, 2025
1 parent 0f81ab6 commit 8376637
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ users)
* ✘ The `-i`/`--ignore-test-doc` argument has been removed from `opam admin check` [#6335 @kit-ty-kate]
*`opam admin check` now sets `with-test` and `with-doc` to `false` instead of `true` [#6335 @kit-ty-kate]
* Enforce repository root check for all command [#6385 @rjbou]
* Add an upgrade advice is the repository is 1.2 version, for all command except upgrade [#6385 @rjbou]

## Opam installer

Expand Down
24 changes: 22 additions & 2 deletions src/client/opamAdminCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,33 @@ open Cmdliner

type command = unit Cmdliner.Term.t * Cmdliner.Cmd.info

let checked_repo_root () =
let repo_version_lt repo_root v =
let v' =
let open OpamStd.Option.Op in
(OpamFile.Repo.read_opt
(OpamRepositoryPath.repo repo_root)
>>= OpamFile.Repo.opam_version)
+! (OpamVersion.of_string "1.2")
in
if OpamVersion.compare v v' > 0 then Some v' else None

let checked_repo_root ?(check=true)() =
let repo_root = OpamFilename.cwd () in
if not (OpamFilename.exists_dir (OpamRepositoryPath.packages_dir repo_root))
then
OpamConsole.error_and_exit `Bad_arguments
"No repository found in current directory.\n\
Please make sure there is a \"packages%s\" directory" OpamArg.dir_sep;
(if check then
let default_current = "2.0" in
match repo_version_lt repo_root
(OpamVersion.of_string default_current) with
| Some v ->
OpamConsole.warning
"The repository is at version %s, \
please consider upgrading to %s with 'opam admin upgrade'"
(OpamVersion.to_string v) default_current
| None -> ());
repo_root

let global_options cli =
Expand Down Expand Up @@ -646,7 +666,7 @@ let upgrade_command cli =
in
let cmd global_options clear_cache create_mirror () =
OpamArg.apply_global_options cli global_options;
let repo_root = checked_repo_root () in
let repo_root = checked_repo_root ~check:false () in
if clear_cache then OpamAdminRepoUpgrade.clear_cache ()
else match create_mirror with
| None ->
Expand Down

0 comments on commit 8376637

Please sign in to comment.