Skip to content

Commit

Permalink
gitbin --> git_location
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Jan 11, 2024
1 parent 64c4d6c commit 3684a87
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
58 changes: 29 additions & 29 deletions src/client/opamClient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,8 @@ let init_checks ?(hard_fail_exn=true) init_config =
else not (soft_fail || hard_fail)

let git_for_windows_check =
if not Sys.win32 && not Sys.cygwin then fun ?gitbin:_ () -> None else
fun ?gitbin () ->
if not Sys.win32 && not Sys.cygwin then fun ?git_location:_ () -> None else
fun ?git_location () ->
let header () = OpamConsole.header_msg "Git" in
let contains_git p =
OpamSystem.resolve_command ~env:[||] (Filename.concat p "git.exe")
Expand All @@ -651,33 +651,33 @@ let git_for_windows_check =
Some (git, OpamSystem.bin_contains_bash p)
| None -> None)
in
let get_gitbin ?gitbin () =
let get_git_location ?git_location () =
let bin =
match gitbin with
| Some _ -> gitbin
match git_location with
| Some _ -> git_location
| None ->
OpamConsole.read "Please enter the path containing git.exe (e.g. C:\\Program Files\\Git\\cmd):"
in
match bin with
| None -> None
| Some gitbin ->
match contains_git gitbin, OpamSystem.bin_contains_bash gitbin with
| Some git_location ->
match contains_git git_location, OpamSystem.bin_contains_bash git_location with
| Some _, false ->
OpamConsole.msg "Using Git from %s" gitbin;
Some gitbin
OpamConsole.msg "Using Git from %s" git_location;
Some git_location
| Some _, true ->
OpamConsole.error
"A bash executable was found in %s, which will override \
Cygwin's bash. Please check your binary path."
gitbin;
git_location;
None
| None, _ ->
OpamConsole.error "No Git executable found in %s." gitbin;
OpamConsole.error "No Git executable found in %s." git_location;
None
in
let rec loop ?gitbin () =
match get_gitbin ?gitbin () with
| Some _ as gitbin -> gitbin
let rec loop ?git_location () =
match get_git_location ?git_location () with
| Some _ as git_location -> git_location
| None -> menu ()
and menu () =
let prompt () =
Expand All @@ -699,17 +699,17 @@ let git_for_windows_check =
match prompt () with
| `Default -> None
| `Specify -> loop ()
| `Location gitbin -> loop ~gitbin ()
| `Location git_location -> loop ~git_location ()
| `Abort ->
OpamConsole.note "Once your choosen Git installed, open a new PowerShell or Command Prompt window, and relaunch opam init.";
OpamStd.Sys.exit_because `Aborted
in
let gitbin =
match gitbin with
let git_location =
match git_location with
| Some (Right ()) -> None
| Some (Left gitbin) ->
| Some (Left git_location) ->
header ();
get_gitbin ~gitbin:(OpamFilename.Dir.to_string gitbin) ()
get_git_location ~git_location:(OpamFilename.Dir.to_string git_location) ()
| None ->
if OpamStd.Sys.tty_out then
(header ();
Expand All @@ -727,23 +727,23 @@ let git_for_windows_check =
OpamConsole.msg
"You can change that later with \
'opam option \"git-location=C:\\A\\Path\\bin\"'")
gitbin;
gitbin
git_location;
git_location

let windows_checks ?cygwin_setup ?gitbin config =
let windows_checks ?cygwin_setup ?git_location config =
let vars = OpamFile.Config.global_variables config in
let env =
List.map (fun (v, c, s) -> v, (lazy (Some c), s)) vars
|> OpamVariable.Map.of_list
in
(* Git handling *)
let git_location : string option = git_for_windows_check ?gitbin () in
let git_location : string option = git_for_windows_check ?git_location () in
OpamCoreConfig.update ?git_location ();
let config =
match git_location with
| Some gitbin ->
| Some git_location ->
OpamFile.Config.with_git_location
(OpamFilename.Dir.of_string gitbin) config
(OpamFilename.Dir.of_string git_location) config
| None -> config
in
(* Cygwin handling *)
Expand Down Expand Up @@ -1011,11 +1011,11 @@ let update_with_init_config ?(overwrite=false) config init_config =
let reinit ?(init_config=OpamInitDefaults.init_config()) ~interactive
?dot_profile ?update_config ?env_hook ?completion ?inplace
?(check_sandbox=true) ?(bypass_checks=false)
?cygwin_setup ?gitbin
?cygwin_setup ?git_location
config shell =
let root = OpamStateConfig.(!r.root_dir) in
let config = update_with_init_config config init_config in
let config = windows_checks ?cygwin_setup ?gitbin config in
let config = windows_checks ?cygwin_setup ?git_location config in
let _all_ok =
if bypass_checks then false else
init_checks ~hard_fail_exn:false init_config
Expand Down Expand Up @@ -1056,7 +1056,7 @@ let init
?repo ?(bypass_checks=false)
?dot_profile ?update_config ?env_hook ?(completion=true)
?(check_sandbox=true)
?cygwin_setup ?gitbin
?cygwin_setup ?git_location
shell =
log "INIT %a"
(slog @@ OpamStd.Option.to_string OpamRepositoryBackend.to_string) repo;
Expand Down Expand Up @@ -1092,7 +1092,7 @@ let init
init_config |>
OpamFile.Config.with_repositories (List.map fst repos)
in
let config = windows_checks ?cygwin_setup ?gitbin config in
let config = windows_checks ?cygwin_setup ?git_location config in

let dontswitch =
if bypass_checks then false else
Expand Down
4 changes: 2 additions & 2 deletions src/client/opamClient.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ val init:
?completion:bool ->
?check_sandbox:bool ->
?cygwin_setup: [ `internal | `default_location | `location of dirname | `no ] ->
?gitbin:(dirname, unit) either ->
?git_location:(dirname, unit) either ->
shell ->
rw global_state * unlocked repos_state * atom list

Expand All @@ -47,7 +47,7 @@ val reinit:
?update_config:bool -> ?env_hook:bool -> ?completion:bool -> ?inplace:bool ->
?check_sandbox:bool -> ?bypass_checks:bool ->
?cygwin_setup: [ `internal | `default_location | `location of dirname | `no ] ->
?gitbin:(dirname, unit) either ->
?git_location:(dirname, unit) either ->
OpamFile.Config.t -> shell -> unit

(** Install the given list of packages. [add_to_roots], if given, specifies that
Expand Down
16 changes: 8 additions & 8 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ let init cli =
else
Term.const None
in
let gitbin =
let git_location =
if Sys.win32 then
mk_opt ~cli (cli_from ~experimental:true cli2_2)
["git-location"] "DIR"
Expand All @@ -337,7 +337,7 @@ let init cli =
else
Term.const None
in
let nogitbin =
let no_git_location =
if Sys.win32 then
mk_flag ~cli (cli_from ~experimental:true cli2_2)
["no-git-location"]
Expand All @@ -351,7 +351,7 @@ let init cli =
interactive update_config completion env_hook no_sandboxing shell
dot_profile_o compiler no_compiler config_file no_config_file reinit
show_opamrc bypass_checks
cygwin_internal cygwin_location gitbin nogitbin
cygwin_internal cygwin_location git_location no_git_location
() =
apply_global_options cli global_options;
apply_build_options cli build_options;
Expand Down Expand Up @@ -420,8 +420,8 @@ let init cli =
| (`default_location | `none), Some dir -> Some (`location dir)
| (`internal | `default_location | `no) as setup, None -> Some setup
in
let gitbin =
match gitbin, nogitbin with
let git_location =
match git_location, no_git_location with
| Some _, true ->
OpamConsole.error_and_exit `Bad_arguments
"Options --no-git-location and --git-location are incompatible";
Expand All @@ -438,7 +438,7 @@ let init cli =
let reinit conf =
OpamClient.reinit ~init_config ~interactive ?dot_profile
?update_config ?env_hook ?completion ~inplace ~bypass_checks
~check_sandbox:(not no_sandboxing) ?cygwin_setup ?gitbin
~check_sandbox:(not no_sandboxing) ?cygwin_setup ?git_location
conf shell
in
let config =
Expand Down Expand Up @@ -478,7 +478,7 @@ let init cli =
?repo ~bypass_checks ?dot_profile
?update_config ?env_hook ?completion
~check_sandbox:(not no_sandboxing)
?cygwin_setup ?gitbin
?cygwin_setup ?git_location
shell
in
OpamStd.Exn.finally (fun () -> OpamRepositoryState.drop rt)
Expand Down Expand Up @@ -527,7 +527,7 @@ let init cli =
$setup_completion $env_hook $no_sandboxing $shell_opt cli
cli_original $dot_profile_flag cli cli_original $compiler
$no_compiler $config_file $no_config_file $reinit $show_default_opamrc
$bypass_checks $cygwin_internal $cygwin_location $gitbin $nogitbin)
$bypass_checks $cygwin_internal $cygwin_location $git_location $no_git_location)

(* LIST *)
let list_doc = "Display the list of available packages."
Expand Down
4 changes: 2 additions & 2 deletions src/client/opamConfigCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,9 @@ let global_allowed_fields, global_allowed_sections =
Config.with_swh_fallback (Config.swh_fallback Config.empty);
"git-location", Atomic_pp
(fun c ->
OpamStd.Option.iter (fun gitbin ->
OpamStd.Option.iter (fun git_location ->
if OpamSystem.bin_contains_bash
(OpamFilename.Dir.to_string gitbin) then
(OpamFilename.Dir.to_string git_location) then
OpamConsole.error_and_exit `False
"Found a bash in given git bin directory,\
which is dangerous!")
Expand Down

0 comments on commit 3684a87

Please sign in to comment.