Skip to content

Commit

Permalink
Fix pulling for empty duniverse lock files
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
  • Loading branch information
NathanReb committed Jul 13, 2022
1 parent 5dff9bc commit e583ffc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

### Fixed

- Fix a bug where `pull` would crash if the lock file contained no package to
vendor (#<PR_NUMBER>, @NathanReb)

### Removed

### Security
Expand Down
18 changes: 12 additions & 6 deletions lib/lockfile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ open Import
module Extra_field = struct
include Opam.Extra_field

let get ?file t opam =
let get ?file ?default t opam =
let open Result.O in
let* value_opt = get t opam in
match value_opt with
| Some result -> Ok result
| None ->
match (value_opt, default) with
| Some result, _ -> Ok result
| None, Some default -> Ok default
| None, None ->
let file_suffix_opt = Option.map ~f:(Printf.sprintf " %s") file in
let file_suffix = Option.value ~default:"" file_suffix_opt in
Error
Expand Down Expand Up @@ -87,6 +88,8 @@ module Root_packages = struct

let field =
Extra_field.make ~name:"root-packages" ~to_opam_value ~from_opam_value

let get ?file opam = Extra_field.get ?file field opam
end

module Depends = struct
Expand Down Expand Up @@ -236,6 +239,9 @@ module Duniverse_dirs = struct

let field =
Extra_field.make ~name:"duniverse-dirs" ~to_opam_value ~from_opam_value

let default = OpamUrl.Map.empty
let get ?file opam = Extra_field.get ?file ~default field opam
end

module Depexts = struct
Expand Down Expand Up @@ -362,10 +368,10 @@ let from_opam ~opam_monorepo_cwd ?file opam =
let open Result.O in
let* version = Extra_field.get ?file Version.field opam in
let* () = Version.compatible version in
let* root_packages = Extra_field.get ?file Root_packages.field opam in
let* root_packages = Root_packages.get ?file opam in
let* depends = Depends.from_filtered_formula (OpamFile.OPAM.depends opam) in
let pin_depends = OpamFile.OPAM.pin_depends opam in
let* duniverse_dirs = Extra_field.get ?file Duniverse_dirs.field opam in
let* duniverse_dirs = Duniverse_dirs.get ?file opam in
let depexts = OpamFile.OPAM.depexts opam in
let* source_config = Source_opam_config.get ~opam_monorepo_cwd opam in
Ok
Expand Down
3 changes: 1 addition & 2 deletions test/bin/empty-duniverse.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ there is nothing to pull and will not create a duniverse:

$ opam-monorepo pull
==> Using lockfile $TESTCASE_ROOT/empty-duniverse.opam.locked
opam-monorepo: [ERROR] Missing x-opam-monorepo-duniverse-dirs field in opam-monorepo lockfile $TESTCASE_ROOT/empty-duniverse.opam.locked
[1]
==> No dependencies to pull, there's nothing to be done here!
$ ls duniverse
ls: cannot access 'duniverse': No such file or directory
[2]

0 comments on commit e583ffc

Please sign in to comment.