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

git-cmd.exe does not run first passed command parameter #2039

Closed
1 task done
tuspet opened this issue Jan 25, 2019 · 9 comments
Closed
1 task done

git-cmd.exe does not run first passed command parameter #2039

tuspet opened this issue Jan 25, 2019 · 9 comments
Assignees
Milestone

Comments

@tuspet
Copy link

tuspet commented Jan 25, 2019

  • I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Git version: 2.20.0
  • Our team uses the 32-bit Portable Git version
  • Machine: Win10 1803 64 bit

Details

Our software runs a git-cmd command to display the actual git home directory:

git-cmd.exe "echo %HOME% && exit"

This command answered with the correct path in 2.19.2 and earlier versions but returns nothing in 2.20.0.
After checking this problem deeply we found that now the 2.20.0 git-cmd.exe does not execute the first passed parameter. See the following easy command with multiple passed commands:

git-cmd.exe "echo 11 && echo 22 && echo 33 && exit"

The expected result is:

11
22
33

But 2.20.0 displays only:

22
33 
@PhilipOakley
Copy link

Could you confirm the two path environment strings you have in the two versions.

Ensuring the right variant of the .exe files is run can be a big problem (especially given the issue of catching Ctrl-C in the different environments). I'm not an expert in that area but there have been on-going issues between the different interpretations about how to handle the different OS paradigms....

@tuspet
Copy link
Author

tuspet commented Jan 28, 2019

Hi,
This problem is not connected to the environment.
The real problem is the following:
Although you can give a command-list to the git-cmd.exe passed as one long parameter (separated by the && characters) the newer git versions (2.20.0 and 2.10.1) forget to launch the first command in the list.
(Seemingly git-cmd starts to launch the passed commands from a wrong index.)
See the following screenshot as a clear reproduction of the issue:
gitcmd_issue_2039_with_example

@dscho
Copy link
Member

dscho commented Jan 28, 2019

I can confirm.

dscho added a commit to dscho/MINGW-packages that referenced this issue Jan 28, 2019
When we tried to make Git CMD safer recently, we inadvertently broke the
use case where users would call

	git-cmd "<some command>"

This was caused by the `doskey` command (which makes Git CMD safer)
swallowing the commands. To fix this, we simply add a double ampersand
to call multiple commands via a single command line (see
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd#remarks
for details).

This fixes git-for-windows/git#2039

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho dscho self-assigned this Jan 29, 2019
@dscho dscho added this to the v2.20.1(2) milestone Jan 29, 2019
dscho added a commit to git-for-windows/build-extra that referenced this issue Jan 29, 2019
The regression where `git-cmd <command>` would not execute the command
[was fixed](git-for-windows/git#2039).

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

dscho commented Jan 30, 2019

A new snapshot is available that should fix this issue. Could I ask y'all to please test?

@tuspet
Copy link
Author

tuspet commented Feb 7, 2019

Hi,
I downloaded the latest snapshot: Portable Git (self-extracting .7z archive): 32-bit.
Tue, 29 Jan 2019 20:05:21 +0100 (commit 9f16cdd)

For me it seems that the problem is not yet fixed.

I hope I downloaded a correct package as it seems that the issue is still reproducible:

for github issue 2039_still not working

Unfortunately I found still (an additional) problem with the parameter processing. See following picture:

for github issue 2039_additional problem

  1. Open a normal cmd.exe and go to the extracted git folder.
  2. Launch the git-cmd.exe "echo Apple && echo Banana" command (no exit command at the end!)
  3. As we are inside the git command line now, try to launch any git command like git --version. None of them are working.

If you think that this second problem is not connected to this parameter problem then I can open a new issue with it.

@dscho
Copy link
Member

dscho commented Feb 7, 2019

Darn. I wish I was aware of that before publishing Git for Windows v2.21.0-rc0. But since I did not hear anything in 8 days, I thought we're fine.

If you think that this second problem is not connected to this parameter problem then I can open a new issue with it.

I think this second problem is connected, but probably in a surprising way for you.

When you call git-cmd "some command", it executes that command, but then does not quit CMD! It is still in that CMD, and the reason why your first command is eaten is that it is considered part of the doskey command that overrides git so that git log does not pick up a git.cmd that is lying around in your current directory.

So now that you are still in that CMD, and now that git was overridden by doskey to some macro that includes your first command, it calls the correct git but with totally unwanted parameters!

If you now call exit and then git --version again, it will work.

dscho added a commit to git-for-windows/MINGW-packages that referenced this issue Feb 7, 2019
We looked for exactly one space after the quoted command, but we really
want to allow an arbitrary number of spaces there.

This should *really* fix
git-for-windows/git#2039 once and for all.

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

dscho commented Feb 21, 2019

@tuspet please re-test with v2.21.0-rc2.

@tuspet
Copy link
Author

tuspet commented Feb 22, 2019

Hi,

Thank you very much. Really great! It seems that the git-cmd.exe works now as expected.
image
The result is okay when we are in the simple cmd.exe, and when we are inside the git-cmd.exe.
See the attached picture. Thanks again!

@dscho
Copy link
Member

dscho commented Feb 23, 2019

@tuspet thanks for testing!

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

No branches or pull requests

3 participants