Skip to content

Commit 32888b8

Browse files
Martin Ågrengitster
authored andcommitted
config: respect pager.config in list/get-mode only
Similar to de121ff (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cd878a2 commit 32888b8

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

Documentation/git-config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ See also <<FILES>>.
233233
using `--file`, `--global`, etc) and `on` when searching all
234234
config files.
235235

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+
236241
[[FILES]]
237242
FILES
238243
-----

builtin/config.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ static int show_origin;
4848
#define ACTION_GET_COLORBOOL (1<<14)
4949
#define ACTION_GET_URLMATCH (1<<15)
5050

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+
5158
#define TYPE_BOOL (1<<0)
5259
#define TYPE_INT (1<<1)
5360
#define TYPE_BOOL_OR_INT (1<<2)
@@ -594,6 +601,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
594601
usage_with_options(builtin_config_usage, builtin_config_options);
595602
}
596603

604+
if (actions & PAGING_ACTIONS)
605+
setup_auto_pager("config", 0);
606+
597607
if (actions == ACTION_LIST) {
598608
check_argc(argc, 0, 0);
599609
if (config_with_options(show_all_config, NULL,

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static struct cmd_struct commands[] = {
389389
{ "column", cmd_column, RUN_SETUP_GENTLY },
390390
{ "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE },
391391
{ "commit-tree", cmd_commit_tree, RUN_SETUP },
392-
{ "config", cmd_config, RUN_SETUP_GENTLY },
392+
{ "config", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG },
393393
{ "count-objects", cmd_count_objects, RUN_SETUP },
394394
{ "credential", cmd_credential, RUN_SETUP_GENTLY },
395395
{ "describe", cmd_describe, RUN_SETUP },

t/t7006-pager.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ test_expect_success TTY 'git branch --set-upstream-to ignores pager.branch' '
245245
! test -e paginated.out
246246
'
247247

248-
test_expect_success TTY 'git config respects pager.config when setting' '
248+
test_expect_success TTY 'git config ignores pager.config when setting' '
249249
rm -f paginated.out &&
250250
test_terminal git -c pager.config config foo.bar bar &&
251-
test -e paginated.out
251+
! test -e paginated.out
252252
'
253253

254-
test_expect_failure TTY 'git config --edit ignores pager.config' '
254+
test_expect_success TTY 'git config --edit ignores pager.config' '
255255
rm -f paginated.out editor.used &&
256256
write_script editor <<-\EOF &&
257257
touch editor.used
@@ -261,10 +261,10 @@ test_expect_failure TTY 'git config --edit ignores pager.config' '
261261
test -e editor.used
262262
'
263263

264-
test_expect_success TTY 'git config --get respects pager.config' '
264+
test_expect_success TTY 'git config --get ignores pager.config' '
265265
rm -f paginated.out &&
266266
test_terminal git -c pager.config config --get foo.bar &&
267-
test -e paginated.out
267+
! test -e paginated.out
268268
'
269269

270270
test_expect_success TTY 'git config --get-urlmatch defaults to not paging' '

0 commit comments

Comments
 (0)