]> git.ipfire.org Git - thirdparty/git.git/commitdiff
column: show auto columns when pager is active
authorKevin Daudt <me@ikke.info>
Mon, 16 Oct 2017 18:35:11 +0000 (20:35 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Oct 2017 03:16:45 +0000 (12:16 +0900)
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 ff1e72483 (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 18d8c2693 (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>
column.c
t/t7006-pager.sh

index ff7bdab1a32478c8719ee3b973742456df7dc629..ded50337f7a52bd237509114c0c330de34f3525a 100644 (file)
--- a/column.c
+++ b/column.c
@@ -5,6 +5,7 @@
 #include "parse-options.h"
 #include "run-command.h"
 #include "utf8.h"
+#include "pager.c"
 
 #define XY2LINEAR(d, x, y) (COL_LAYOUT((d)->colopts) == COL_COLUMN ? \
                            (x) * (d)->rows + (y) : \
@@ -224,7 +225,7 @@ int finalize_colopts(unsigned int *colopts, int stdout_is_tty)
                if (stdout_is_tty < 0)
                        stdout_is_tty = isatty(1);
                *colopts &= ~COL_ENABLE_MASK;
-               if (stdout_is_tty)
+               if (stdout_is_tty || pager_in_use())
                        *colopts |= COL_ENABLED;
        }
        return 0;
index afa03f3b65afd3aea22b967d82a8c4455e7b8808..f630fe0f2bd825fd696a2a40c1d25377cde314e7 100755 (executable)
@@ -570,4 +570,18 @@ test_expect_success 'command with underscores does not complain' '
        test_cmp expect actual
 '
 
+test_expect_success TTY 'git tag with auto-columns ' '
+       test_commit one &&
+       test_commit two &&
+       test_commit three &&
+       test_commit four &&
+       test_commit five &&
+       cat >expect <<-\EOF &&
+       initial  one      two      three    four     five
+       EOF
+       test_terminal env PAGER="cat >actual" COLUMNS=80 \
+               git -c column.ui=auto tag --sort=authordate &&
+       test_cmp expect actual
+'
+
 test_done