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

Fix console mode restoring #87

Merged

Conversation

dscho
Copy link
Member

@dscho dscho commented Mar 3, 2025

Under certain circumstances, when a non-MSYS process is spawned from an MSYS process that is spawned from a non-MSYS process that is spawned from an MSYS process, the console state can get corrupted by the MSYS2 runtime.

This is the case, for example, when spawning a background process that outputs to stdout from a Git hook.

This behavior is inherited from the Cygwin runtime which allows the same symptom to be reproduced as long as one is careful enough to force git.exe to use Cygwin's Bash to run its hooks.

The Cygwin core developer who is the only person to understand Cygwin's pseudo console handling was kind enough to fix this problem, and I backported it to the MSYS2 runtime v3.5.7.

This closes microsoft/git#730.
This closes git-for-windows/git#4776.

@dscho
Copy link
Member Author

dscho commented Mar 3, 2025

/open pr

The workflow run was started

The required console mode for a non-cygwin process is different from
that for a cygwin process. There are currently three modes: tty::cygwin,
tty::native, and tty::restore. The latter two are for the non-cygwin
processes. tty::restore is the mode for the non-cygwin processes that
started the cygwin process, used to restore the previous behaviour.
tty::native is the mode that reflects some terminfo flags. The issue
below is caused because the console mode fails to be restored to the
previous console mode used by cmd.exe.
This patch redesigns the strategy to determine which mode should be
set on console close() to fix all similar problems. Previously, the
number of handle count is used to determine the appropriate console
mode. However, the handle count seems uncertain for that purpose.
In the new design, the relation ship between the master process and
the process that is about to close the console is mainly used. This
can provide more certain result than previous one.

Addresses: microsoft/git#730
Backported-from: 3312f2d (Cygwin: console: Redesign mode set strategy on close()., 2025-03-03)
Fixes: 30d2669 ("Cygwin: console: Fix clean up conditions in close()")
Reported-by: Mike Marcelais, Johannes Schindelin <[email protected]>
Signed-off-by: Takashi Yano <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
@dscho dscho force-pushed the fix-non-cygwin-console-mode-on-close branch from f551f2a to 463ebcd Compare March 3, 2025 17:21
@dscho
Copy link
Member Author

dscho commented Mar 3, 2025

/open pr

The workflow run was started

@dscho dscho merged commit 1d21a67 into git-for-windows:main Mar 3, 2025
21 checks passed
@dscho dscho deleted the fix-non-cygwin-console-mode-on-close branch March 3, 2025 17:47
github-actions bot pushed a commit to git-for-windows/build-extra that referenced this pull request Mar 3, 2025
A bug has been
[fixed](git-for-windows/msys2-runtime#87) that,
when calling `git add -p` from VS Code's internal terminal, after using
the `e`dit command, caused [the internal terminal got
stuck](git-for-windows/git#4776) and no
further command was accepted.

Signed-off-by: gitforwindowshelper[bot] <[email protected]>
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

Successfully merging this pull request may close these issues.

Git hooks can corrupt command line on Windows Weird interaction with git add -p and Notepad++ (git hangs)
2 participants