Skip to content

Commit f1e2918

Browse files
committed
Merge branch 're-fix-git-hooks-problem'
The report in microsoft/git#730 describes a bug where running a background task in a Git hook was clashing with the MSYS2 runtime's console mode wrangling. Incidentally, the same fix addressed the bug git-for-windows/git#4776 reported: Running `git add -p` in Notepad++ (or VS Code), after `e`diting a hunk, the console gets stuck. Sadly, this bug fix caused a regression that was reported in msys2/msys2-runtime#268. Even more sadly, the fix for _that_ regression re-broke the Git hook issue described above. I reported this issue to Cygwin (via IRC, sorry, no public record), and they came up with this fix. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 46fafe3 + a86d33e commit f1e2918

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

winsup/cygwin/fhandler/console.cc

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ fhandler_console::setup ()
771771
con.disable_master_thread = true;
772772
con.master_thread_suspended = false;
773773
con.num_processed = 0;
774+
con.curr_input_mode = tty::restore;
775+
con.curr_output_mode = tty::restore;
774776
}
775777
}
776778

@@ -849,11 +851,6 @@ fhandler_console::set_input_mode (tty::cons_mode m, const termios *t,
849851
flags |= ENABLE_PROCESSED_INPUT;
850852
break;
851853
}
852-
if (con.curr_input_mode != tty::cygwin && m == tty::cygwin)
853-
{
854-
prev_input_mode_backup = con.prev_input_mode;
855-
con.prev_input_mode = oflags;
856-
}
857854
con.curr_input_mode = m;
858855
SetConsoleMode (p->input_handle, flags);
859856
if (!(oflags & ENABLE_VIRTUAL_TERMINAL_INPUT)
@@ -893,11 +890,6 @@ fhandler_console::set_output_mode (tty::cons_mode m, const termios *t,
893890
flags |= DISABLE_NEWLINE_AUTO_RETURN;
894891
break;
895892
}
896-
if (con.curr_output_mode != tty::cygwin && m == tty::cygwin)
897-
{
898-
prev_output_mode_backup = con.prev_output_mode;
899-
GetConsoleMode (p->output_handle, &con.prev_output_mode);
900-
}
901893
con.curr_output_mode = m;
902894
acquire_attach_mutex (mutex_timeout);
903895
DWORD resume_pid = attach_console (con.owner);
@@ -1836,6 +1828,12 @@ fhandler_console::open (int flags, mode_t)
18361828
handle_set.output_handle = h;
18371829
release_output_mutex ();
18381830

1831+
if (con.owner == GetCurrentProcessId ())
1832+
{
1833+
GetConsoleMode (get_handle (), &con.prev_input_mode);
1834+
GetConsoleMode (get_output_handle (), &con.prev_output_mode);
1835+
}
1836+
18391837
wpbuf.init ();
18401838

18411839
handle_set.input_mutex = input_mutex;
@@ -1881,6 +1879,19 @@ fhandler_console::open (int flags, mode_t)
18811879
setenv ("TERM", "cygwin", 1);
18821880
}
18831881

1882+
if (con.curr_input_mode != tty::cygwin)
1883+
{
1884+
prev_input_mode_backup = con.prev_input_mode;
1885+
GetConsoleMode (get_handle (), &con.prev_input_mode);
1886+
set_input_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
1887+
}
1888+
if (con.curr_output_mode != tty::cygwin)
1889+
{
1890+
prev_output_mode_backup = con.prev_output_mode;
1891+
GetConsoleMode (get_output_handle (), &con.prev_output_mode);
1892+
set_output_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
1893+
}
1894+
18841895
debug_printf ("opened conin$ %p, conout$ %p", get_handle (),
18851896
get_output_handle ());
18861897

@@ -4720,7 +4731,7 @@ fhandler_console::cons_mode_on_close (handle_set_t *p)
47204731
NTSTATUS status =
47214732
NtQueryInformationProcess (GetCurrentProcess (), ProcessBasicInformation,
47224733
&pbi, sizeof (pbi), NULL);
4723-
if (NT_SUCCESS (status)
4734+
if (NT_SUCCESS (status) && cygwin_pid (con.owner)
47244735
&& !process_alive ((DWORD) pbi.InheritedFromUniqueProcessId))
47254736
/* Execed from normal cygwin process and the parent has been exited. */
47264737
return tty::cygwin;

0 commit comments

Comments
 (0)