From 2db04ac170269903320255de5aaf0b4e8d0674a3 Mon Sep 17 00:00:00 2001 From: Raja Boujbel Date: Fri, 16 Feb 2024 15:54:01 +0100 Subject: [PATCH] init: on windows, fix handling of 'git-location' when defined in init config file (opamrc given via commandline, or present on users defaults) --- master_changes.md | 1 + src/client/opamClient.ml | 48 ++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/master_changes.md b/master_changes.md index 8d07447fb8e..5165847de4e 100644 --- a/master_changes.md +++ b/master_changes.md @@ -22,6 +22,7 @@ users) * Recommend enabling Developer Mode on Windows [#5831 @dra27] * Disable ACL in Cygwin internal install to avoid permission mismatch errors [#5796 @kit-ty-kate - fix #5781] * Add `sys-pkg-manager-cmd` as an accepted field in opamrc files [#5847 @rjbou - fix #5844] + * Fix `git-location` handling in init config file [#5848 @rjbou - fix #5845] ## Config report diff --git a/src/client/opamClient.ml b/src/client/opamClient.ml index 811c685cd92..3da136d4d83 100644 --- a/src/client/opamClient.ml +++ b/src/client/opamClient.ml @@ -747,7 +747,25 @@ let windows_checks ?cygwin_setup ?git_location config = |> OpamVariable.Map.of_list in (* Git handling *) - let git_location : string option = git_for_windows_check ?git_location () in + let git_location = + match git_location, OpamFile.Config.git_location config with + | None, None -> None + | Some (Right ()), None -> Some (Right ()) + | Some (Right ()), Some _ -> + OpamConsole.note + "As '--no-git-location' is given in argument, ignoring field \ + 'git-location' in opamrc"; + Some (Right ()) + | Some (Left gl), None | None, Some gl -> Some (Left gl) + | Some (Left gl_cli), Some gl_config -> + OpamConsole.note + "Git location defined in opamrc '%s' and via CLI \ + ('--git-location' option, %s). Keeping last one." + (OpamFilename.Dir.to_string gl_config) + (OpamFilename.Dir.to_string gl_cli) ; + Some (Left gl_cli) + in + let git_location = git_for_windows_check ?git_location () in OpamCoreConfig.update ?git_location (); let config = match git_location with @@ -784,18 +802,18 @@ let windows_checks ?cygwin_setup ?git_location config = OpamStd.Sys.exit_because `Aborted in let config = - OpamFile.Config.with_sys_pkg_manager_cmd - (OpamStd.String.Map.add "cygwin" cygcheck - (OpamFile.Config.sys_pkg_manager_cmd config)) - config - in - OpamConsole.note "Configured with %s for depexts" - (if OpamSysInteract.Cygwin.is_internal config then - "internal Cygwin install" - else - Printf.sprintf "Cygwin at %s" - OpamFilename.(Dir.to_string (dirname_dir (dirname cygcheck)))); - config + OpamFile.Config.with_sys_pkg_manager_cmd + (OpamStd.String.Map.add "cygwin" cygcheck + (OpamFile.Config.sys_pkg_manager_cmd config)) + config + in + OpamConsole.note "Configured with %s for depexts" + (if OpamSysInteract.Cygwin.is_internal config then + "internal Cygwin install" + else + Printf.sprintf "Cygwin at %s" + OpamFilename.(Dir.to_string (dirname_dir (dirname cygcheck)))); + config in let install_cygwin_tools () = let packages = @@ -1018,7 +1036,9 @@ let update_with_init_config ?(overwrite=false) config init_config = setifnew C.default_invariant C.with_default_invariant (I.default_invariant init_config) |> setifnew C.sys_pkg_manager_cmd C.with_sys_pkg_manager_cmd - (I.sys_pkg_manager_cmd init_config) + (I.sys_pkg_manager_cmd init_config) |> + setifnew C.git_location C.with_git_location_opt + (I.git_location init_config) let reinit ?(init_config=OpamInitDefaults.init_config()) ~interactive ?dot_profile ?update_config ?env_hook ?completion ?inplace