Skip to content

Commit 27b30be

Browse files
johnkeepinggitster
authored andcommitted
config: fail if --get-urlmatch finds no value
The --get, --get-all and --get-regexp options to git-config exit with status 1 if the key is not found but --get-urlmatch succeeds in this case. Change --get-urlmatch to behave in the same way as the other --get* options so that all four are consistent. --get-color is a special case because it accepts a default value to return and so should not return an error if the key is not found. Also clarify this behaviour in the documentation. Signed-off-by: John Keeping <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 326e5bc commit 27b30be

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Documentation/git-config.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ OPTIONS
102102
given URL is returned (if no such key exists, the value for
103103
section.key is used as a fallback). When given just the
104104
section as name, do so for all the keys in the section and
105-
list them.
105+
list them. Returns error code 1 if no value is found.
106106

107107
--global::
108108
For writing options: write to global `~/.gitconfig` file

builtin/config.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
389389

390390
static int get_urlmatch(const char *var, const char *url)
391391
{
392+
int ret;
392393
char *section_tail;
393394
struct string_list_item *item;
394395
struct urlmatch_config config = { STRING_LIST_INIT_DUP };
@@ -415,6 +416,8 @@ static int get_urlmatch(const char *var, const char *url)
415416
git_config_with_options(urlmatch_config_entry, &config,
416417
&given_config_source, respect_includes);
417418

419+
ret = !values.nr;
420+
418421
for_each_string_list_item(item, &values) {
419422
struct urlmatch_current_candidate_value *matched = item->util;
420423
struct strbuf buf = STRBUF_INIT;
@@ -431,7 +434,7 @@ static int get_urlmatch(const char *var, const char *url)
431434
free(config.url.url);
432435

433436
free((void *)config.section);
434-
return 0;
437+
return ret;
435438
}
436439

437440
static char *default_user_config(void)

t/t1300-repo-config.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,9 @@ test_expect_success 'urlmatch' '
11401140
cookieFile = /tmp/cookie.txt
11411141
EOF
11421142
1143+
test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1144+
test_must_be_empty actual &&
1145+
11431146
echo true >expect &&
11441147
git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
11451148
test_cmp expect actual &&

0 commit comments

Comments
 (0)