config: respect `pager.config` in list/get-mode only

Similar to de121ffe5 (tag: respect `pager.tag` in list-mode only, 2017-08-02), use the DELAY_PAGER_CONFIG-mechanism to only respect `pager.config` when we are listing or "get"ing config. We have several getters and some are guaranteed to give at most one line of output. Paging all getters including those could be convenient from a documentation point-of-view. The downside would be that a misconfigured or not so modern pager might wait for user interaction before terminating. Let's instead respect the config for precisely those getters which may produce more than one line of output. `--get-urlmatch` may or may not produce multiple lines of output, depending on the exact usage. Let's not try to recognize the two modes, but instead make `--get-urlmatch` always respect the config. Analyzing the detailed usage might be trivial enough here, but could establish a precedent that we will never be able to enforce throughout the codebase and that will just open a can of worms. This fixes the failing test added in the previous commit. Also adapt the test for whether `git config foo.bar bar` and `git config --get foo.bar` respects `pager.config`. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Ågren committed Feb 21, 2018 at 19:51 UTC 32888b8fd56175f52f3139915d931f78d8c4ef89
4 files changed +21 -6
Documentation/git-config.txt
+5
@@ -233,6 +233,11 @@ See also <<FILES>>.
233 using `--file`, `--global`, etc) and `on` when searching all
234 config files.
235
236 +CONFIGURATION
237 +-------------
238 +`pager.config` is only respected when listing configuration, i.e., when
239 +using `--list` or any of the `--get-*` which may return multiple results.
240 +
241 [[FILES]]
242 FILES
243 -----
builtin/config.c
+10
@@ -48,6 +48,13 @@ static int show_origin;
48 #define ACTION_GET_COLORBOOL (1<<14)
49 #define ACTION_GET_URLMATCH (1<<15)
50
51 +/*
52 + * The actions "ACTION_LIST | ACTION_GET_*" which may produce more than
53 + * one line of output and which should therefore be paged.
54 + */
55 +#define PAGING_ACTIONS (ACTION_LIST | ACTION_GET_ALL | \
56 + ACTION_GET_REGEXP | ACTION_GET_URLMATCH)
57 +
58 #define TYPE_BOOL (1<<0)
59 #define TYPE_INT (1<<1)
60 #define TYPE_BOOL_OR_INT (1<<2)
@@ -594,6 +601,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
601 usage_with_options(builtin_config_usage, builtin_config_options);
602 }
603
604 + if (actions & PAGING_ACTIONS)
605 + setup_auto_pager("config", 0);
606 +
607 if (actions == ACTION_LIST) {
608 check_argc(argc, 0, 0);
609 if (config_with_options(show_all_config, NULL,
git.c
+1 -1
@@ -389,7 +389,7 @@ static struct cmd_struct commands[] = {
389 { "column", cmd_column, RUN_SETUP_GENTLY },
390 { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE },
391 { "commit-tree", cmd_commit_tree, RUN_SETUP },
392 - { "config", cmd_config, RUN_SETUP_GENTLY },
392 + { "config", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG },
393 { "count-objects", cmd_count_objects, RUN_SETUP },
394 { "credential", cmd_credential, RUN_SETUP_GENTLY },
395 { "describe", cmd_describe, RUN_SETUP },
t/t7006-pager.sh
+5 -5
@@ -245,13 +245,13 @@ test_expect_success TTY 'git branch --set-upstream-to ignores pager.branch' '
245 ! test -e paginated.out
246 '
247
248 -test_expect_success TTY 'git config respects pager.config when setting' '
248 +test_expect_success TTY 'git config ignores pager.config when setting' '
249 rm -f paginated.out &&
250 test_terminal git -c pager.config config foo.bar bar &&
251 - test -e paginated.out
251 + ! test -e paginated.out
252 '
253
254 -test_expect_failure TTY 'git config --edit ignores pager.config' '
254 +test_expect_success TTY 'git config --edit ignores pager.config' '
255 rm -f paginated.out editor.used &&
256 write_script editor <<-\EOF &&
257 touch editor.used
@@ -261,10 +261,10 @@ test_expect_failure TTY 'git config --edit ignores pager.config' '
261 test -e editor.used
262 '
263
264 -test_expect_success TTY 'git config --get respects pager.config' '
264 +test_expect_success TTY 'git config --get ignores pager.config' '
265 rm -f paginated.out &&
266 test_terminal git -c pager.config config --get foo.bar &&
267 - test -e paginated.out
267 + ! test -e paginated.out
268 '
269
270 test_expect_success TTY 'git config --get-urlmatch defaults to not paging' '