Monorepo management for opam overlays
0
fork

Configure Feed

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

Use SSH push URLs for workspace repos; propagate push failures

- workspace_repos now converts HTTPS origin URLs to SSH push URLs
via url_to_push_url (same as package repos), fixing 403 errors
when pushing opam-repo to tangled.org
- workspace_repos now returns errors instead of swallowing them,
so push correctly reports failure instead of printing "✓ Changes
pushed" after a failed opam-repo push

+33 -9
+33 -9
lib/push.ml
··· 171 171 Log.warn (fun m -> m "Failed to commit in %s: %s" name e))) 172 172 173 173 let workspace_repos ~proc ~fs ~config ~force ~push_mono = 174 + let knot = Config.knot config in 175 + let errors = ref [] in 174 176 let push_repo ~commit name path = 175 177 if Git.Repository.is_repo ~fs path then begin 176 178 let repo = Git.Repository.open_repo ~fs path in 177 179 match Git.Repository.remote_url repo "origin" with 178 180 | None -> Log.debug (fun m -> m "%s has no origin remote, skipping" name) 179 - | Some _ -> ( 181 + | Some fetch_url -> ( 182 + (* Ensure push URL uses SSH, not HTTPS *) 183 + let push_url = Ctx.url_to_push_url ~knot fetch_url in 184 + (match 185 + Git.Repository.set_push_url repo ~name:"origin" ~url:push_url 186 + with 187 + | Ok () -> () 188 + | Error (`Msg msg) -> 189 + Log.warn (fun m -> m "Failed to set push URL for %s: %s" name msg)); 180 190 if commit then commit_pending ~fs path name; 181 191 let branch = 182 192 Git.Repository.current_branch repo |> Option.value ~default:"main" ··· 193 203 result.Git_cli.stderr -> 194 204 Log.app (fun m -> m " ✓ %s (already synced)" name) 195 205 | Error e -> 196 - Log.app (fun m -> m " ✗ %s: %a" name Git_cli.pp_error e)) 206 + Log.app (fun m -> m " ✗ %s: %a" name Git_cli.pp_error e); 207 + errors := (name, e) :: !errors) 197 208 end 198 209 in 199 210 let mono = Config.Paths.monorepo config in 200 211 let opam_repo = Config.Paths.opam_repo config in 201 212 if push_mono then push_repo ~commit:false "mono" mono; 202 - push_repo ~commit:true "opam-repo" opam_repo 213 + push_repo ~commit:true "opam-repo" opam_repo; 214 + !errors 203 215 204 216 (** {1 Main Push Operation} *) 205 217 ··· 431 443 match log_push_results push_results with 432 444 | Error e -> Error e 433 445 | Ok () -> 434 - if upstream then 435 - workspace_repos ~proc ~fs:fs_t ~config ~force ~push_mono; 436 - Ok ()) 446 + let ws_errors = 447 + if upstream then 448 + workspace_repos ~proc ~fs:fs_t ~config ~force ~push_mono 449 + else [] 450 + in 451 + if ws_errors <> [] then 452 + let _name, e = List.hd ws_errors in 453 + Error (Ctx.Git_error e) 454 + else Ok ()) 437 455 438 456 let load_sources ~fs ~config = 439 457 let sources_path = Fpath.(Config.Paths.monorepo config / "sources.toml") in ··· 484 502 let push_mono = packages = [] in 485 503 if to_push = [] then begin 486 504 Log.app (fun m -> m "Nothing to push (all repos in sync)"); 487 - if upstream then 488 - workspace_repos ~proc ~fs:fs_t ~config ~force ~push_mono; 489 - Ok () 505 + let ws_errors = 506 + if upstream then 507 + workspace_repos ~proc ~fs:fs_t ~config ~force ~push_mono 508 + else [] 509 + in 510 + if ws_errors <> [] then 511 + let _name, e = List.hd ws_errors in 512 + Error (Ctx.Git_error e) 513 + else Ok () 490 514 end 491 515 else 492 516 export_and_push ~proc ~fs ~fs_t ~config ~sources ~upstream