Skip to content

Commit 75901df

Browse files
committed
Merge branch 'ma/config-page-only-in-list-mode'
In a way similar to how "git tag" learned to honor the pager setting only in the list mode, "git config" learned to ignore the pager setting when it is used for setting values (i.e. when the purpose of the operation is not to "show"). * ma/config-page-only-in-list-mode: config: change default of `pager.config` to "on" config: respect `pager.config` in list/get-mode only t7006: add tests for how git config paginates
2 parents 0afbf6c + c0e9f5b commit 75901df

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

Documentation/git-config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ 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+
The default is to use a pager.
241+
236242
[[FILES]]
237243
FILES
238244
-----

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", 1);
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: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ test_expect_success TTY 'configuration can disable pager' '
110110
! test -e paginated.out
111111
'
112112

113-
test_expect_success TTY 'git config uses a pager if configured to' '
114-
rm -f paginated.out &&
115-
test_config pager.config true &&
116-
test_terminal git config --list &&
117-
test -e paginated.out
118-
'
119-
120113
test_expect_success TTY 'configuration can enable pager (from subdir)' '
121114
rm -f paginated.out &&
122115
mkdir -p subdir &&
@@ -252,6 +245,48 @@ test_expect_success TTY 'git branch --set-upstream-to ignores pager.branch' '
252245
! test -e paginated.out
253246
'
254247

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
252+
'
253+
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
258+
EOF
259+
EDITOR=./editor test_terminal git -c pager.config config --edit &&
260+
! test -e paginated.out &&
261+
test -e editor.used
262+
'
263+
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
268+
'
269+
270+
test_expect_success TTY 'git config --get-urlmatch defaults to paging' '
271+
rm -f paginated.out &&
272+
test_terminal git -c http."https://foo.com/".bar=foo \
273+
config --get-urlmatch http https://foo.com &&
274+
test -e paginated.out
275+
'
276+
277+
test_expect_success TTY 'git config --get-all respects pager.config' '
278+
rm -f paginated.out &&
279+
test_terminal git -c pager.config=false config --get-all foo.bar &&
280+
! test -e paginated.out
281+
'
282+
283+
test_expect_success TTY 'git config --list defaults to paging' '
284+
rm -f paginated.out &&
285+
test_terminal git config --list &&
286+
test -e paginated.out
287+
'
288+
289+
255290
# A colored commit log will begin with an appropriate ANSI escape
256291
# for the first color; the text "commit" comes later.
257292
colorful() {

0 commit comments

Comments
 (0)