Subject: Re: [PATCH] editor: only save (and restore) the terminal if using a tty

From: Junio C Hamano <[email-masked]>
Date: Wed, 24 Nov 2021 12:51:00 -0800

Carlo Arenas <[email-masked]> writes:

> On Wed, Nov 24, 2021 at 11:34 AM Junio C Hamano <[email-masked]> wrote:
>>
>> Why 'vi' and 'vim' are so special?  Is this an attempt to paper over
>> a bug in 'vim' on the caller side?
>
> not sure if the bug is on vi/vim, cygwin's pty or the new conPTY that
> Windows Terminal uses; but in Git for Windows, using an MSYS vim (that
> uses cygwin's pty) within Windows Terminal (and other terminals that
> use conPTY most likely) leads to this terminal output corruption, that
> bash "fixes" when it gets the control back, but that git does not
> (unless something like what I am proposing is done), and that is
> specially disruptive when doing several commits in a series (ex: an
> interactive rebase).
>
> you could say it is an attempt to paper over that bug, but IMHO it is
> also a way for git to protect itself from a "rogue" editor, as it is
> now just trusting that the editor wouldn't mess with its terminal
> settings after being invoked and it returns control to git.

Surely, bash keeps using the same TTY and it may be in its interest
to "protect" it.  We on the other hand would exit when we are done
and no need for the TTY.  In other words, bash may "own" TTY and it
may want to take a good care of it.  We don't.

I would have to say that your argument is a bit of stretch ;-).