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

error: unable to start editor '' (error: cannot spawn : No such file or directory) #2011

Closed
1 task done
Simran-B opened this issue Jan 8, 2019 · 19 comments
Closed
1 task done
Assignees
Milestone

Comments

@Simran-B
Copy link

Simran-B commented Jan 8, 2019

  • 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 2.20.1.windows.1
cpu: x86_64
built from commit: 7c9fbc07db0e2939b36095df45864b8cda19b64f
sizeof-long: 4
sizeof-size_t: 8
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
Microsoft Windows [Version 10.0.17134.472] (Pro, 64-bit)
  • What options did you set as part of the installation? Or did you choose the
    defaults?
Editor Option: VisualStudioCode
Custom Editor Path:
Path Option: Cmd
SSH Option: OpenSSH
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Performance Tweaks FSCache: Enabled
Use Credential Manager: Enabled
Enable Symlinks: Enabled

Details

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

CMD

git rebase -i HEAD~2
  • What did you expect to occur after running these commands?

Interactive rebase to start Visual Studio Code

  • What actually happened instead?

Git was unable to launch Visual Studio Code:

hint: Waiting for your editor to close the file... error: cannot spawn : No such file or directory
error: unable to start editor ''

I then ran the Git setup again and made sure that Visual Studio Code is selected as default editor, but after re-installation and opening a new command prompt, the same problem still occurred.

Then I checked the configuration:

$ git config --global core.editor
'C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe' --wait

If I use Ctrl+R for this very command in single quote marks, an error occurs (not found). If I replace the single quote marks by double quote marks, VSCode is launched successfully:

"C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe" --wait

I tried to change the configuration:

$ git config --global core.editor "C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe" --wait
$ git config --global core.editor
C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe

This does not work, the quote marks and the --wait option disappear. I tried a few variations and ended up with this:

$ git config --global core.editor "\"C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe\" --wait"

$ git config --global core.editor
"C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe" --wait

