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

The Git-for-windows installer should create an shortcut icon for bash.exe #3689

Open
1 task done
octogonz opened this issue Feb 9, 2022 · 5 comments
Open
1 task done

Comments

@octogonz
Copy link

octogonz commented Feb 9, 2022

  • 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? 64-bit
$ git --version --build-options

git version 2.31.1.windows.1
cpu: x86_64
built from commit: c5f0be26a7e3846e3b6268d1c6c4800d838c6bbb
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
  • Which version of Windows are you running? 10 / 64-bit
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.19043.1466]
  • 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: CustomEditor
Custom Editor Path: C:\Program Files\Kate\bin\kwrite.exe
Default Branch Option:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Merge
Use Credential Manager: Core
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable Pseudo Console Support: Disabled

Details

The problem

There is a longstanding known issue where Git Bash's TTY gets lost when STDIN is passed to a shell command on Windows. This breaks programs that want to interactively prompt for terminal input.

Examples of people who encountered this problem over the years:

The status quo

The commonly recommended workaround is to use the winpty wrapper for EVERY such shell command. Instead of rush setup, we must do winpty rush.cmd setup. Instead of yarn upgrade-interactive, we must do winpty yarn.cmd upgrade-interactive. And so forth.

This works but is obviously very clumsy.

A better solution

It turns out that Git provides two Bash binaries:

  • C:\Program Files\Git\git-bash.exe - This is what gets launched by the Git Bash shortcut icon. It requires winpty because its terminal is the mintty.exe from MinGW. (A GUI app that does custom font rendering.)
  • C:\Program Files\Git\bin\bash.exe - This is a conventional Windows console app (with Microsoft fonts), which opens a Win32 terminal, and therefore its TTY is compatible with other Windows console apps like node.exe.

Thus, a really great workaround is to drag+drop C:\Program Files\Git\bin\bash.exe onto your Windows desktop, and create a shortcut icon for it. That will open a nice Bash terminal with no need for winpty. This seems like a much better workaround. 👍👍

Questions:

  1. Why doesn't the Git-for-windows installer create a shortcut icon for bash.exe? (For example maybe there could be two icons, Git Bash - MinTTY and Git Bash - Terminal?)
  2. Shouldn't bash.exe be the preferred default experience for people who are wanting to use Bash on Windows? What's so preferable about mintty.exe?
@rimrul
Copy link
Member

rimrul commented Feb 9, 2022

It turns out that Git provides two Bash binaries:

  • C:\Program Files\Git\git-bash.exe - This is what gets launched by the Git Bash shortcut icon. It requires winpty because its terminal is the mintty.exe from MinGW. (A GUI app that does custom font rendering.)
  • C:\Program Files\Git\bin\bash.exe - This is a conventional Windows console app (with Microsoft fonts), which opens a Win32 terminal, and therefore its TTY is compatible with other Windows console apps like node.exe.

It's (as always) more complicated than that. Git Bash doesn't need to run using mintty, it can also run using Conhost.
There's an option in the installer to choose which one you prefer. In fact, we used to have only Conhost based Git Bash back in the days of Git for Windows 1.x.

What's so preferable about mintty.exe?

If you're on a recent build of Windows 10, not terribly much. If you're on an old build of Windows 10 or an even older version of Windows, everything. Microsoft has improved Conhost a lot in recent years, but we're still supporting versions going back to Vista and our support for new Conhost features like ConPTY is still experimental. Once that becomes stable we might consider flipping the default to Conhost on fresh installs on new Builds of Windows 10.

  1. Why doesn't the Git-for-windows installer create a shortcut icon for bash.exe?

Because we don't want people calling that executable directly. Its existence is an implementation detail. There's slightly more to Git Bash than just calling mintty /bin/bash

@dscho
Copy link
Member

dscho commented Feb 9, 2022

There is an option in Git for Windows' installer to use ConHost instead of MinTTY. That should address your concern.

Having two Git Bash shortcuts -- one that uses MinTTY, the other ConHost -- would simply be too confusing.

@octogonz
Copy link
Author

octogonz commented Feb 9, 2022

People typically encounter this problem a long time after they installed Git Bash. Maybe it was installed by someone else, e.g. a lab administrator or a developer SDK.

Our current solution looks like this:

C:\Example> rush setup

NPM credentials are missing or expired

ERROR: It appears that Rush was invoked from Git Bash shell, which does not support the
TTY mode for interactive input that is required by this feature.

Known workarounds are:
- Invoke Rush using "winpty rush.cmd" instead of "rush"
- Or add this to your .bashrc:  alias rush="winpty rush.cmd"
- Or create a Git Bash shortcut icon that launches
  "C:\Program Files\Git\bin\bash.exe" instead of "git-bash.exe"

It sounds like you're proposing that we add an item:

- Uninstall Git for Windows, then reinstall it. While installing, be sure to
  uncheck "Only show new options". After having clicked the "Next"
  button 8 times, you will get to a page that asks you to choose between
  "Use MinTTY" versus "Use Windows' default console window."
  Make sure to choose the second one.  Having done so, the "Git Bash"
  icon on your computer will now behave differently from the identical
  "Git Bash" icon on other people's computers who did not do this.
  Specifically, it will work correctly with Node.js.

Whereas I'm asking for a simpler world where we can say:

- When launching Git Bash, click on the icon that says "Git Bash - Console"
  instead of the icon that says "Git Bash - MinTTY"

@octogonz
Copy link
Author

octogonz commented Feb 9, 2022

Git Bash doesn't need to run using mintty, it can also run using Conhost.
There's an option in the installer to choose which one you prefer.

I noticed that the Git Bash shortcut invokes "C:\Program Files\Git\git-bash.exe" --cd-to-home regardless of which option was chosen during installation. Where is the state stored? If it's in a text file that can be modified (without Administrator permissions), then maybe Rush could prompt to fix the setting.

Something like:

It appears that Rush was invoked from Git Bash shell.  Node.js cannot prompt for
input because your Git Bash is configured to use MinTTY.

Would you like to reconfigure Git Bash to use a Windows console? Yes/No

@rimrul
Copy link
Member

rimrul commented Feb 10, 2022

I noticed that the Git Bash shortcut invokes "C:\Program Files\Git\git-bash.exe" --cd-to-home regardless of which option was chosen during installation. Where is the state stored?

Directly in git-bash.exe.

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