builtin/config: introduce "get" subcommand

Introduce a new "get" subcommand to git-config(1). Please refer to preceding commits regarding the motivation behind this change. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed May 6, 2024 at 10:56 UTC 4e513890008406234beba49c5dc8f23e557490cc
3 files changed +194 -99
Documentation/git-config.txt
+45 -48
@@ -10,18 +10,14 @@ SYNOPSIS
10 --------
11 [verse]
12 'git config list' [<file-option>] [<display-option>] [--includes]
13 +'git config get' [<file-option>] [<display-option>] [--includes] [--all] [--regexp=<regexp>] [--value=<value>] [--fixed-value] [--default=<default>] <name>
14 'git config' [<file-option>] [--type=<type>] [--comment=<message>] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] <name> [<value> [<value-pattern>]]
15 'git config' [<file-option>] [--type=<type>] [--comment=<message>] --add <name> <value>
16 'git config' [<file-option>] [--type=<type>] [--comment=<message>] [--fixed-value] --replace-all <name> <value> [<value-pattern>]
16 -'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get <name> [<value-pattern>]
17 -'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get-all <name> [<value-pattern>]
18 -'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] --get-regexp <name-regex> [<value-pattern>]
19 -'git config' [<file-option>] [--type=<type>] [-z|--null] --get-urlmatch <name> <URL>
17 'git config' [<file-option>] [--fixed-value] --unset <name> [<value-pattern>]
18 'git config' [<file-option>] [--fixed-value] --unset-all <name> [<value-pattern>]
19 'git config' [<file-option>] --rename-section <old-name> <new-name>
20 'git config' [<file-option>] --remove-section <name>
24 -'git config' [<file-option>] --get-color <name> [<default>]
21 'git config' [<file-option>] --get-colorbool <name> [<stdout-is-tty>]
22 'git config' [<file-option>] -e | --edit
23
@@ -80,6 +76,12 @@ COMMANDS
76 list::
77 List all variables set in config file, along with their values.
78
79 +get::
80 + Emits the value of the specified key. If key is present multiple times
81 + in the configuration, emits the last value. If `--all` is specified,
82 + emits all values associated with key. Returns error code 1 if key is
83 + not present.
84 +
85 [[OPTIONS]]
86 OPTIONS
87 -------
@@ -105,22 +107,16 @@ OPTIONS
107 not contain linefeed characters (no multi-line comments are
108 permitted).
109
108 ---get::
109 - Get the value for a given key (optionally filtered by a regex
110 - matching the value). Returns error code 1 if the key was not
111 - found and the last value if multiple key values were found.
112 -
113 ---get-all::
114 - Like get, but returns all values for a multi-valued key.
110 +--all::
111 + With `get`, return all values for a multi-valued key.
112
116 ---get-regexp::
117 - Like --get-all, but interprets the name as a regular expression and
118 - writes out the key names. Regular expression matching is currently
119 - case-sensitive and done against a canonicalized version of the key
120 - in which section and variable names are lowercased, but subsection
121 - names are not.
113 +---regexp::
114 + With `get`, interpret the name as a regular expression. Regular
115 + expression matching is currently case-sensitive and done against a
116 + canonicalized version of the key in which section and variable names
117 + are lowercased, but subsection names are not.
118
123 ---get-urlmatch <name> <URL>::
119 +--url=<URL>::
120 When given a two-part <name> as <section>.<key>, the value for
121 <section>.<URL>.<key> whose <URL> part matches the best to the
122 given URL is returned (if no such key exists, the value for
@@ -251,7 +247,7 @@ Valid `<type>`'s include:
247
248 --name-only::
249 Output only the names of config variables for `list` or
254 - `--get-regexp`.
250 + `get`.
251
252 --show-origin::
253 Augment the output of all queried config options with the
@@ -275,17 +271,6 @@ Valid `<type>`'s include:
271 When the color setting for `name` is undefined, the command uses
272 `color.ui` as fallback.
273
278 ---get-color <name> [<default>]::
279 -
280 - Find the color configured for `name` (e.g. `color.diff.new`) and
281 - output it as the ANSI color escape sequence to the standard
282 - output. The optional `default` parameter is used instead, if
283 - there is no color configured for `name`.
284 -+
285 -`--type=color [--default=<default>]` is preferred over `--get-color`
286 -(but note that `--get-color` will omit the trailing newline printed by
287 -`--type=color`).
288 -
274 -e::
275 --edit::
276 Opens an editor to modify the specified config file; either
@@ -299,7 +284,7 @@ Valid `<type>`'s include:
284 config files.
285
286 --default <value>::
302 - When using `--get`, and the requested variable is not found, behave as if
287 + When using `get`, and the requested variable is not found, behave as if
288 <value> were the value assigned to that variable.
289
290 DEPRECATED MODES
@@ -308,15 +293,33 @@ DEPRECATED MODES
293 The following modes have been deprecated in favor of subcommands. It is
294 recommended to migrate to the new syntax.
295
296 +'git config <name>'::
297 + Replaced by `git config get <name>`.
298 +
299 -l::
300 --list::
301 Replaced by `git config list`.
302
303 +--get <name> [<value-pattern>]::
304 + Replaced by `git config get [--value=<pattern>] <name>`.
305 +
306 +--get-all <name> [<value-pattern>]::
307 + Replaced by `git config get [--value=<pattern>] --all --show-names <name>`.
308 +
309 +--get-regexp <name-regexp>::
310 + Replaced by `git config get --all --show-names --regexp <name-regexp>`.
311 +
312 +--get-urlmatch <name> <URL>::
313 + Replaced by `git config get --all --show-names --url=<URL> <name>`.
314 +
315 +--get-color <name> [<default>]::
316 + Replaced by `git config get --type=color [--default=<default>] <name>`.
317 +
318 CONFIGURATION
319 -------------
320 `pager.config` is only respected when listing configuration, i.e., when
318 -using `list` or any of the `--get-*` which may return multiple results.
319 -The default is to use a pager.
321 +using `list` or `get` which may return multiple results. The default is to use
322 +a pager.
323
324 [[FILES]]
325 FILES
@@ -519,25 +522,19 @@ you have to provide a regex matching the value of exactly one line.
522 To query the value for a given key, do
523
524 ------------
522 -% git config --get core.filemode
523 -------------
524 -
525 -or
526 -
527 -------------
528 -% git config core.filemode
525 +% git config get core.filemode
526 ------------
527
528 or, to query a multivar:
529
530 ------------
534 -% git config --get core.gitproxy "for kernel.org$"
531 +% git config get --value="for kernel.org$" core.gitproxy
532 ------------
533
534 If you want to know all the values for a multivar, do:
535
536 ------------
540 -% git config --get-all core.gitproxy
537 +% git config get --all --show-names core.gitproxy
538 ------------
539
540 If you like to live dangerously, you can replace *all* core.gitproxy by a
@@ -571,8 +568,8 @@ script:
568
569 ------------
570 #!/bin/sh
574 -WS=$(git config --get-color color.diff.whitespace "blue reverse")
575 -RESET=$(git config --get-color "" "reset")
571 +WS=$(git config get --type=color --default="blue reverse" color.diff.whitespace)
572 +RESET=$(git config get --type=color --default="reset" "")
573 echo "${WS}your whitespace color or blue reverse${RESET}"
574 ------------
575
@@ -580,11 +577,11 @@ For URLs in `https://weak.example.com`, `http.sslVerify` is set to
577 false, while it is set to `true` for all others:
578
579 ------------
583 -% git config --type=bool --get-urlmatch http.sslverify https://good.example.com
580 +% git config get --type=bool --url=https://good.example.com http.sslverify
581 true
585 -% git config --type=bool --get-urlmatch http.sslverify https://weak.example.com
582 +% git config get --type=bool --url=https://weak.example.com http.sslverify
583 false
587 -% git config --get-urlmatch http https://weak.example.com
584 +% git config get --url=https://weak.example.com http
585 http.cookieFile /tmp/cookie.txt
586 http.sslverify false
587 ------------
builtin/config.c
+60 -9
@@ -17,7 +17,7 @@
17
18 static const char *const builtin_config_usage[] = {
19 N_("git config list [<file-option>] [<display-option>] [--includes]"),
20 - N_("git config [<options>]"),
20 + N_("git config get [<file-option>] [<display-option>] [--includes] [--all] [--regexp=<regexp>] [--value=<value>] [--fixed-value] [--default=<default>] <name>"),
21 NULL
22 };
23
@@ -26,6 +26,11 @@ static const char *const builtin_config_list_usage[] = {
26 NULL
27 };
28
29 +static const char *const builtin_config_get_usage[] = {
30 + N_("git config get [<file-option>] [<display-option>] [--includes] [--all] [--regexp=<regexp>] [--value=<value>] [--fixed-value] [--default=<default>] <name>"),
31 + NULL
32 +};
33 +
34 static char *key;
35 static regex_t *key_regexp;
36 static const char *value_pattern;
@@ -722,6 +727,16 @@ static void handle_nul(void) {
727 OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), \
728 OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object"))
729
730 +#define CONFIG_TYPE_OPTIONS \
731 + OPT_GROUP(N_("Type")), \
732 + OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), \
733 + OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), \
734 + OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), \
735 + OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), \
736 + OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), \
737 + OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), \
738 + OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE)
739 +
740 #define CONFIG_DISPLAY_OPTIONS \
741 OPT_GROUP(N_("Display options")), \
742 OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), \
@@ -746,14 +761,7 @@ static struct option builtin_config_options[] = {
761 OPT_CMDMODE('e', "edit", &actions, N_("open an editor"), ACTION_EDIT),
762 OPT_CMDMODE(0, "get-color", &actions, N_("find the color configured: slot [<default>]"), ACTION_GET_COLOR),
763 OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot [<stdout-is-tty>]"), ACTION_GET_COLORBOOL),
749 - OPT_GROUP(N_("Type")),
750 - OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type),
751 - OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL),
752 - OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT),
753 - OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT),
754 - OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR),
755 - OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH),
756 - OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE),
764 + CONFIG_TYPE_OPTIONS,
765 CONFIG_DISPLAY_OPTIONS,
766 OPT_GROUP(N_("Other")),
767 OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")),
@@ -799,8 +807,51 @@ static int cmd_config_list(int argc, const char **argv, const char *prefix)
807 return 0;
808 }
809
810 +static int cmd_config_get(int argc, const char **argv, const char *prefix)
811 +{
812 + const char *value_pattern = NULL, *url = NULL;
813 + int flags = 0;
814 + struct option opts[] = {
815 + CONFIG_LOCATION_OPTIONS,
816 + CONFIG_TYPE_OPTIONS,
817 + OPT_GROUP(N_("Filter options")),
818 + OPT_BOOL(0, "all", &do_all, N_("return all values for multi-valued config options")),
819 + OPT_BOOL(0, "regexp", &use_key_regexp, N_("interpret the name as a regular expression")),
820 + OPT_STRING(0, "value", &value_pattern, N_("pattern"), N_("show config with values matching the pattern")),
821 + OPT_BIT(0, "fixed-value", &flags, N_("use string equality when comparing values to value pattern"), CONFIG_FLAGS_FIXED_VALUE),
822 + OPT_STRING(0, "url", &url, N_("URL"), N_("show config matching the given URL")),
823 + CONFIG_DISPLAY_OPTIONS,
824 + OPT_BOOL(0, "show-names", &show_keys, N_("show config keys in addition to their values")),
825 + OPT_GROUP(N_("Other")),
826 + OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
827 + OPT_STRING(0, "default", &default_value, N_("value"), N_("use default value when missing entry")),
828 + OPT_END(),
829 + };
830 +
831 + argc = parse_options(argc, argv, prefix, opts, builtin_config_get_usage,
832 + PARSE_OPT_STOP_AT_NON_OPTION);
833 + check_argc(argc, 1, 1);
834 +
835 + if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern)
836 + die(_("--fixed-value only applies with 'value-pattern'"));
837 + if (default_value && (do_all || url))
838 + die(_("--default= cannot be used with --all or --url="));
839 + if (url && (do_all || use_key_regexp || value_pattern))
840 + die(_("--url= cannot be used with --all, --regexp or --value"));
841 +
842 + handle_config_location(prefix);
843 + handle_nul();
844 +
845 + setup_auto_pager("config", 1);
846 +
847 + if (url)
848 + return get_urlmatch(argv[0], url);
849 + return get_value(argv[0], value_pattern, flags);
850 +}
851 +
852 static struct option builtin_subcommand_options[] = {
853 OPT_SUBCOMMAND("list", &subcommand, cmd_config_list),
854 + OPT_SUBCOMMAND("get", &subcommand, cmd_config_get),
855 OPT_END(),
856 };
857
t/t1300-config.sh
+89 -42
@@ -17,9 +17,15 @@ do
17 case "$mode" in
18 legacy)
19 mode_prefix="--"
20 + mode_get=""
21 + mode_get_all="--get-all"
22 + mode_get_regexp="--get-regexp"
23 ;;
24 subcommands)
25 mode_prefix=""
26 + mode_get="get"
27 + mode_get_all="get --all"
28 + mode_get_regexp="get --regexp --all --show-names"
29 ;;
30 *)
31 BUG "unknown mode $mode";;
@@ -398,7 +404,7 @@ test_expect_success 'multi-valued get-all returns all' '
404 wow
405 wow2 for me
406 EOF
401 - git config --get-all nextsection.nonewline >actual &&
407 + git config ${mode_get_all} nextsection.nonewline >actual &&
408 test_cmp expect actual
409 '
410
@@ -500,7 +506,7 @@ nextsection.nonewline wow2 for me
506 EOF
507
508 test_expect_success '--get-regexp' '
503 - git config --get-regexp in >output &&
509 + git config ${mode_get_regexp} in >output &&
510 test_cmp expect output
511 '
512
@@ -510,7 +516,7 @@ nextsection.nonewline
516 EOF
517
518 test_expect_success '--name-only --get-regexp' '
513 - git config --name-only --get-regexp in >output &&
519 + git config ${mode_get_regexp} --name-only in >output &&
520 test_cmp expect output
521 '
522
@@ -521,7 +527,7 @@ EOF
527
528 test_expect_success '--add' '
529 git config --add nextsection.nonewline "wow4 for you" &&
524 - git config --get-all nextsection.nonewline > output &&
530 + git config ${mode_get_all} nextsection.nonewline > output &&
531 test_cmp expect output
532 '
533
@@ -543,21 +549,21 @@ test_expect_success 'get variable with empty value' '
549 echo novalue.variable > expect
550
551 test_expect_success 'get-regexp variable with no value' '
546 - git config --get-regexp novalue > output &&
552 + git config ${mode_get_regexp} novalue > output &&
553 test_cmp expect output
554 '
555
556 echo 'novalue.variable true' > expect
557
558 test_expect_success 'get-regexp --bool variable with no value' '
553 - git config --bool --get-regexp novalue > output &&
559 + git config ${mode_get_regexp} --bool novalue > output &&
560 test_cmp expect output
561 '
562
563 echo 'emptyvalue.variable ' > expect
564
565 test_expect_success 'get-regexp variable with empty value' '
560 - git config --get-regexp emptyvalue > output &&
566 + git config ${mode_get_regexp} emptyvalue > output &&
567 test_cmp expect output
568 '
569
@@ -1131,7 +1137,7 @@ test_expect_success 'quoting' '
1137 '
1138
1139 test_expect_success 'key with newline' '
1134 - test_must_fail git config "key.with
1140 + test_must_fail git config ${mode_get} "key.with
1141 newline" 123'
1142
1143 test_expect_success 'value with newline' 'git config key.sub value.with\\\
@@ -1185,7 +1191,7 @@ test_expect_success '--null --list' '
1191 '
1192
1193 test_expect_success '--null --get-regexp' '
1188 - git config --null --get-regexp "val[0-9]" >result.raw &&
1194 + git config ${mode_get_regexp} --null "val[0-9]" >result.raw &&
1195 nul_to_q <result.raw >result &&
1196 echo >>result &&
1197 test_cmp expect result
@@ -1194,21 +1200,21 @@ test_expect_success '--null --get-regexp' '
1200 test_expect_success 'inner whitespace kept verbatim, spaces only' '
1201 echo "foo bar" >expect &&
1202 git config section.val "foo bar" &&
1197 - git config --get section.val >actual &&
1203 + git config ${mode_get} section.val >actual &&
1204 test_cmp expect actual
1205 '
1206
1207 test_expect_success 'inner whitespace kept verbatim, horizontal tabs only' '
1208 echo "fooQQbar" | q_to_tab >expect &&
1209 git config section.val "$(cat expect)" &&
1204 - git config --get section.val >actual &&
1210 + git config ${mode_get} section.val >actual &&
1211 test_cmp expect actual
1212 '
1213
1214 test_expect_success 'inner whitespace kept verbatim, horizontal tabs and spaces' '
1215 echo "foo Q bar" | q_to_tab >expect &&
1216 git config section.val "$(cat expect)" &&
1211 - git config --get section.val >actual &&
1217 + git config ${mode_get} section.val >actual &&
1218 test_cmp expect actual
1219 '
1220
@@ -1283,11 +1289,11 @@ test_expect_success 'git -c can represent empty string' '
1289 '
1290
1291 test_expect_success 'key sanity-checking' '
1286 - test_must_fail git config foo=bar &&
1287 - test_must_fail git config foo=.bar &&
1288 - test_must_fail git config foo.ba=r &&
1289 - test_must_fail git config foo.1bar &&
1290 - test_must_fail git config foo."ba
1292 + test_must_fail git config ${mode_get} foo=bar &&
1293 + test_must_fail git config ${mode_get} foo=.bar &&
1294 + test_must_fail git config ${mode_get} foo.ba=r &&
1295 + test_must_fail git config ${mode_get} foo.1bar &&
1296 + test_must_fail git config ${mode_get} foo."ba
1297 z".bar &&
1298 test_must_fail git config . false &&
1299 test_must_fail git config .foo false &&
@@ -1336,7 +1342,7 @@ test_expect_success 'git -c complains about empty key and value' '
1342 '
1343
1344 test_expect_success 'multiple git -c appends config' '
1339 - test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" &&
1345 + test_config alias.x "!git -c x.two=2 config ${mode_get_regexp} ^x\.*" &&
1346 cat >expect <<-\EOF &&
1347 x.one 1
1348 x.two 2
@@ -1502,7 +1508,7 @@ test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
1508 v="${SQ}key.one=foo${SQ}" &&
1509 v="$v ${SQ}key.two=bar${SQ}" &&
1510 v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
1505 - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1511 + GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual &&
1512 cat >expect <<-EOF &&
1513 key.one foo
1514 key.two bar
@@ -1515,7 +1521,7 @@ test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
1521 v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
1522 v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
1523 v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
1518 - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1524 + GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual &&
1525 cat >expect <<-EOF &&
1526 key.one foo
1527 key.two bar
@@ -1529,7 +1535,7 @@ test_expect_success 'old and new-style entries can mix' '
1535 v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
1536 v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
1537 v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
1532 - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1538 + GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual &&
1539 cat >expect <<-EOF &&
1540 key.oldone oldfoo
1541 key.newone newfoo
@@ -1542,7 +1548,7 @@ test_expect_success 'old and new-style entries can mix' '
1548 test_expect_success 'old and new bools with ambiguous subsection' '
1549 v="${SQ}key.with=equals.oldbool${SQ}" &&
1550 v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
1545 - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
1551 + GIT_CONFIG_PARAMETERS=$v git config ${mode_get_regexp} "key.*" >actual &&
1552 cat >expect <<-EOF &&
1553 key.with equals.oldbool
1554 key.with=equals.newbool
@@ -1556,7 +1562,7 @@ test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1562 env.two two
1563 EOF
1564 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \
1559 - git config --get-regexp "env.*" >actual &&
1565 + git config ${mode_get_regexp} "env.*" >actual &&
1566 test_cmp expect actual &&
1567
1568 cat >expect <<-EOF &&
@@ -1564,12 +1570,12 @@ test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
1570 env.two two
1571 EOF
1572 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \
1567 - git config --get-regexp "env.*" >actual &&
1573 + git config ${mode_get_regexp} "env.*" >actual &&
1574 test_cmp expect actual &&
1575
1576 test_must_fail env \
1577 GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \
1572 - git config --get-regexp "env.*"
1578 + git config ${mode_get_regexp} "env.*"
1579 '
1580
1581 test_expect_success 'git --config-env=key=envvar support' '
@@ -1617,7 +1623,7 @@ test_expect_success 'git -c and --config-env work together' '
1623 ENVVAR=env-value git \
1624 -c bar.cmd=cmd-value \
1625 --config-env=bar.env=ENVVAR \
1620 - config --get-regexp "^bar.*" >actual &&
1626 + config ${mode_get_regexp} "^bar.*" >actual &&
1627 test_cmp expect actual
1628 '
1629
@@ -1645,7 +1651,7 @@ test_expect_success 'git config handles environment config pairs' '
1651 GIT_CONFIG_COUNT=2 \
1652 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
1653 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
1648 - git config --get-regexp "pair.*" >actual &&
1654 + git config ${mode_get_regexp} "pair.*" >actual &&
1655 cat >expect <<-EOF &&
1656 pair.one foo
1657 pair.two bar
@@ -1655,7 +1661,7 @@ test_expect_success 'git config handles environment config pairs' '
1661
1662 test_expect_success 'git config ignores pairs without count' '
1663 test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1658 - git config pair.one 2>error &&
1664 + git config ${mode_get} pair.one 2>error &&
1665 test_must_be_empty error
1666 '
1667
@@ -1663,7 +1669,7 @@ test_expect_success 'git config ignores pairs exceeding count' '
1669 GIT_CONFIG_COUNT=1 \
1670 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1671 GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
1666 - git config --get-regexp "pair.*" >actual 2>error &&
1672 + git config ${mode_get_regexp} "pair.*" >actual 2>error &&
1673 cat >expect <<-EOF &&
1674 pair.one value
1675 EOF
@@ -1674,14 +1680,14 @@ test_expect_success 'git config ignores pairs exceeding count' '
1680 test_expect_success 'git config ignores pairs with zero count' '
1681 test_must_fail env \
1682 GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1677 - git config pair.one 2>error &&
1683 + git config ${mode_get} pair.one 2>error &&
1684 test_must_be_empty error
1685 '
1686
1687 test_expect_success 'git config ignores pairs with empty count' '
1688 test_must_fail env \
1689 GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
1684 - git config pair.one 2>error &&
1690 + git config ${mode_get} pair.one 2>error &&
1691 test_must_be_empty error
1692 '
1693
@@ -1720,7 +1726,7 @@ test_expect_success 'environment overrides config file' '
1726 one = value
1727 EOF
1728 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
1723 - git config pair.one >actual &&
1729 + git config ${mode_get} pair.one >actual &&
1730 cat >expect <<-EOF &&
1731 override
1732 EOF
@@ -1730,7 +1736,7 @@ test_expect_success 'environment overrides config file' '
1736 test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
1737 GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
1738 GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
1733 - git config pair.one >actual &&
1739 + git config ${mode_get} pair.one >actual &&
1740 cat >expect <<-EOF &&
1741 override
1742 EOF
@@ -1805,20 +1811,28 @@ test_expect_success 'urlmatch' '
1811
1812 test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1813 test_must_be_empty actual &&
1814 + test_expect_code 1 git config get --url=https://good.example.com --bool doesnt.exist >actual &&
1815 + test_must_be_empty actual &&
1816
1817 echo true >expect &&
1818 git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
1819 test_cmp expect actual &&
1820 + git config get --bool --url=https://good.example.com http.SSLverify >actual &&
1821 + test_cmp expect actual &&
1822
1823 echo false >expect &&
1824 git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual &&
1825 test_cmp expect actual &&
1826 + git config get --bool --url=https://weak.example.com http.sslverify >actual &&
1827 + test_cmp expect actual &&
1828
1829 {
1830 echo http.cookiefile /tmp/cookie.txt &&
1831 echo http.sslverify false
1832 } >expect &&
1833 git config --get-urlmatch HTTP https://weak.example.com >actual &&
1834 + test_cmp expect actual &&
1835 + git config get --url=https://weak.example.com HTTP >actual &&
1836 test_cmp expect actual
1837 '
1838
@@ -1834,6 +1848,8 @@ test_expect_success 'urlmatch with --show-scope' '
1848 local http.sslverify false
1849 EOF
1850 git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual &&
1851 + test_cmp expect actual &&
1852 + git config get --url=https://weak.example.com --show-scope HTTP >actual &&
1853 test_cmp expect actual
1854 '
1855
@@ -1866,45 +1882,67 @@ test_expect_success 'urlmatch favors more specific URLs' '
1882 echo http.cookiefile /tmp/root.txt >expect &&
1883 git config --get-urlmatch HTTP https://example.com >actual &&
1884 test_cmp expect actual &&
1885 + git config get --url=https://example.com HTTP >actual &&
1886 + test_cmp expect actual &&
1887
1888 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1889 git config --get-urlmatch HTTP https://example.com/subdirectory >actual &&
1890 test_cmp expect actual &&
1891 + git config get --url=https://example.com/subdirectory HTTP >actual &&
1892 + test_cmp expect actual &&
1893
1894 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1895 git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual &&
1896 test_cmp expect actual &&
1897 + git config get --url=https://example.com/subdirectory/nested HTTP >actual &&
1898 + test_cmp expect actual &&
1899
1900 echo http.cookiefile /tmp/user.txt >expect &&
1901 git config --get-urlmatch HTTP https://user@example.com/ >actual &&
1902 test_cmp expect actual &&
1903 + git config get --url=https://user@example.com/ HTTP >actual &&
1904 + test_cmp expect actual &&
1905
1906 echo http.cookiefile /tmp/subdirectory.txt >expect &&
1907 git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual &&
1908 test_cmp expect actual &&
1909 + git config get --url=https://averylonguser@example.com/subdirectory HTTP >actual &&
1910 + test_cmp expect actual &&
1911
1912 echo http.cookiefile /tmp/preceding.txt >expect &&
1913 git config --get-urlmatch HTTP https://preceding.example.com >actual &&
1914 test_cmp expect actual &&
1915 + git config get --url=https://preceding.example.com HTTP >actual &&
1916 + test_cmp expect actual &&
1917
1918 echo http.cookiefile /tmp/wildcard.txt >expect &&
1919 git config --get-urlmatch HTTP https://wildcard.example.com >actual &&
1920 test_cmp expect actual &&
1921 + git config get --url=https://wildcard.example.com HTTP >actual &&
1922 + test_cmp expect actual &&
1923
1924 echo http.cookiefile /tmp/sub.txt >expect &&
1925 git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual &&
1926 test_cmp expect actual &&
1927 + git config get --url=https://sub.example.com/wildcardwithsubdomain HTTP >actual &&
1928 + test_cmp expect actual &&
1929
1930 echo http.cookiefile /tmp/trailing.txt >expect &&
1931 git config --get-urlmatch HTTP https://trailing.example.com >actual &&
1932 test_cmp expect actual &&
1933 + git config get --url=https://trailing.example.com HTTP >actual &&
1934 + test_cmp expect actual &&
1935
1936 echo http.cookiefile /tmp/sub.txt >expect &&
1937 git config --get-urlmatch HTTP https://user@sub.example.com >actual &&
1938 test_cmp expect actual &&
1939 + git config get --url=https://user@sub.example.com HTTP >actual &&
1940 + test_cmp expect actual &&
1941
1942 echo http.cookiefile /tmp/multiwildcard.txt >expect &&
1943 git config --get-urlmatch HTTP https://wildcard.example.org >actual &&
1944 + test_cmp expect actual &&
1945 + git config get --url=https://wildcard.example.org HTTP >actual &&
1946 test_cmp expect actual
1947 '
1948
@@ -2027,7 +2065,7 @@ test_expect_success '--unset last key removes section (except if commented)' '
2065 [one]
2066 EOF
2067 git config --unset two.subsection.key &&
2030 - test "not [two subsection]" = "$(git config one.key)" &&
2068 + test "not [two subsection]" = "$(git config ${mode_get} one.key)" &&
2069 test_line_count = 3 .git/config
2070 '
2071
@@ -2150,7 +2188,7 @@ test_expect_success '--show-origin with --get-regexp' '
2188 file:$HOME/.gitconfig user.global true
2189 file:.git/config user.local true
2190 EOF
2153 - git config --show-origin --get-regexp "user\.[g|l].*" >output &&
2191 + git config ${mode_get_regexp} --show-origin "user\.[g|l].*" >output &&
2192 test_cmp expect output
2193 '
2194
@@ -2158,7 +2196,7 @@ test_expect_success '--show-origin getting a single key' '
2196 cat >expect <<-\EOF &&
2197 file:.git/config local
2198 EOF
2161 - git config --show-origin user.override >output &&
2199 + git config ${mode_get} --show-origin user.override >output &&
2200 test_cmp expect output
2201 '
2202
@@ -2290,7 +2328,7 @@ test_expect_success '--show-scope getting a single value' '
2328 cat >expect <<-\EOF &&
2329 local true
2330 EOF
2293 - git config --show-scope --get user.local >output &&
2331 + git config ${mode_get} --show-scope user.local >output &&
2332 test_cmp expect output
2333 '
2334
@@ -2559,9 +2597,9 @@ test_expect_success 'refuse --fixed-value for incompatible actions' '
2597 # These modes complain when --fixed-value has no value-pattern
2598 test_must_fail git config --file=config --fixed-value dev.null bogus &&
2599 test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
2562 - test_must_fail git config --file=config --fixed-value --get dev.null &&
2563 - test_must_fail git config --file=config --fixed-value --get-all dev.null &&
2564 - test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
2600 + test_must_fail git config ${mode_prefix}get --file=config --fixed-value dev.null &&
2601 + test_must_fail git config ${mode_get_all} --file=config --fixed-value dev.null &&
2602 + test_must_fail git config ${mode_get_regexp} --file=config --fixed-value "dev.*" &&
2603 test_must_fail git config --file=config --fixed-value --unset dev.null &&
2604 test_must_fail git config --file=config --fixed-value --unset-all dev.null
2605 '
@@ -2591,12 +2629,12 @@ test_expect_success '--fixed-value uses exact string matching' '
2629 cp initial config &&
2630 test_must_fail git config --file=config --unset fixed.test "$META" &&
2631 git config --file=config --fixed-value --unset fixed.test "$META" &&
2594 - test_must_fail git config --file=config fixed.test &&
2632 + test_must_fail git config ${mode_get} --file=config fixed.test &&
2633
2634 cp initial config &&
2635 test_must_fail git config --file=config --unset-all fixed.test "$META" &&
2636 git config --file=config --fixed-value --unset-all fixed.test "$META" &&
2599 - test_must_fail git config --file=config fixed.test &&
2637 + test_must_fail git config ${mode_get} --file=config fixed.test &&
2638
2639 cp initial config &&
2640 git config --file=config --replace-all fixed.test bogus "$META" &&
@@ -2623,18 +2661,27 @@ test_expect_success '--get and --get-all with --fixed-value' '
2661 git config --file=config --add fixed.test "$META" &&
2662
2663 git config --file=config --get fixed.test bogus &&
2664 + git config get --file=config --value=bogus fixed.test &&
2665 test_must_fail git config --file=config --get fixed.test "$META" &&
2666 + test_must_fail git config get --file=config --value="$META" fixed.test &&
2667 git config --file=config --get --fixed-value fixed.test "$META" &&
2668 + git config get --file=config --fixed-value --value="$META" fixed.test &&
2669 test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
2670
2671 git config --file=config --get-all fixed.test bogus &&
2672 + git config get --all --file=config --value=bogus fixed.test &&
2673 test_must_fail git config --file=config --get-all fixed.test "$META" &&
2674 + test_must_fail git config get --all --file=config --value="$META" fixed.test &&
2675 git config --file=config --get-all --fixed-value fixed.test "$META" &&
2676 + git config get --all --file=config --value="$META" --fixed-value fixed.test &&
2677 test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
2678
2679 git config --file=config --get-regexp fixed+ bogus &&
2680 + git config get --regexp --file=config --value=bogus fixed+ &&
2681 test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
2682 + test_must_fail git config get --regexp --file=config --value="$META" fixed+ &&
2683 git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
2684 + git config get --regexp --file=config --fixed-value --value="$META" fixed+ &&
2685 test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
2686 '
2687