Skip to content

Commit e22bb14

Browse files
committed
Merge branch 'mm/maint-config-explicit-bool-display'
* mm/maint-config-explicit-bool-display: config: display key_delim for config --bool --get-regexp
2 parents 3f7d11c + 008e3cc commit e22bb14

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

builtin/config.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
9999
const char *vptr = value;
100100
int must_free_vptr = 0;
101101
int dup_error = 0;
102+
int must_print_delim = 0;
102103

103104
if (!use_key_regexp && strcmp(key_, key))
104105
return 0;
@@ -109,10 +110,8 @@ static int show_config(const char *key_, const char *value_, void *cb)
109110
return 0;
110111

111112
if (show_keys) {
112-
if (value_)
113-
printf("%s%c", key_, key_delim);
114-
else
115-
printf("%s", key_);
113+
printf("%s", key_);
114+
must_print_delim = 1;
116115
}
117116
if (seen && !do_all)
118117
dup_error = 1;
@@ -130,16 +129,23 @@ static int show_config(const char *key_, const char *value_, void *cb)
130129
} else if (types == TYPE_PATH) {
131130
git_config_pathname(&vptr, key_, value_);
132131
must_free_vptr = 1;
132+
} else if (value_) {
133+
vptr = value_;
134+
} else {
135+
/* Just show the key name */
136+
vptr = "";
137+
must_print_delim = 0;
133138
}
134-
else
135-
vptr = value_?value_:"";
136139
seen++;
137140
if (dup_error) {
138141
error("More than one value for the key %s: %s",
139142
key_, vptr);
140143
}
141-
else
144+
else {
145+
if (must_print_delim)
146+
printf("%c", key_delim);
142147
printf("%s%c", vptr, term);
148+
}
143149
if (must_free_vptr)
144150
/* If vptr must be freed, it's a pointer to a
145151
* dynamically allocated buffer, it's safe to cast to

t/t1300-repo-config.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ test_expect_success 'get-regexp variable with no value' \
333333
'git config --get-regexp novalue > output &&
334334
cmp output expect'
335335

336+
echo 'novalue.variable true' > expect
337+
338+
test_expect_success 'get-regexp --bool variable with no value' \
339+
'git config --bool --get-regexp novalue > output &&
340+
cmp output expect'
341+
336342
echo 'emptyvalue.variable ' > expect
337343

338344
test_expect_success 'get-regexp variable with empty value' \

0 commit comments

Comments
 (0)