Select the types of activity you want to include in your feed.
Remove monopam extract command
The extract functionality was breaking monopam push for normal repos. A different strategy will be used for the "develop first, extract later" workflow.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
···164164 Term.(
165165 ret (const run $ package_arg $ upstream_arg $ logging_term))
166166167167-(* Extract command *)
168168-169169-let extract_cmd =
170170- let doc = "Extract a subdirectory as a standalone repository" in
171171- let man = [
172172- `S Manpage.s_description;
173173- `P "Extracts a subdirectory from the monorepo as a standalone git \
174174- repository with full history. Enables 'develop first, extract later'.";
175175- `P "The extraction process:";
176176- `I ("1.", "Runs git subtree split to extract commits");
177177- `I ("2.", "Creates a new git repository in checkouts");
178178- `I ("3.", "Configures the remote URL");
179179- `S "EXAMPLES";
180180- `Pre " monopam extract my-lib --repo git@github.com:user/my-lib.git";
181181- `Pre " monopam extract my-lib --repo git@github.com:user/my-lib.git --push";
182182- ] in
183183- let info = Cmd.info "extract" ~doc ~man in
184184- let subdir_arg =
185185- let doc = "Subdirectory in monorepo to extract" in
186186- Arg.(required & pos 0 (some string) None & info [] ~docv:"SUBDIR" ~doc)
187187- in
188188- let repo_arg =
189189- let doc = "Git URL for the new repository" in
190190- Arg.(required & opt (some string) None & info [ "repo"; "r" ] ~docv:"URL" ~doc)
191191- in
192192- let branch_arg =
193193- let doc = "Branch name (default: from config)" in
194194- Arg.(value & opt (some string) None & info [ "branch"; "b" ] ~docv:"BRANCH" ~doc)
195195- in
196196- let push_arg =
197197- let doc = "Push to remote after extraction" in
198198- Arg.(value & flag & info [ "push" ] ~doc)
199199- in
200200- let create_opam_arg =
201201- let doc = "Create opam package metadata in overlay" in
202202- Arg.(value & flag & info [ "create-opam" ] ~doc)
203203- in
204204- let run subdir repo branch push create_opam () =
205205- Eio_main.run @@ fun env ->
206206- with_config env @@ fun config ->
207207- let fs = Eio.Stdenv.fs env in
208208- let proc = Eio.Stdenv.process_mgr env in
209209- match Monopam.extract ~proc ~fs ~config ~subdir ~repo_url:repo
210210- ?branch ~push ~create_opam () with
211211- | Ok () -> `Ok ()
212212- | Error e ->
213213- Fmt.epr "Error: %a@." Monopam.pp_error e;
214214- `Error (false, "extract failed")
215215- in
216216- Cmd.v info
217217- Term.(ret (const run $ subdir_arg $ repo_arg
218218- $ branch_arg $ push_arg $ create_opam_arg $ logging_term))
219219-220167(* Add command *)
221168222169let add_cmd =
···934881 in
935882 let info = Cmd.info "monopam" ~version:"%%VERSION%%" ~doc ~man in
936883 Cmd.group info
937937- [ status_cmd; pull_cmd; push_cmd; extract_cmd; add_cmd; remove_cmd; changes_cmd; verse_cmd ]
884884+ [ status_cmd; pull_cmd; push_cmd; add_cmd; remove_cmd; changes_cmd; verse_cmd ]
938885939886let () = exit (Cmd.eval main_cmd)
-113
lib/monopam.ml
···1919 | Dirty_state of Package.t list
2020 | Package_not_found of string
2121 | Claude_error of string
2222- | Subdir_not_found of string
2323- | Checkout_exists of Fpath.t
24222523let pp_error ppf = function
2624 | Config_error msg -> Fmt.pf ppf "Configuration error: %s" msg
···3230 pkgs
3331 | Package_not_found name -> Fmt.pf ppf "Package not found: %s" name
3432 | Claude_error msg -> Fmt.pf ppf "Claude error: %s" msg
3535- | Subdir_not_found name -> Fmt.pf ppf "Subdirectory not found: %s" name
3636- | Checkout_exists path -> Fmt.pf ppf "Checkout already exists: %a" Fpath.pp path
37333834let fs_typed (fs : _ Eio.Path.t) : Eio.Fs.dir_ty Eio.Path.t =
3935 let dir, _ = fs in
···838834 end
839835 else Ok ()
840836 end
841841- end
842842-843843-let create_opam_package ~fs ~config ~name ~repo_url =
844844- let opam_repo = Config.Paths.opam_repo config in
845845- let pkg_dir = Fpath.(opam_repo / "packages" / name / (name ^ ".dev")) in
846846- let opam_file = Fpath.(pkg_dir / "opam") in
847847- let content = Printf.sprintf {|opam-version: "2.0"
848848-name: "%s"
849849-version: "dev"
850850-synopsis: "TODO: Add synopsis"
851851-dev-repo: "git+%s"
852852-depends: [
853853- "dune" {>= "3.0"}
854854- "ocaml" {>= "4.14"}
855855-]
856856-build: [
857857- ["dune" "build" "-p" name "-j" jobs]
858858-]
859859-|} name repo_url in
860860- let pkg_dir_eio = Eio.Path.(fs / Fpath.to_string pkg_dir) in
861861- mkdirs pkg_dir_eio;
862862- let opam_eio = Eio.Path.(fs / Fpath.to_string opam_file) in
863863- Eio.Path.save ~create:(`Or_truncate 0o644) opam_eio content;
864864- Log.app (fun m -> m "Created opam package at %a" Fpath.pp opam_file);
865865- Ok ()
866866-867867-let extract ~proc ~fs ~config ~subdir ~repo_url ?branch ?(push = false)
868868- ?(create_opam = false) () =
869869- let ( let* ) r f = Result.bind (Result.map_error (fun e -> Git_error e) r) f in
870870- let fs = fs_typed fs in
871871- let monorepo = Config.Paths.monorepo config in
872872- let checkouts_root = Config.Paths.checkouts config in
873873- let checkout_dir = Fpath.(checkouts_root / subdir) in
874874- let branch = Option.value branch ~default:(Config.default_branch config) in
875875-876876- (* Validate: subdir exists in monorepo *)
877877- if not (Git.Subtree.exists ~fs ~repo:monorepo ~prefix:subdir) then
878878- Error (Subdir_not_found subdir)
879879- else
880880- (* Validate: checkout doesn't already exist *)
881881- let checkout_eio = Eio.Path.(fs / Fpath.to_string checkout_dir) in
882882- let checkout_exists =
883883- match Eio.Path.kind ~follow:true checkout_eio with
884884- | `Directory -> true | _ -> false | exception _ -> false
885885- in
886886- if checkout_exists then Error (Checkout_exists checkout_dir)
887887- else
888888- (* Validate: monorepo is clean *)
889889- if Git.is_dirty ~proc ~fs monorepo then
890890- Error (Git_error (Git.Dirty_worktree monorepo))
891891- else begin
892892- ensure_checkouts_dir ~fs ~config;
893893-894894- (* Step 1: Split the subtree history *)
895895- Log.info (fun m -> m "Splitting subtree history for %s" subdir);
896896- let* split_commit = Git.Subtree.split ~proc ~fs ~repo:monorepo ~prefix:subdir () in
897897- Log.info (fun m -> m "Split commit: %s" split_commit);
898898-899899- (* Step 2: Create new repo from split *)
900900- Log.info (fun m -> m "Creating checkout at %a" Fpath.pp checkout_dir);
901901- let* () = Git.init ~proc ~fs checkout_dir in
902902- let checkout_eio = Eio.Path.(fs / Fpath.to_string checkout_dir) in
903903- let monorepo_path = Fpath.to_string monorepo in
904904-905905- (* Fetch split commit from monorepo *)
906906- let* _ = run_git_in ~proc ~cwd:checkout_eio
907907- [ "fetch"; monorepo_path; split_commit ] in
908908- let* _ = run_git_in ~proc ~cwd:checkout_eio
909909- [ "checkout"; "-b"; branch; "FETCH_HEAD" ] in
910910-911911- (* Step 3: Add origin remote *)
912912- Log.info (fun m -> m "Adding remote origin: %s" repo_url);
913913- let* _ = run_git_in ~proc ~cwd:checkout_eio
914914- [ "remote"; "add"; "origin"; repo_url ] in
915915-916916- (* Step 4: Optionally push *)
917917- let push_result =
918918- if push then begin
919919- Log.info (fun m -> m "Pushing to %s" repo_url);
920920- Git.push_remote ~proc ~fs ~branch checkout_dir
921921- |> Result.map_error (fun e -> Git_error e)
922922- end else Ok ()
923923- in
924924- match push_result with
925925- | Error e -> Error e
926926- | Ok () ->
927927-928928- (* Step 5: Optionally create opam metadata *)
929929- let create_opam_result =
930930- if create_opam then
931931- create_opam_package ~fs ~config ~name:subdir ~repo_url
932932- else Ok ()
933933- in
934934- match create_opam_result with
935935- | Error e -> Error e
936936- | Ok () ->
937937-938938- (* Print summary *)
939939- Log.app (fun m -> m "Extracted %s to %a" subdir Fpath.pp checkout_dir);
940940- Log.app (fun m -> m "");
941941- Log.app (fun m -> m "Next steps:");
942942- if not push then begin
943943- Log.app (fun m -> m " 1. Create the remote repository");
944944- Log.app (fun m -> m " 2. Push: cd %a && git push -u origin %s"
945945- Fpath.pp checkout_dir branch)
946946- end;
947947- if not create_opam then
948948- Log.app (fun m -> m " 3. Add opam package metadata to enable push/pull");
949949- Ok ()
950837 end
951838952839let add ~proc ~fs ~config ~package () =
-34
lib/monopam.mli
···4343 (** Operation blocked due to dirty packages *)
4444 | Package_not_found of string (** Named package not found in opam repo *)
4545 | Claude_error of string (** Claude API or response parsing error *)
4646- | Subdir_not_found of string (** Subdirectory not found in monorepo *)
4747- | Checkout_exists of Fpath.t (** Checkout already exists at path *)
48464947val pp_error : error Fmt.t
5048(** [pp_error] formats errors. *)
···112110 @param config Monopam configuration
113111 @param package Optional specific package to push
114112 @param upstream If true, also push checkouts to their git remotes *)
115115-116116-(** {2 Extract} *)
117117-118118-val extract :
119119- proc:_ Eio.Process.mgr ->
120120- fs:Eio.Fs.dir_ty Eio.Path.t ->
121121- config:Config.t ->
122122- subdir:string ->
123123- repo_url:string ->
124124- ?branch:string ->
125125- ?push:bool ->
126126- ?create_opam:bool ->
127127- unit ->
128128- (unit, error) result
129129-(** [extract ~proc ~fs ~config ~subdir ~repo_url ()] extracts a subdirectory
130130- from the monorepo as a standalone git repository with full history.
131131-132132- Enables the "develop in monorepo first, extract later" workflow.
133133-134134- The extraction process:
135135- 1. Runs git subtree split to extract commits affecting the subdirectory
136136- 2. Creates a new git repository in the checkouts directory
137137- 3. Configures the remote URL
138138-139139- @param proc Eio process manager
140140- @param fs Eio filesystem
141141- @param config Monopam configuration
142142- @param subdir Subdirectory in monorepo to extract
143143- @param repo_url Git URL for the new repository
144144- @param branch Branch name (default: from config)
145145- @param push If true, push to remote after extraction
146146- @param create_opam If true, create opam package metadata in overlay *)
147113148114(** {2 Package Management} *)
149115