"Garbled" character output in PowerShell when launching "git gui" #6874

Closed
opened 2026-01-31 00:49:30 +00:00 by claunia · 3 comments
Owner

Originally created by @patrikhuber on GitHub (Mar 14, 2020).

Environment

  • OS: Microsoft Windows NT 10.0.18362.0
  • PowerShell version: 6.2.4
  • posh-git version/path: 1.0.0 beta3 ~\Documents\PowerShell\Modules\posh-git\1.0.0
  • git version 2.25.0.windows.1

Steps to reproduce

In a PowerShell, with posh-git and git-for-windows (which includes git gui) installed:

When typing git gui, the git gui window opens, but on the powershell prompt, the encoding of the characters is outputted and the cursor stays on that line. Only after pressing "Enter", the prompt becomes "normal" again.

~\MyProj [mybranch +2 ~2 -0 !]> git gui    <-- nicely colourised
~\MyProj [mybranch +2 ~2 -0 !]>    <-- no colours, "weird" output. Have to press "enter" to get prompt to normal again.
~\MyProj [mybranch +2 ~2 -0 !]>    <-- nicely colourised

image

Expected behavior

Quite obvious I think, the PowerShell prompt should output the "normal" prompt with the coloured characters and stuff (from posh-git).

Actual behavior

Stuff like [ is output (see above/screenshot).

Related issues

I've opened https://github.com/dahlbyk/posh-git/issues/738 first but the author suggested it's likely a git-gui issue. I've then opened https://github.com/prati0100/git-gui/issues/34 but the author said it might likely be a Windows Terminal issue and related to https://github.com/microsoft/terminal/issues/4809. After posting in https://github.com/microsoft/terminal/issues/4809, @DHowett-MSFT advised to open a new issue here, as my issue is with PowerShell, and not with git-bash.

Originally created by @patrikhuber on GitHub (Mar 14, 2020). # Environment * OS: Microsoft Windows NT 10.0.18362.0 * PowerShell version: 6.2.4 * posh-git version/path: 1.0.0 beta3 ~\Documents\PowerShell\Modules\posh-git\1.0.0 * git version 2.25.0.windows.1 # Steps to reproduce In a PowerShell, with posh-git and git-for-windows (which includes git gui) installed: When typing `git gui`, the git gui window opens, but on the powershell prompt, the encoding of the characters is outputted and the cursor stays on that line. Only after pressing "Enter", the prompt becomes "normal" again. ``` ~\MyProj [mybranch +2 ~2 -0 !]> git gui <-- nicely colourised ~\MyProj [mybranch +2 ~2 -0 !]> <-- no colours, "weird" output. Have to press "enter" to get prompt to normal again. ~\MyProj [mybranch +2 ~2 -0 !]> <-- nicely colourised ``` ![image](https://user-images.githubusercontent.com/4967343/74587540-ab6a4a00-4feb-11ea-93fb-99cadce54d23.png) # Expected behavior Quite obvious I think, the PowerShell prompt should output the "normal" prompt with the coloured characters and stuff (from posh-git). # Actual behavior Stuff like `[` is output (see above/screenshot). # Related issues I've opened https://github.com/dahlbyk/posh-git/issues/738 first but the author suggested it's likely a git-gui issue. I've then opened https://github.com/prati0100/git-gui/issues/34 but the author said it might likely be a Windows Terminal issue and related to https://github.com/microsoft/terminal/issues/4809. After posting in https://github.com/microsoft/terminal/issues/4809, @DHowett-MSFT advised to open a new issue here, as my issue is with PowerShell, and not with git-bash.
claunia added the Resolution-Duplicate label 2026-01-31 00:49:30 +00:00
Author
Owner

@DHowett-MSFT commented on GitHub (Mar 14, 2020):

Alright, I just got this thing under event tracing. Here's what I found (annotated)

image

(time goes from left to right)

What's happening is this:

  1. I type in git gui, press enter
  2. Powershell disables VT rendering (for compatibility reasons), setting mode=3
  3. git.exe launches, and kicks off a sequence of processes (one of which is sh.exe)
  4. git.exe exits, returning control to Powershell
  5. Powershell re-enables VT rendering, setting mode=7
  6. Powershell prints its prompt, or when it's being slow it doesn't print its prompt.
  7. sh.exe, which was spawned under line 3, disables VT rendering (mode=3)
  8. Powershell finishes printing the prompt and begins taking user input
  9. When the user types, powershell tries to use VT (disabled on line 7) to color it
  10. This happens: image

Unfortunately, there isn't anything powershell (or the windows console!) can do to help this situation: the output mode is console-wide global state, and sh.exe is setting that global state to ignore powershell's text rendering commands—after powershell was put back in control.

@DHowett-MSFT commented on GitHub (Mar 14, 2020): Alright, I just got this thing under event tracing. Here's what I found (annotated) ![image](https://user-images.githubusercontent.com/14316954/76690446-2e87bb80-65fd-11ea-8f30-f5385a6cfc0f.png) (time goes from left to right) What's happening is this: 1. I type in `git gui`, press enter 2. Powershell _disables_ VT rendering (for compatibility reasons), setting mode=3 3. `git.exe` launches, and kicks off a sequence of processes (one of which is `sh.exe`) 4. `git.exe` _exits_, returning control to Powershell 5. Powershell _re-enables_ VT rendering, setting mode=7 6. Powershell prints its prompt, or when it's being slow it _doesn't_ print its prompt. 7. `sh.exe`, which was spawned under line 3, _disables VT rendering_ (mode=3) 8. Powershell finishes printing the prompt and begins taking user input 9. When the user types, powershell tries to use VT (disabled on line 7) to color it 10. This happens: ![image](https://user-images.githubusercontent.com/14316954/76690479-8e7e6200-65fd-11ea-8df5-fe7afc0a76dc.png) Unfortunately, there isn't anything powershell (or the windows console!) can do to help this situation: the output mode is console-wide global state, and sh.exe is setting that global state to ignore powershell's text rendering commands—after powershell was put back in control.
Author
Owner

@DHowett-MSFT commented on GitHub (Mar 17, 2020):

In light of all this, I've filed /dup #4954 to track figuring out whether we can make the output handle mode process-local state instead of global state.

@DHowett-MSFT commented on GitHub (Mar 17, 2020): In light of all this, I've filed /dup #4954 to track figuring out whether we can make the output handle mode process-local state instead of global state.
Author
Owner

@ghost commented on GitHub (Mar 17, 2020):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Mar 17, 2020): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#6874