This looked promising, but the interactive rebase still fails with the same error message (same if I don't add quote marks). How to properly configure Git for VSCode under Windows?

@dscho
Copy link
Member

dscho commented Jan 9, 2019

Does it work if you replace the backslashes by forward slashes?

@Simran-B
Copy link
Author

I tried all of the following and none worked:

"C:/Users/Simran/AppData/Local/Programs/Microsoft VS Code/Code.exe"

"C:/Users/Simran/AppData/Local/Programs/Microsoft VS Code/Code.exe --wait"
"\"C:/Users/Simran/AppData/Local/Programs/Microsoft VS Code/Code.exe\" --wait"
"'C:/Users/Simran/AppData/Local/Programs/Microsoft VS Code/Code.exe' --wait"

"C:\\Users\\Simran\\AppData\\Local\\Programs\\Microsoft_VS_Code\\Code.exe --wait"
"\"C:\\Users\\Simran\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" --wait"
"'C:\\Users\\Simran\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe' --wait"

"C:\\\\Users\\\\Simran\\\\AppData\\\\Local\\\\Programs\\\\Microsoft_VS_Code\\\\Code.exe --wait"
"\"C:\\\\Users\\\\Simran\\\\AppData\\\\Local\\\\Programs\\\\Microsoft VS Code\\\\Code.exe\" --wait"
"'C:\\\\Users\\\\Simran\\\\AppData\\\\Local\\\\Programs\\\\Microsoft VS Code\\\\Code.exe' --wait"

"C://Users//Simran//AppData//Local//Programs//Microsoft_VS_Code//Code.exe --wait"
"\"C://Users//Simran//AppData//Local//Programs//Microsoft VS Code//Code.exe\" --wait"
"'C://Users//Simran//AppData//Local//Programs//Microsoft VS Code//Code.exe' --wait"

I even renamed the folder to Microsoft_VS_Code (so no spaces in the path anymore) and tried these:

"C:\Users\Simran\AppData\Local\Programs\Microsoft_VS_Code\Code.exe --wait"
"\"C:\Users\Simran\AppData\Local\Programs\Microsoft_VS_Code\Code.exe\" --wait"
"'C:\Users\Simran\AppData\Local\Programs\Microsoft_VS_Code\Code.exe' --wait"

"C:\\Users\\Simran\\AppData\\Local\\Programs\\Microsoft_VS_Code\\Code.exe --wait"
"\"C:\\Users\\Simran\\AppData\\Local\\Programs\\Microsoft_VS_Code\\Code.exe\" --wait"
"'C:\\Users\\Simran\\AppData\\Local\\Programs\\Microsoft_VS_Code\\Code.exe' --wait"

"C:\\\\Users\\\\Simran\\\\AppData\\\\Local\\\\Programs\\\\Microsoft_VS_Code\\\\Code.exe --wait"
"\"C:\\\\Users\\\\Simran\\\\AppData\\\\Local\\\\Programs\\\\Microsoft_VS_Code\\\\Code.exe\" --wait"
"'C:\\\\Users\\\\Simran\\\\AppData\\\\Local\\\\Programs\\\\Microsoft_VS_Code\\\\Code.exe' --wait"

"C:/Users/Simran/AppData/Local/Programs/Microsoft_VS_Code/Code.exe --wait"
"\"C:/Users/Simran/AppData/Local/Programs/Microsoft_VS_Code/Code.exe\" --wait"
"'C:/Users/Simran/AppData/Local/Programs/Microsoft_VS_Code/Code.exe' --wait"

"C://Users//Simran//AppData//Local//Programs//Microsoft_VS_Code//Code.exe --wait"
"\"C://Users//Simran//AppData//Local//Programs//Microsoft_VS_Code//Code.exe\" --wait"
"'C://Users//Simran//AppData//Local//Programs//Microsoft_VS_Code//Code.exe' --wait"

The error is always

hint: Waiting for your editor to close the file... error: cannot spawn : No such file or directory
error: unable to start editor ''

It seems like something is fundamentally broken in the way Git tries to launch another program.

@PhilipOakley
Copy link

Just wondering if this has a long tail link to #2001, and onward to #2007, which is a recent change noted as:

This problem becomes apparent on Git for Windows since fe21c6b285df
(mingw: reencode environment variables on the fly (UTF-16 <-> UTF-8)),
when the getenv() implementation provided in compat/mingw.c was changed
to keep a certain amount of alloc'ed strings and freeing them on
subsequent calls.

@Simran-B
Copy link
Author

Sounds probable, especially because git commit --amend launches VS Code for me without issues if I set it back to the default (so this is certainly not an installer issue). It also works with escaped double quote marks and with forward slashes:

git config --global core.editor "'C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe' --wait"
git config --global core.editor "\"C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe\" --wait"
git config --global core.editor "'C:/Users/Simran/AppData/Local/Programs/Microsoft VS Code/Code.exe' --wait"

@Simran-B
Copy link
Author

Interestingly, VS Code is also started successfully for COMMIT_EDITMSG in a merge with 50k files involved.

@dscho
Copy link
Member

dscho commented Feb 21, 2019

@Simran-B could you test with v2.21.0-rc0? There are quite a few getenv()-related fixes and workarounds in that version.

@dscho
Copy link
Member

dscho commented Feb 26, 2019

@Simran-B or with the latest snapshot?

@Simran-B
Copy link
Author

Simran-B commented Feb 26, 2019

First, I verified that the error occurs in Command Prompt, PowerShell as well as Git Bash using v2.20.1 - it does. So it shouldn't matter which terminal is used to check if a particular version is broken or not.

Next, I downloaded the PortableGit 2.21.0 64-bit packages of rc0, rc1 and rc2 and tried the same command in git-bash.exe and git-cmd.exe.
❌ Got the error in every attempt.

I also tried:
❌ PortableGit snapshot 2.21.0.rc2.windows.1.707.gf6431ebcae (64 and 32 bit)
❌ MinGit-prerelease-2.21.0.rc2.windows.1.707.gf6431ebcae-64-bit (cmd\git.exe)
❌ MinGit-prerelease-2.21.0.rc2.windows.1.707.gf6431ebcae-BusyBox-64-bit (cmd\git.exe)
❌ Git-prerelease-2.21.0.rc2.windows.1.707.gf6431ebcae-64-bit.exe (Windows installer)

... but to no avail 😞

Finally, I tried to find the last working version:
✔️ 2.17.0.windows.1
✔️ 2.18.0.windows.1
✔️ 2.19.0.rc0.windows.1
❌ 2.19.0.rc0.windows.2
✔️ 2.19.0.rc1.windows.1
✔️ 2.19.0.rc2.windows.1
✔️ 2.19.0.windows.1
✔️ 2.19.1.windows.1
❌ 2.19.2.windows.1
❌ 2.20.0.rc0.windows.1
❌ 2.20.0.rc1.windows.1
❌ 2.20.0.rc2.windows.1
❌ 2.20.0.windows.1

So it was broken somewhere between 2.19.1 and 2.19.2, except that there is exactly one RC (2.19.0.rc0.windows.2) which is also broken, but not the preceding and following release candidates - what on earth?!

@Simran-B
Copy link
Author

Simran-B commented Feb 26, 2019

Found the answer here: git-for-windows/build-extra#203 (comment)

  • 2.19.1 has optional support for built-in rebase, but it's disabled by default
  • 2.19.2 uses the built-in rebase by default, rebase.useBuiltin true does not need to be set
  • If I explicitly set this to false, then the built-in rebase is not used and it works. If it's enabled, then it fails. The built-in rebase was apparently never able to launch the editor on Windows and is broken up to the latest snapshot.

image

@dscho
Copy link
Member

dscho commented Feb 26, 2019

@Simran-B thank you for your patient reporting and testing.

What you found is an odd thing, indeed, until one realizes that there are two ways to launch the editor: one from git.exe directly, and one from the (still too many) Unix shell scripts in which part of Git is implemented.

The Unix shell scripts have no problem with the single quotes, but git.exe does.

So what I am doing right now is to change the installer to use double quotes when configuring the editor.

@dscho dscho self-assigned this Feb 26, 2019
@dscho dscho added this to the v2.21.0 milestone Feb 26, 2019
dscho added a commit to git-for-windows/build-extra that referenced this issue Feb 26, 2019
This fixes git-for-windows/git#2011, and while
at it also starts supporting system-wide Sublime Text installations.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to git-for-windows/build-extra that referenced this issue Feb 26, 2019
The installer [now configures editors so that the built-in rebase
can use them](git-for-windows/git#2011).

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

dscho commented Feb 26, 2019

@Simran-B you can even test the last-minute snapshot before v2.21.0...

@Simran-B
Copy link
Author

Simran-B commented Mar 1, 2019

@dscho Sorry but it seems to be broken still. I manually changed core.editor to use double quote marks and tried with the latest portable snapshot (2.21.0.windows.1.4.gda5a923050), but it still failed.

Then I set it to something random to test the installer:

>git config --global --get-all core.editor
calc.exe

I installed the 64-bit snapshot and verified that core.editor gets set with quotation marks:

>git config --global --get-all core.editor
"C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe" --wait

But this still errors out for the built-in rebase, no matter if I use cmd, Powershell or git-bash:

>git rebase -i HEAD~1
hint: Waiting for your editor to close the file... error: cannot spawn : No such file or directory
error: unable to start editor ''

Also tested if the spaces in the editor path might cause this, but they don't:

>git config --global core.editor "\"C:\Users\Simran\AppData\Local\Programs\Microsoft_VS_Code\Code.exe\" --wait"

>git rebase -i HEAD~1
hint: Waiting for your editor to close the file... error: cannot spawn : No such file or directory
error: unable to start editor ''

>git config rebase.useBuiltin false
>git rebase -i HEAD~1

[main 2019-03-01T09:43:56.474Z] update#setState idle
Successfully rebased and updated refs/heads/devel.

@dscho
Copy link
Member

dscho commented Mar 1, 2019

Can you re-run the git rebase -i HEAD^ command after setting GIT_TRACE=1?

@dscho
Copy link
Member

dscho commented Mar 1, 2019

For me, VS Code opens correctly, and the log up to that point reads:

$ GIT_TRACE=1 git rebase -i HEAD^
11:23:07.400499 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
11:23:07.400499 git.c:419               trace: built-in: git rebase -i HEAD^
11:23:07.400499 run-command.c:643       trace: run_command: git config --bool rebase.usebuiltin
11:23:07.420499 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
11:23:07.422499 git.c:419               trace: built-in: git config --bool rebase.usebuiltin
11:23:07.446499 run-command.c:643       trace: run_command: GIT_CHERRY_PICK_HELP='Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".' git rebase--interactive --autosquash --upstream=bf91b39e3c32f5b7e5a2660feea7b832d21bc7c2 --onto=bf91b39e3c32f5b7e5a2660feea7b832d21bc7c2 --onto-name=HEAD^ --head-name=refs/heads/master --allow-empty-message
11:23:07.464496 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
11:23:07.468498 git.c:419               trace: built-in: git rebase--interactive --autosquash --upstream=bf91b39e3c32f5b7e5a2660feea7b832d21bc7c2 --onto=bf91b39e3c32f5b7e5a2660feea7b832d21bc7c2 --onto-name=HEAD^ --head-name=refs/heads/master --allow-empty-message
hint: Waiting for your editor to close the file... 11:23:07.493515 run-command.c:643       trace: run_command: '"C:\\Program Files\\Microsoft VS Code\\Code.exe" --wait' C:/git-sdk-64/usr/src/build-extra/.git/rebase-merge/git-rebase-todo

[main 2019-03-01T10:23:08.197Z] update#setState idle

@Simran-B
Copy link
Author

Simran-B commented Mar 1, 2019

cmd:

>git version
git version 2.21.0.windows.1.4.gda5a923050

>git config core.editor
"C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe" --wait

>git config rebase.useBuiltin

>set GIT_TRACE=1

C:\xxx>git rebase -i "HEAD^"
12:27:47.262374 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
12:27:47.263393 git.c:419               trace: built-in: git rebase -i HEAD^
12:27:47.266405 run-command.c:643       trace: run_command: git config --bool rebase.usebuiltin
12:27:47.311472 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
12:27:47.317470 git.c:419               trace: built-in: git config --bool rebase.usebuiltin
12:27:48.352353 run-command.c:643       trace: run_command: GIT_CHERRY_PICK_HELP='Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".' git rebase--interactive --autosquash --upstream=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto-name=HEAD^ --head-name=refs/heads/devel --allow-empty-message
12:27:48.405510 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
12:27:48.414526 git.c:419               trace: built-in: git rebase--interactive --autosquash --upstream=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto-name=HEAD^ --head-name=refs/heads/devel --allow-empty-message
hint: Waiting for your editor to close the file... 12:27:48.487764 run-command.c:643       trace: run_command:  C:/xxx/.git/rebase-merge/git-rebase-todo
error: cannot spawn : No such file or directory
error: unable to start editor ''

powershell:

PS C:\xxx> $env:GIT_TRACE = 1
PS C:\xxx> git rebase -i HEAD^
12:35:58.677364 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
12:35:58.679363 git.c:419               trace: built-in: git rebase -i HEAD^
12:35:58.679363 run-command.c:643       trace: run_command: git config --bool rebase.usebuiltin
12:35:58.707483 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
12:35:58.713480 git.c:419               trace: built-in: git config --bool rebase.usebuiltin
12:35:59.505232 run-command.c:643       trace: run_command: GIT_CHERRY_PICK_HELP='Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".' git rebase--interactive --autosquash --upstream=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto-name=HEAD^ --head-name=refs/heads/devel --allow-empty-message
12:35:59.535217 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
12:35:59.547213 git.c:419               trace: built-in: git rebase--interactive --autosquash --upstream=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto-name=HEAD^ --head-name=refs/heads/devel --allow-empty-message
hint: Waiting for your editor to close the file... 12:35:59.600197 run-command.c:643       trace: run_command:  C:/xxx/.git/rebase-merge/git-rebase-todo
error: cannot spawn : No such file or directory
error: unable to start editor ''

git-bash:

$ GIT_TRACE=1 git rebase -i HEAD^
12:37:34.931428 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
12:37:34.932429 git.c:419               trace: built-in: git rebase -i HEAD^
12:37:34.932429 run-command.c:643       trace: run_command: git config --bool rebase.usebuiltin
12:37:34.961419 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
12:37:34.969418 git.c:419               trace: built-in: git config --bool rebase.usebuiltin
12:37:35.811162 run-command.c:643       trace: run_command: GIT_CHERRY_PICK_HELP='Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".' git rebase--interactive --autosquash --upstream=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto-name=HEAD^ --head-name=refs/heads/devel --allow-empty-message
12:37:35.843149 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
12:37:35.857145 git.c:419               trace: built-in: git rebase--interactive --autosquash --upstream=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto=e7cdfaa2cb2286cffe43b0931c56a5e574787945 --onto-name=HEAD^ --head-name=refs/heads/devel --allow-empty-message
hint: Waiting for your editor to close the file... 12:37:35.926123 run-command.c:643       trace: run_command:  C:/xxx/.git/rebase-merge/git-rebase-todo
error: cannot spawn : No such file or directory
error: unable to start editor ''

There does not seem to be a difference between the terminals, except how you can set (temporary) environment variables and whether ^ needs to be quoted to work.

The interesting bit is: it tries to launch the file(!), not the editor with file path as argument 😕

VS Code is configured globally as editor:

>git config --get-all --local core.editor

>git config --get-all --worktree core.editor

>git config --get-all --system core.editor

>git config --get-all --global core.editor
"C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe" --wait

>git config --get-all core.editor
"C:\Users\Simran\AppData\Local\Programs\Microsoft VS Code\Code.exe" --wait

But even if I also set it for local, system and worktree explicitly, it still lacks the editor path in the run command:
run_command: C:/xxx/.git/rebase-merge/git-rebase-todo

@dscho
Copy link
Member

dscho commented Mar 1, 2019

Did you notice the two spaces before the file name? I think that your sequence editor is somehow configured to the empty string.

Can you see what git config --show-origin sequence.editor says? Or maybe you have the environment variable GIT_SEQUENCE_EDITOR set to the empty string somewhere (find out by calling echo "${GIT_SEQUENCE_EDITOR+set}" in Git Bash)?

@Simran-B
Copy link
Author

Simran-B commented Mar 1, 2019

I did not see the extra space to be honest... Does this look good or bad?

>git config --show-origin sequence.editor
file:C:/Users/Simran/.gitconfig

The command you suggested does not print anything. With bash -x it prints:

$ echo "${GIT_SEQUENCE_EDITOR+set}"
+ echo ''

I also created an empty env var with regedit of my own to compare the behavior and it then printed set as opposed to above command. There is clearly no GIT_* env var:

image

image

@Simran-B
Copy link
Author

Simran-B commented Mar 1, 2019

From the git docs:

sequence.editor
Text editor used by git rebase -i for editing the rebase instruction file. The value is meant to be interpreted by the shell when it is used. It can be overridden by the GIT_SEQUENCE_EDITOR environment variable. When not configured the default commit message editor is used instead.

So you can override which editor should be used for interactive rebases. I just checked my .gitconfig and see what I found:

[sequence]
	editor = 

I removed this section and tada, it works! 🍾 🎈 🎉

>git rebase -i HEAD~1
hint: Waiting for your editor to close the file...
Successfully rebased and updated refs/heads/devel.

No clue how this got into the configuration file though... Was this set by some legacy installer perhaps? Or some misbehaving script, e.g. the chocolatey installer for Git? (can't remember if I installed Git with choco the first time on this machine...)

This probably explains why other commands were able to launch VS Code too: They likely use the default editor, which does not get overwritten by the sequence.editor setting.

@dscho
Copy link
Member

dscho commented Mar 1, 2019

Yeah, finally figured it out!

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