-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git on windows: check and advertise to use Git for Windows #5718
Conversation
src/client/opamClient.ml
Outdated
@@ -635,6 +635,57 @@ let init_checks ?(hard_fail_exn=true) init_config = | |||
if hard_fail && hard_fail_exn then OpamStd.Sys.exit_because `Configuration_error | |||
else not (soft_fail || hard_fail) | |||
|
|||
let git_for_windows_check = | |||
if Sys.win32 then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn’t this code be also ran on Cygwin?
if Sys.win32 then | |
if Sys.win32 || Sys.cygwin then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally agree with @kit-ty-kate but I'm not a Cygwin user. I could see it going either way; Cygwin (not MSYS2) is meant as a full Unix replacement including userland tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - for the same reason as we're advising users aiming for native Windows opam experience to use Git for Windows, users of Cygwin's opam should be using Cygwin's git (or at least, we shouldn't be advising the contrary). Cygwin's opam package is maintained, as well.
src/client/opamClient.ml
Outdated
let git_for_windows_check = | ||
if Sys.win32 then | ||
fun cygbin -> | ||
let gitcmd = OpamSystem.resolve_command "git" in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To deal with the common edge case where both Cygwin (or MSYS2) git and Git for Windows git are installed, I've been doing PATH modifications in DkML so that Git for Windows always is in front of the PATH (before /usr/bin
). That may be overkill here but the problem remains what to do when they are both installed.
Currently this PR will search the PATH and only check the first git
... which will almost always be Cygwin/MSYS2 /usr/bin/git
.
Not sure how, but could OpamSystem.resolve_command
be adjusted to find the correct git
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: The PATH hack for shells (PATH="${PATH/:\/usr\/bin:\/bin:/:}"
) seen in https://learn.microsoft.com/en-us/vcpkg/users/platforms/mingw#how-to-avoid-mixing-different-installations seems like a common way to fix these sorts of Cygwin/MSYS2 problems. So my suggestion would be to have a OpamSystem.resolve_command ~safe:()
mode which does the PATH hack in OCaml to find if there is a Git for Windows. And if that fails, then do a normal OpamSystem.resolve_command
if needed.
b420dea
to
19745f2
Compare
PR update with new mechanism: at init, ask for user to specify its git path (git4win or winget), stores it, and put it at the beginning of build & other paths. |
@jonahbeckford could you test the new git selection mechanism, if you have some time? |
Sure. Is there a GitHub artifact with the |
I can try to generate one. |
Makes it easy for code reviewers (so they don't have to rebuild the source code). Makes it easy to compare-and-constrast old version. Helps ocaml#5718
Makes it easy for code reviewers (so they don't have to rebuild the source code). Makes it easy to compare-and-constrast old version. Helps ocaml#5718
Makes it easy for code reviewers (so they don't have to rebuild the source code). Makes it easy to compare-and-constrast old version. + Allow GitHub Actions manual workflow Helps ocaml#5718
Makes it easy for code reviewers (so they don't have to rebuild the source code). Makes it easy to compare-and-constrast old version. Helps ocaml#5718
Don't worry. I am using the Testing
Issue ALooks like it is missing the VC Runtime redistributables (
That isn't the end of the world ... I believe you will be building completely static versions. In the meantime, I'll install https://aka.ms/vs/17/release/vc_redist.x64.exe |
I have a screen capture at https://vimeo.com/893933043. Most of it is smooth (thx!) but there are a few adjustments needed:
|
Thanks a lot for this detailed feedback! The workflow needs to be updated:
|
bb918d4
to
c14e3a5
Compare
I have a small code suggestion, but otherwise LTGM. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not convinced gitbinfield
is a very descriptive name of the new option. What about git-path
?
It's normal, it's not meant to stay :) [the names] Looking for name ideas for:
|
Thanks a lot! Indeed, better advertise to launch another terminal session to have the path updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments on the message, and a few drive-by comments. As ever, I'm sorry to enter these discussions late. I think the general mechanism here is very good, and what I'm suggesting next reuses everything that's already here, just in a slightly different way.
I wonder if there is a possibly conceptually different approach to storing the path to Git's bin (with apologies if this has already been discussed and ruled out, because I know that @rjbou and @kit-ty-kate have discussed this extensively!).
The mechanism for adding Cygwin's bin
directory to PATH
is a necessary evil for Windows support, but the (admittedly very) long-term trajectory for Windows is that it should one day be unnecessary. Conversely, the "tricks" to get a Git installation's bin
directory into PATH
is something we'd likely always need to do.
I'd be tempted, therefore, to make it the job of opam init to determine if it can find the exact path to a git.exe
which it likes (Git for Windows) and store that - so internally opam
stores C:\Program Files\Git\cmd\git.exe
(that path can be determined using the Registry). opam should obviously offer the choice, but I think opam init
should attempt to find that version of git, regardless of PATH
(the menu could of course offer the git.exe
found in PATH).
The rest of the check (bash in PATH, etc.) is more general. We should be checking the entire PATH to see if Cygwin's bash is going to be shadowed anyway, and we can also warn that the git
found in PATH does not match the one opam wants to use, or has that the user has done something which causes git.exe
and bash.exe
to be next to each other (non-recommended Git-for-Windows configuration, other package managers, etc.)
So, in summary: I think opam should very precisely determine the git.exe
it wants to use (same idea as OPAMFETCH, etc.) and store that - all its git operations should do that. opam shouldn't then do any magic PATH manipulation where git is concerned - it should simply warn the user (possibly at each call - i.e. at opam install
, etc.) that the git in PATH may cause problems for package installations. That approach is similar to what Git-for-Windows itself does - it provides the ability to put git-bash in PATH, but strongly recommends not doing so.
src/client/opamClient.ml
Outdated
@@ -635,12 +635,118 @@ let init_checks ?(hard_fail_exn=true) init_config = | |||
if hard_fail && hard_fail_exn then OpamStd.Sys.exit_because `Configuration_error | |||
else not (soft_fail || hard_fail) | |||
|
|||
let windows_checks ?cygwin_setup config = | |||
let git_for_windows_check = | |||
if not Sys.win32 && not Sys.cygwin then fun ?gitbin:_ () -> None else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not Sys.win32 && not Sys.cygwin then fun ?gitbin:_ () -> None else | |
if Sys.unix then fun ?gitbin:_ () -> None else |
Makes it easy for code reviewers (so they don't have to rebuild the source code). Makes it easy to compare-and-constrast old version. Helps ocaml#5718
…Git for Windows if needed
…u that contains everything
Co-authored-by: David Allsopp <[email protected]> Co-authored-by: jonahbeckford <[email protected]>
Thanks a lot! |
-- outdated, to be updated --
At initialisation, check the origin of resolved git command:
\cmd
)This is done by checking the existence of a bash executable near git.
related to #5617
/cc @jonahbeckford
todo