Commit cbb3f3c9 authored by Johannes Schindelin's avatar Johannes Schindelin Committed by Junio C Hamano

mingw: intercept isatty() to handle /dev/null as Git expects it

When Git's source code calls isatty(), it really asks whether the
respective file descriptor is connected to an interactive terminal.

Windows' _isatty() function, however, determines whether the file
descriptor is associated with a character device. And NUL, Windows'
equivalent of /dev/null, is a character device.

Which means that for years, Git mistakenly detected an associated
interactive terminal when being run through the test suite, which
almost always redirects stdin, stdout and stderr to /dev/null.

This bug only became obvious, and painfully so, when the new
bisect--helper entered the `pu` branch and made the automatic build & test
time out because t6030 was waiting for an answer.

For details, see Johannes Schindelin's avatarJohannes Schindelin <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent c3808ca6
......@@ -384,6 +384,9 @@ int mingw_raise(int sig);
* ANSI emulation wrappers
int winansi_isatty(int fd);
#define isatty winansi_isatty
void winansi_init(void);
HANDLE winansi_get_osfhandle(int fd);
......@@ -7,6 +7,9 @@
#include <wingdi.h>
#include <winreg.h>
/* In this file, we actually want to use Windows' own isatty(). */
#undef isatty
ANSI codes used by git: m, K
......@@ -570,6 +573,36 @@ static void detect_msys_tty(int fd)
int winansi_isatty(int fd)
int res = isatty(fd);
if (res) {
* Make sure that /dev/null is not fooling Git into believing
* that we are connected to a terminal, as "_isatty() returns a
* nonzero value if the descriptor is associated with a
* character device."; for more information, see
HANDLE handle = (HANDLE)_get_osfhandle(fd);
if (fd == STDIN_FILENO) {
DWORD dummy;
if (!GetConsoleMode(handle, &dummy))
res = 0;
} else if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
if (!GetConsoleScreenBufferInfo(handle, &dummy))
res = 0;
return res;
void winansi_init(void)
int con1, con2;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment