Monorepo management for opam overlays
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Port add_all, commit, rm from Git_cli to ocaml-git

- Update fork_join.ml and monopam.ml to use Git.Repository
- Remove add_all, commit, rm from Git_cli
- Add 14 tests for add_all, commit, rm
- Simplify test code using unwrap helper

+20 -60
+10 -5
lib/fork_join.ml
··· 921 921 copy_directory ~fs ~src ~dest; 922 922 Ok () 923 923 | Git_add_all path -> 924 - Git_cli.add_all ~proc ~fs path |> Result.map_error (fun e -> Git_error e) 924 + let git_repo = Git.Repository.open_repo ~fs path in 925 + Git.Repository.add_all git_repo 926 + |> Result.map_error (fun (`Msg msg) -> Git_error (Git_cli.Io_error msg)) 925 927 | Git_commit { repo; message } -> 926 - Git_cli.commit ~proc ~fs ~message repo 927 - |> Result.map_error (fun e -> Git_error e) 928 + let git_repo = Git.Repository.open_repo ~fs repo in 929 + Git.Repository.commit git_repo ~message 930 + |> Result.map (fun _ -> ()) 931 + |> Result.map_error (fun (`Msg msg) -> Git_error (Git_cli.Io_error msg)) 928 932 | Git_rm { repo; path; recursive } -> 929 - Git_cli.rm ~proc ~fs ~recursive repo path 930 - |> Result.map_error (fun e -> Git_error e) 933 + let git_repo = Git.Repository.open_repo ~fs repo in 934 + Git.Repository.rm git_repo ~recursive path 935 + |> Result.map_error (fun (`Msg msg) -> Git_error (Git_cli.Io_error msg)) 931 936 | Update_sources_toml { path; name; entry } -> ( 932 937 let sources = 933 938 match Sources_registry.load ~fs:(fs :> _ Eio.Path.t) path with
-13
lib/git_cli.ml
··· 229 229 [ "merge" ] @ (if ff_only then [ "--ff-only" ] else []) @ [ ref_name ] 230 230 in 231 231 run_git_ok ~proc ~cwd args |> Result.map ignore 232 - 233 - let add_all ~proc ~fs path = 234 - let cwd = path_to_eio ~fs path in 235 - run_git_ok ~proc ~cwd [ "add"; "-A" ] |> Result.map ignore 236 - 237 - let commit ~proc ~fs ~message path = 238 - let cwd = path_to_eio ~fs path in 239 - run_git_ok ~proc ~cwd [ "commit"; "-m"; message ] |> Result.map ignore 240 - 241 - let rm ~proc ~fs ~recursive path target = 242 - let cwd = path_to_eio ~fs path in 243 - let args = if recursive then [ "rm"; "-r"; target ] else [ "rm"; target ] in 244 - run_git_ok ~proc ~cwd args |> Result.map ignore
-28
lib/git_cli.mli
··· 207 207 @param ref_name The ref to merge (e.g., "verse/handle/main") 208 208 @param ff_only If true, only allow fast-forward merges (default: false) 209 209 @param path Path to the repository *) 210 - 211 - val add_all : 212 - proc:_ Eio.Process.mgr -> 213 - fs:Eio.Fs.dir_ty Eio.Path.t -> 214 - Fpath.t -> 215 - (unit, error) result 216 - (** [add_all ~proc ~fs path] stages all changes (git add -A) in the repository 217 - at [path]. *) 218 - 219 - val commit : 220 - proc:_ Eio.Process.mgr -> 221 - fs:Eio.Fs.dir_ty Eio.Path.t -> 222 - message:string -> 223 - Fpath.t -> 224 - (unit, error) result 225 - (** [commit ~proc ~fs ~message path] creates a commit with the given message in 226 - the repository at [path]. *) 227 - 228 - val rm : 229 - proc:_ Eio.Process.mgr -> 230 - fs:Eio.Fs.dir_ty Eio.Path.t -> 231 - recursive:bool -> 232 - Fpath.t -> 233 - string -> 234 - (unit, error) result 235 - (** [rm ~proc ~fs ~recursive path target] removes [target] from the git index in 236 - the repository at [path]. If [recursive] is true, removes directories 237 - recursively (git rm -r). *)
+10 -14
lib/monopam.ml
··· 1589 1589 Log.info (fun m -> 1590 1590 m "Regenerated %d opam-repo entries from monorepo" !updated); 1591 1591 if commit && Git.Repository.is_repo ~fs opam_repo then 1592 - match Git_cli.add_all ~proc ~fs opam_repo with 1593 - | Error e -> 1594 - Log.warn (fun m -> 1595 - m "Failed to stage opam-repo: %a" Git_cli.pp_error e) 1592 + let repo = Git.Repository.open_repo ~fs opam_repo in 1593 + match Git.Repository.add_all repo with 1594 + | Error (`Msg e) -> 1595 + Log.warn (fun m -> m "Failed to stage opam-repo: %s" e) 1596 1596 | Ok () -> ( 1597 1597 match 1598 - Git_cli.commit ~proc ~fs opam_repo 1598 + Git.Repository.commit repo 1599 1599 ~message:"Update opam files from monorepo" 1600 1600 with 1601 - | Error (Git_cli.Command_failed (_, result)) 1602 - when String.starts_with ~prefix:"nothing to commit" 1603 - result.Git_cli.stdout 1604 - || String.starts_with ~prefix:"nothing to commit" 1605 - result.Git_cli.stderr -> 1601 + | Error (`Msg msg) 1602 + when String.starts_with ~prefix:"nothing to commit" msg -> 1606 1603 () 1607 - | Error e -> 1608 - Log.warn (fun m -> 1609 - m "Failed to commit opam-repo: %a" Git_cli.pp_error e) 1610 - | Ok () -> Log.info (fun m -> m "Committed opam-repo changes")) 1604 + | Error (`Msg e) -> 1605 + Log.warn (fun m -> m "Failed to commit opam-repo: %s" e) 1606 + | Ok _ -> Log.info (fun m -> m "Committed opam-repo changes")) 1611 1607 end 1612 1608 1613 1609 (** Clone monorepo and opam-repo from verse registry if they don't exist