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 20, 2025
1 parent 0f81ab6 commit 799f8b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 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
8 changes: 3 additions & 5 deletions tests/reftests/admin-cache.test
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
N0REP0
### mv REPO OPER
### opam repository set-url default OPER/ --set-default
[default] Initialised
### : create repo
### rm -rf REPO
### <repo>
opam-version: "1.2"
opam-version: "2.0"
### <packages/ipsum/ipsum.1/opam>
opam-version: "2.0"
### <packages/dolor/dolor.1/opam>
Expand Down Expand Up @@ -252,7 +250,7 @@ amet : md5 : exists, link to sha512
amet : sha256 : exists, link to sha512
amet : sha512 : exists
### ::::::::::::::::::::::::::::::::::::
### :IV: add a other hashes afterwards :
### :IV: add another hashes afterwards :
### ::::::::::::::::::::::::::::::::::::
### : ipsum : only md5 then adding sha512
### : dolor : md5 & sha256 then adding sha512
Expand Down

0 comments on commit 799f8b1

Please sign in to comment.