Skip to content

Commit

Permalink
switch: make opam switch repo links parsing consistent
Browse files Browse the repository at this point in the history
new behaviour in 2.3, old behaviour is stil available with cli < 2.3
  • Loading branch information
Keryan-dev authored and rjbou committed Aug 9, 2024
1 parent f98b8f2 commit 2379d84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ users)

## Switch
* ◈ Add `opam switch import --deps-only` option to install only dependencies of root package at import [#5388 @rjbou - fix #5200]
* [BUG] Make accepted `--repos` URLs on creation consistent with `opam repository` [#6091 @Keryan-dev - fix #4673]

## Config

Expand Down
19 changes: 11 additions & 8 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2557,7 +2557,7 @@ let repository cli =
(* From a list of strings (either "repo_name" or "repo_name=URL"), configure the
repos with URLs if possible, and return the updated repos_state and selection of
repositories *)
let with_repos_rt gt repos f =
let with_repos_rt gt cli repos f =
OpamRepositoryState.with_ `Lock_none gt @@ fun rt ->
let repos, rt =
match repos with
Expand All @@ -2574,9 +2574,10 @@ let with_repos_rt gt repos f =
OpamStd.List.filter_map (function
| (_, None) -> None
| (n, Some url) ->
let handle_suffix = OpamCLIVersion.Op.(cli @>= cli2_3) in
let repo =
OpamStd.Option.Op.(
OpamUrl.parse_opt ~handle_suffix:false ~from_file:false url
OpamUrl.parse_opt ~handle_suffix ~from_file:false url
>>| fun u -> n, u)
in
if repo = None then
Expand Down Expand Up @@ -2720,9 +2721,11 @@ let switch cli =
This scans the current directory for package definitions, chooses a \
compatible compiler, creates a local switch and installs the local \
package dependencies.";
`Pre " opam switch create trunk --repos \
default,beta=git+https://github.com/ocaml/ocaml-beta-repository.git \
ocaml-variants.4.10.0+trunk";
`Pre (Printf.sprintf
" opam switch create trunk --repos \
default,beta=%shttps://github.com/ocaml/ocaml-beta-repository.git \
ocaml-variants.4.10.0+trunk"
(if OpamCLIVersion.Op.(cli @>= cli2_3) then "" else "git+"));
`P "Create a new switch called \"trunk\", with \
$(b,ocaml-variants.4.10.0+trunk) as compiler, with a new $(i,beta) \
repository bound to the given URL selected besides the default one."
Expand Down Expand Up @@ -2869,7 +2872,7 @@ let switch cli =
`Ok ()
| Some `list_available, pattlist ->
OpamGlobalState.with_ `Lock_none @@ fun gt ->
with_repos_rt gt repos @@ fun (repos, rt) ->
with_repos_rt gt cli repos @@ fun (repos, rt) ->
let compilers = OpamSwitchCommand.get_compiler_packages ?repos rt in
let st = OpamSwitchState.load_virtual ?repos_list:repos gt rt in
OpamConsole.msg "# Listing available compilers from repositories: %s\n"
Expand Down Expand Up @@ -2909,7 +2912,7 @@ let switch cli =
`Ok ()
| Some `install, switch_arg::params ->
OpamGlobalState.with_ `Lock_write @@ fun gt ->
with_repos_rt gt repos @@ fun (repos, rt) ->
with_repos_rt gt cli repos @@ fun (repos, rt) ->
let switch = OpamSwitch.of_string switch_arg in
let use_local =
not no_install && not empty && OpamSwitch.is_external switch
Expand Down Expand Up @@ -2999,7 +3002,7 @@ let switch cli =
else Some (OpamFile.make (OpamFilename.of_string filename))
in
if is_new_switch then
with_repos_rt gt repos @@ fun (repos, rt) ->
with_repos_rt gt cli repos @@ fun (repos, rt) ->
let synopsis = "Import from " ^ Filename.basename filename in
let (), gt =
OpamGlobalState.with_write_lock gt @@ fun gt ->
Expand Down
9 changes: 6 additions & 3 deletions tests/reftests/switch-creation.test
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ${BASEDIR}/OPAM/undef-switch
### # expects a warning, useful to check chosen backend
### opam switch create w-repo --repositories=from-link=https://github.com/ocaml/opam-repository.git --dry-run --empty
Creating repository from-link...
[ERROR] Could not update repository "from-link": OpamDownload.Download_fail(_, "curl: empty response while downloading https://github.com/ocaml/opam-repository.git/index.tar.gz")
[ERROR] Initial fetch of these repositories failed: from-link
# Return code 40 #
[from-link] Initialised
[WARNING] The repository 'from-link' at git+https://github.com/ocaml/opam-repository.git doesn't have a 'repo' file, and might not be compatible with this version of opam.
[NOTE] Repository at git+https://github.com/ocaml/opam-repository.git doesn't define its version, assuming it's 1.2.

<><> Upgrading repositories from older opam format ><><><><><><><><><><><><><><>
Upgrading repository "from-link"...

0 comments on commit 2379d84

Please sign in to comment.