Skip to content
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

An idea to prevent CMD from picking up any git.exe in the current directory #1945

Closed
gdh1995 opened this issue Nov 22, 2018 · 9 comments
Closed
Assignees
Milestone

Comments

@gdh1995
Copy link

gdh1995 commented Nov 22, 2018

The release note in https://github.com/git-for-windows/git/releases/tag/v2.19.2.windows.1 says:

It is impossible to turn off CMD's behavior where it picks up any git.exe in the current directory, so let's discourage the use of Git CMD.

I agree with it, but I think there may be a way to make CMD not use the git.exe in the current directory - according to $PATHEXT, git.com takes precedence over git.exe, so if only there's /usr/bin/git.com, then a command like git status will use it directly.

Just a naive idea~

@dscho
Copy link
Member

dscho commented Nov 22, 2018

Have you tested your idea?

@gdh1995
Copy link
Author

gdh1995 commented Nov 22, 2018

Have you tested your idea?

Sorry to bother you. My idea of using git.com can not pass any simple test.

Maybe DOSKEY is another solution. Here's my test (after cp /usr/bin/ls.exe /r/working/git.exe):

R:\working$ DOSKEY git=D:\Git\mingw64\bin\git.exe $*

R:\working$ git --version
git version 2.19.2.windows.1

R:\working$ .\git --version
ls (GNU coreutils) 8.30
...

This new idea is learned from https://stackoverflow.com/questions/20530996/aliases-in-windows-command-prompt.

@dscho
Copy link
Member

dscho commented Nov 22, 2018

Sorry to bother you.

Not at all!

My idea of using git.com can not pass any simple test.

That's too sad...

Maybe DOSKEY is another solution.

That's a really good idea! I just performed a few tests with this, and it seems to work quite well!

dscho added a commit to git-for-windows/MINGW-packages that referenced this issue Nov 22, 2018
This is based on a proposal by Dahan Gong in
git-for-windows/git#1945: use DOSKEY to force
the intended `git.exe` to be used when a command line such as `git show
HEAD` is called.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
Copy link
Member

dscho commented Nov 22, 2018

Fixed via git-for-windows/MINGW-packages@8217238

@dscho dscho closed this as completed Nov 22, 2018
@gdh1995
Copy link
Author

gdh1995 commented Nov 23, 2018

Thanks.

BTW, I just wonder whether the commit can still work even when @@EXEPATH@@ contains any space characters.

@gdh1995
Copy link
Author

gdh1995 commented Nov 23, 2018

Um... A sadly news is, I just test a new command of echo 1 | git log, and find that CMD fallback to search PATH for git.exe. CMD is indeed too annoying.

@dscho
Copy link
Member

dscho commented Nov 23, 2018

I just wonder whether the commit can still work even when @@EXEPATH@@ contains any space characters.

It should, as the path is inside quotes.

A sadly news is, I just test a new command of echo 1 | git log, and find that CMD fallback to search PATH for git.exe.

That is indeed sad! Oh well. At least it works for the common case, as it is quite unusual to pipe something into git, especially in CMD.

So I guess we keep Git CMD deprecated, but ship with your fix from now on?

@dscho dscho added this to the v2.19.2(2) milestone Nov 23, 2018
@dscho dscho self-assigned this Nov 23, 2018
dscho added a commit to git-for-windows/build-extra that referenced this issue Nov 23, 2018
Git CMD [no longer picks up `git.exe` from the current directory
(if any)](git-for-windows/git#1945).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@mfriedrich74
Copy link

mfriedrich74 commented Nov 23, 2018 via email

@dscho
Copy link
Member

dscho commented Nov 23, 2018

@mfriedrich74 if you somehow get the SafeDllSearchMode to apply to CMD's .exe search, that will be quite the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants