The issue "Duplicated lines when moving in pager #3235" will be fixed with Git 2.33 (Q3 2021).
You can test it today with Git for Windows snapshots.

(see duplicate lines at the top)
Root cause: when we cannot figure out how wide the terminal is, we use a fallback value of 80 ourselves (which cannot be avoided), but when we run the pager, we export it in COLUMNS
, which forces the pager to use the hardcoded value, even when the pager is perfectly capable to figure it out itself.
Stop exporting COLUMNS
when we fall back on the hardcoded default value for our own use.
See commit 9b6e2c8 (21 Jun 2021) by Johannes Schindelin (dscho
).
(Merged by Junio C Hamano -- gitster
-- in commit 32d6280, 08 Jul 2021)
pager
: avoid setting COLUMNS
when we're guessing its value
Co-authored-by: Junio C Hamano
Signed-off-by: Johannes Schindelin
We query TIOCGWINSZ
in Git to determine the correct value for COLUMNS
, and then set that environment variable.
If TIOCGWINSZ
is not available, we fall back to the hard-coded value 80 and still set the environment variable.
On Windows this is a problem.
The reason is that Git for Windows uses a version of less
that relies on the MSYS2 runtime to interact with the pseudo terminal (typically inside a MinTTY window, which is also aware of the MSYS2 runtime).
Both MinTTY and less.exe
interact with that pseudo terminal via ioctl()
calls (which the MSYS2 runtime emulates even if there is no such thing on Windows).
Since https://github.com/gwsw/less/commit/bb0ee4e76c2, less
prefers the COLUMNS
variable over asking ncurses itself.
But git.exe
itself is not aware of the MSYS2 runtime, or for that matter of that pseudo terminal, and has no way to call ioctl()
or TIOCGWINSZ
.
Therefore, git.exe
will fall back to hard-coding 80 columns, no matter what the actual terminal size is.
But less.exe
is totally able to interact with the MSYS2 runtime and would not actually require Git's help (which actually makes things worse here).
So let's not override COLUMNS
on Windows.
Let's just not set COLUMNS
unless we managed to query the actual value from the terminal.
This fixes git-for-windows/git
issue 3235