Skip to content

Commit 1dc14e8

Browse files
committed
config: make 'git config list --type=<X>' work
Previously, the --type=<X> argument to 'git config list' was ignored and did nothing. Now, we add the use of format_config() to the show_all_config() function so each key-value pair is attempted to be parsed. If there is an error in parsing, then the row is not output. This is a change in behavior! We are starting to respect an option that was previously ignored, leading to potential user confusion. This is probably still a good option, since the --type argument did not change behavior at all previously, so users can get the behavior they expect by removing the --type argument or adding the --no-type argument. Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent 5601a5a commit 1dc14e8

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

builtin/config.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -363,21 +363,12 @@ static int show_all_config(const char *key_, const char *value_,
363363
{
364364
const struct config_display_options *opts = cb;
365365
const struct key_value_info *kvi = ctx->kvi;
366+
struct strbuf formatted = STRBUF_INIT;
366367

367-
if (opts->show_origin || opts->show_scope) {
368-
struct strbuf buf = STRBUF_INIT;
369-
if (opts->show_scope)
370-
show_config_scope(opts, kvi, &buf);
371-
if (opts->show_origin)
372-
show_config_origin(opts, kvi, &buf);
373-
/* Use fwrite as "buf" can contain \0's if "end_null" is set. */
374-
fwrite(buf.buf, 1, buf.len, stdout);
375-
strbuf_release(&buf);
376-
}
377-
if (!opts->omit_values && value_)
378-
printf("%s%c%s%c", key_, opts->delim, value_, opts->term);
379-
else
380-
printf("%s%c", key_, opts->term);
368+
if (format_config(opts, &formatted, key_, value_, kvi, 0) >= 0)
369+
fwrite(formatted.buf, 1, formatted.len, stdout);
370+
371+
strbuf_release(&formatted);
381372
return 0;
382373
}
383374

t/t1300-config.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2459,9 +2459,10 @@ done
24592459

24602460
cat >.git/config <<-\EOF &&
24612461
[section]
2462-
foo = true
2462+
foo = True
24632463
number = 10
24642464
big = 1M
2465+
path = ~/dir
24652466
EOF
24662467

24672468
test_expect_success 'identical modern --type specifiers are allowed' '
@@ -2503,6 +2504,29 @@ test_expect_success 'unset type specifiers may be reset to conflicting ones' '
25032504
test_cmp_config 1048576 --type=bool --no-type --type=int section.big
25042505
'
25052506

2507+
test_expect_success 'list --type=bool shows only canonicalizable bool values' '
2508+
cat >expect <<-EOF &&
2509+
section.foo=true
2510+
section.number=true
2511+
section.big=true
2512+
EOF
2513+
2514+
git config ${mode_prefix}list --type=bool >actual &&
2515+
test_cmp expect actual
2516+
'
2517+
2518+
test_expect_success 'list --type=path shows only canonicalizable path values' '
2519+
cat >expect <<-EOF &&
2520+
section.foo=True
2521+
section.number=10
2522+
section.big=1M
2523+
section.path=$HOME/dir
2524+
EOF
2525+
2526+
git config ${mode_prefix}list --type=path >actual &&
2527+
test_cmp expect actual
2528+
'
2529+
25062530
test_expect_success '--type rejects unknown specifiers' '
25072531
test_must_fail git config --type=nonsense section.foo 2>error &&
25082532
test_grep "unrecognized --type argument" error

0 commit comments

Comments
 (0)