Skip to content

Commit d46f476

Browse files
committed
merge: do not trust fstat(2) too much when checking interactiveness
The heuristic used by "git merge" to decide if it automatically gives an editor upon clean automerge is to see if the standard input and the standard output is the same device and is a tty, we are in an interactive session. "The same device" test was done by comparing fstat(2) result on the two file descriptors (and they must match), and we asked isatty() only for the standard input (we insist that they are the same device and there is no point asking tty-ness of the standard output). The stat(2) emulation in the Windows port however does not give a usable value in the st_ino field, so even if the standard output is connected to something different from the standard input, "The same device" test may incorrectly return true. To accomodate it, add another isatty() check for the standard output stream as well. Reported-by: Erik Faye-Lund <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1f1b96 commit d46f476

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ static int default_edit_option(void)
11291129
/* Use editor if stdin and stdout are the same and is a tty */
11301130
return (!fstat(0, &st_stdin) &&
11311131
!fstat(1, &st_stdout) &&
1132-
isatty(0) &&
1132+
isatty(0) && isatty(1) &&
11331133
st_stdin.st_dev == st_stdout.st_dev &&
11341134
st_stdin.st_ino == st_stdout.st_ino &&
11351135
st_stdin.st_mode == st_stdout.st_mode);

0 commit comments

Comments
 (0)