Skip to content

Commit b2d3fd2

Browse files
Ikkegitster
authored andcommitted
column: show auto columns when pager is active
When columns are set to automatic for git tag and the output is paginated by git, the output is a single column instead of multiple columns. Standard behaviour in git is to honor auto values when the pager is active, which happens for example with commands like git log showing colors when being paged. Since ff1e724 (tag: change default of `pager.tag` to "on", 2017-08-02), the pager has been enabled by default, exposing this problem to more people. finalize_colopts in column.c only checks whether the output is a TTY to determine if columns should be enabled with columns set to auto. Also check if the pager is active. Adding a test for git column is possible but requires some care to work around a race on stdin. See commit 18d8c26 (test_terminal: redirect child process' stdin to a pty, 2015-08-04). Test git tag instead, since that does not involve stdin, and since that was the original motivation for this patch. Helped-by: Rafael Ascensão <rafa.almas@gmail.com> Signed-off-by: Kevin Daudt <me@ikke.info> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ff1e724 commit b2d3fd2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

column.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "parse-options.h"
66
#include "run-command.h"
77
#include "utf8.h"
8+
#include "pager.c"
89

910
#define XY2LINEAR(d, x, y) (COL_LAYOUT((d)->colopts) == COL_COLUMN ? \
1011
(x) * (d)->rows + (y) : \
@@ -224,7 +225,7 @@ int finalize_colopts(unsigned int *colopts, int stdout_is_tty)
224225
if (stdout_is_tty < 0)
225226
stdout_is_tty = isatty(1);
226227
*colopts &= ~COL_ENABLE_MASK;
227-
if (stdout_is_tty)
228+
if (stdout_is_tty || pager_in_use())
228229
*colopts |= COL_ENABLED;
229230
}
230231
return 0;

t/t7006-pager.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,4 +570,18 @@ test_expect_success 'command with underscores does not complain' '
570570
test_cmp expect actual
571571
'
572572

573+
test_expect_success TTY 'git tag with auto-columns ' '
574+
test_commit one &&
575+
test_commit two &&
576+
test_commit three &&
577+
test_commit four &&
578+
test_commit five &&
579+
cat >expect <<-\EOF &&
580+
initial one two three four five
581+
EOF
582+
test_terminal env PAGER="cat >actual" COLUMNS=80 \
583+
git -c column.ui=auto tag --sort=authordate &&
584+
test_cmp expect actual
585+
'
586+
573587
test_done

0 commit comments

Comments
 (0)