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 for Windows set VS Code as editor wrongly using exe instead of cmd #3452

Closed
1 task done
segevfiner opened this issue Oct 8, 2021 · 11 comments · Fixed by git-for-windows/build-extra#384
Closed
1 task done
Milestone

Comments

@segevfiner
Copy link

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

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options
git version 2.33.0.windows.2
cpu: x86_64
built from commit: 8735530946cced809cc6cc4c2ca3b078cdb3dfc8
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.19042.1237]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt
Editor Option: VisualStudioCode
Custom Editor Path:
Default Branch Option:
Path Option: Cmd
SSH Option: ExternalOpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: FFOnly
Use Credential Manager: Core
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable Pseudo Console Support: Disabled
Enable FSMonitor: Disabled
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

Pretty much a new computer and a clean install.

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

PowerShell 7.1.4

git commit
  • What did you expect to occur after running these commands?

The VS Code editor will open with the COMMIT_EDITMSG file, and when the tab is closed, the commit will proceed.

  • What actually happened instead?

The commit only proceeds when the window is closed, and I get strange debug messages from VS Code in the terminal.

  • Why this happens?

The VS Code code CLI is not the Code.exe executable, rather it is a bin\code.cmd inside the installation folder. It is this bin folder that is added to the PATH.

Git for Windows' installer sets:

[core]
	editor = \"C:\\Users\\Segev\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" --wait

But it should be:

[core]
	editor = \"C:\\Users\\Segev\\AppData\\Local\\Programs\\Microsoft VS Code\\bin\\code.cmd\" --wait

Or:

[core]
	editor = code --wait
  • If the problem was occurring with a specific repository, can you provide the
    URL to that repository to help us with testing?

Any repo.

@rimrul
Copy link
Member

rimrul commented Oct 8, 2021

Strongly related to #2616. We should probably also call the batch wrapper for VSCodium and VS Code Insiders.

@dscho
Copy link
Member

dscho commented Oct 8, 2021

I am worried about the implications, such as quoting paths containing spaces. The current contents of code.cmd seem to be:

@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
"%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %*
endlocal

The "run Electron as node" setting is probably the thing that upsets your VS Code.

Or:

[core]
	editor = code --wait

That only works if the user chose to add it to the PATH, which not all users do. So that's not an option.

@segevfiner
Copy link
Author

I am worried about the implications, such as quoting paths containing spaces. The current contents of code.cmd seem to be:

@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
"%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %*
endlocal

Passing paths with spaces works correctly for me, so I assume %* is the correct incantation in cmd/batch to forward arguments.

The "run Electron as node" setting is probably the thing that upsets your VS Code.

Or:

[core]
	editor = code --wait

The CLI entry point for VS Code is different from the GUI executable default entry point, launching the GUI executable directly will not give you the CLI. ELECTRON_RUN_AS_NODE is just an implementation detail of how this CLI script works. They need to run it with node.js rather than electron so they set this variable to use the node.js embedded in the Electron executable.

That only works if the user chose to add it to the PATH, which not all users do. So that's not an option.

Yep. And although VS Code does add itself to PATH (The bin sub-folder) on installation by default, it is likely more robust to resolve the path on installation.

@dscho
Copy link
Member

dscho commented Oct 8, 2021

Passing paths with spaces works correctly for me, so I assume %* is the correct incantation in cmd/batch to forward arguments.

Please be more precise: are you talking about manually launching the .cmd script? That's not my concern. My concern is how Git calls it.

@segevfiner
Copy link
Author

Passing paths with spaces works correctly for me, so I assume %* is the correct incantation in cmd/batch to forward arguments.

Please be more precise: are you talking about manually launching the .cmd script? That's not my concern. My concern is how Git calls it.

Tested this as well just now by creating a repo with spaces in the path and trying to commit. VS Code opened correctly.

@dscho
Copy link
Member

dscho commented Oct 8, 2021

@segevfiner
Copy link
Author

@segevfiner next step: find out how to change https://github.com/git-for-windows/build-extra/blob/4676f286a1ec830a5038b32400808a353dc6c48d/installer/install.iss#L1812 to pick up the .cmd instead of the .exe.

VisualStudioCodePath:=ExtractFileName(VisualStudioCodePath) + '\bin\code.cmd'?

@dscho
Copy link
Member

dscho commented Oct 8, 2021

@segevfiner next step: find out how to change https://github.com/git-for-windows/build-extra/blob/4676f286a1ec830a5038b32400808a353dc6c48d/installer/install.iss#L1812 to pick up the .cmd instead of the .exe.

VisualStudioCodePath:=ExtractFileName(VisualStudioCodePath) + '\bin\code.cmd'?

Is this robust, though? Have you found any official Visual Studio Code resources that talk about figuring out the path?

@segevfiner
Copy link
Author

@segevfiner next step: find out how to change https://github.com/git-for-windows/build-extra/blob/4676f286a1ec830a5038b32400808a353dc6c48d/installer/install.iss#L1812 to pick up the .cmd instead of the .exe.

VisualStudioCodePath:=ExtractFileName(VisualStudioCodePath) + '\bin\code.cmd'?

Is this robust, though? Have you found any official Visual Studio Code resources that talk about figuring out the path?

Not really. I do remember that this is the path to this since evey version of VS Code that I used, but to be sure we might want to rope in someone from the VS Code team, though I'm not sure what the appropriate channel to contact them is.

@segevfiner
Copy link
Author

@segevfiner next step: find out how to change https://github.com/git-for-windows/build-extra/blob/4676f286a1ec830a5038b32400808a353dc6c48d/installer/install.iss#L1812 to pick up the .cmd instead of the .exe.

VisualStudioCodePath:=ExtractFileName(VisualStudioCodePath) + '\bin\code.cmd'?

Is this robust, though? Have you found any official Visual Studio Code resources that talk about figuring out the path?

It appears VS Code actually does the same thing: https://github.com/microsoft/vscode/blob/ee1655a82ebdfd38bf8792088a6602c69f7bbd94/src/vs/platform/native/electron-main/nativeHostMainService.ts#L361

Whether they will ever change it or not, who knows...

@dscho
Copy link
Member

dscho commented Oct 11, 2021

Whether they will ever change it or not, who knows...

So for the moment, we can do the same. Up until it breaks, that is (iff it ever breaks).

Care to implement it and open a PR in build-extra?

@dscho dscho added this to the v2.33.1 milestone Oct 13, 2021
dscho added a commit to git-for-windows/build-extra that referenced this issue Oct 13, 2021
When VS Code is configured as editor, [it no
longer needs the window to be closed, just the
tab](git-for-windows/git#3452).

Signed-off-by: Johannes Schindelin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants