-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Allow running Git directly from C:\Program Files\Git\mingw64\bin\git.exe
#2506
Conversation
Is there a test that we could add to demonstrate the change? Such as: does the output of |
Should we prepend rather than append them to the PATH ?? |
Maybe I'm over analyzing this. But if we're appending $HOME/bin and /usr/bin and /mingXX/ to the PATH, aren't we introducing ambiguity? If I have an official release installed in Program Files and a private version installed in my $HOME, which version of a lib-exec (or maybe just non-builtin) exe gets run when I run a command? I think a series of tests with before and after output would be helpful here. |
The function name threw you off, right? It appends to the buffer, not to the |
We're actually prepending it, by virtue of starting with a completely empty buffer. And then we add
Note that none of this has anything to do with the But your concern is valid: we really need to prepend the components to the
The biggest problem with adding a test here is that the functionality added in this PR depends highly on the If run as If run as What we can do (and what I will do) is to add a simple test that verifies that |
Um, perhaps I'm just being dense here, but I find all this startup magic way more confusing than I think it needs to be, but I realize there are historical issues here. Yes, append in the name of the function did throw me, but also the different meanings of the variable "path" in the caller and callee didn't help. As for testing, would it be helpful to create a tXXXX.sh script that does essentially:
And then confirm that the child script was invoked correctly (meaning git.exe found the correct associated git-core directory and was able find the "gitDASHecho-path" ) and that the child script inherited the expected PATH. Perhaps that's overkill. Perhaps not. |
I'm going to be away from my keyboard for a while today, so I'm going to go ahead and approve this. I'd like to see some tests and maybe a little more comments about what we're doing, but I don't want to block this for that. |
Yes, you're right, hysterical raisins at play. And the fact that Git is not really portable enough to support Windows, we go out of our way to pretend that we're just implementing POSIX shims in
That's a good idea! Originally, I was worried about |
yeah, i forgot about the DLLs, but maybe also copy them into that bin directory too. (I'm thinking about a MSVC=1 build that will complain differently....) |
The biggest problem with that will be that I don't know which DLLs are required in that test... But
It should not complain differently, because as part of the build, the DLLs are copied into what will become |
Git for Windows wants to add `git.exe` to the users' `PATH`, without cluttering the latter with unnecessary executables such as `wish.exe`. To that end, it invented the concept of its "Git wrapper", i.e. a tiny executable located in `C:\Program Files\Git\cmd\git.exe` (originally a CMD script) whose sole purpose is to set up a couple of environment variables and then spawn the _actual_ `git.exe` (which nowadays lives in `C:\Program Files\Git\mingw64\bin\git.exe` for 64-bit, and the obvious equivalent for 32-bit installations). Currently, the following environment variables are set unless already initialized: - `MSYSTEM`, to make sure that the MSYS2 Bash and the MSYS2 Perl interpreter behave as expected, and - `PLINK_PROTOCOL`, to force PuTTY's `plink.exe` to use the SSH protocol instead of Telnet, - `PATH`, to make sure that the `bin` folder in the user's home directory, as well as the `/mingw64/bin` and the `/usr/bin` directories are included. The trick here is that the `/mingw64/bin/` and `/usr/bin/` directories are relative to the top-level installation directory of Git for Windows (which the included Bash interprets as `/`, i.e. as the MSYS pseudo root directory). Using the absence of `MSYSTEM` as a tell-tale, we can detect in `git.exe` whether these environment variables have been initialized properly. Therefore we can call `C:\Program Files\Git\mingw64\bin\git` in-place after this change, without having to call Git through the Git wrapper. Obviously, above-mentioned directories must be _prepended_ to the `PATH` variable, otherwise we risk picking up executables from unrelated Git installations. We do that by constructing the new `PATH` value from scratch, appending `$HOME/bin` (if `HOME` is set), then the MSYS2 system directories, and then appending the original `PATH`. Side note: this modification of the `PATH` variable is independent of the modification necessary to reach the executables and scripts in `/mingw64/libexec/git-core/`, i.e. the `GIT_EXEC_PATH`. That modification is still performed by Git, elsewhere, long after making the changes described above. While we _still_ cannot simply hard-link `mingw64\bin\git.exe` to `cmd` (because the former depends on a couple of `.dll` files that are only in `mingw64\bin`, i.e. calling `...\cmd\git.exe` would fail to load due to missing dependencies), at least we can now avoid that extra process of running the Git wrapper (which then has to wait for the spawned `git.exe` to finish) by calling `...\mingw64\bin\git.exe` directly, via its absolute path. Testing this is in Git's test suite tricky: we set up a "new" MSYS pseudo-root and copy the `git.exe` file into the appropriate location, then verify that `MSYSTEM` is set properly, and also that the `PATH` is modified so that scripts can be found in `$HOME/bin`, `/mingw64/bin/` and `/usr/bin/`. This addresses git-for-windows#2283 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Originally, we refrained from adding a regression test in 7b6c649 (system_path(): Add prefix computation at runtime if RUNTIME_PREFIX set, 2008-08-10), and in 226c0dd (exec_cmd: RUNTIME_PREFIX on some POSIX systems, 2018-04-10). The reason was that it was deemed too tricky to test. Turns out that it is not tricky to test at all: we simply create a pseudo-root, copy the `git` executable into the `git/` subdirectory of that pseudo-root, then copy a script into the `libexec/git-core/` directory and expect that to be picked up. As long as the trash directory is in a location where binaries can be executed, this works. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@jeffhostetler just to make sure: do you want me to add any more information to the commit message? |
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
Allow running Git directly from `C:\Program Files\Git\mingw64\bin\git.exe`
We still recommend running
git.exe
via the Git wrapper in/cmd/
, just to make sure that the environment variables are set appropriately, such as adding the/usr/bin/
directory to thePATH
.This is relevant e.g. for running the hooks via the Bash.
With this PR, we no longer require that Git be run via the
/cmd/git.exe
wrapper: it can be run directly from/mingw64/bin/git.exe
, configuring the environment variables appropriately itself (using the absence of theMSYSTEM
variable as indicator that it should do so).This addresses #2283