Skip to content

Commit 0759dfd

Browse files
committed
Merge branch 'jk/config-get-urlmatch' into maint
"git config --get-urlmatch", unlike other variants of the "git config --get" family, did not signal error with its exit status when there was no matching configuration. * jk/config-get-urlmatch: Documentation/git-config: fix --get-all description Documentation/git-config: use bulleted list for exit codes config: fail if --get-urlmatch finds no value
2 parents f1cfacf + 24990b2 commit 0759dfd

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

Documentation/git-config.txt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ that location (you can say '--local' but that is the default).
5858
This command will fail with non-zero status upon error. Some exit
5959
codes are:
6060

61-
. The config file is invalid (ret=3),
62-
. can not write to the config file (ret=4),
63-
. no section or name was provided (ret=2),
64-
. the section or key is invalid (ret=1),
65-
. you try to unset an option which does not exist (ret=5),
66-
. you try to unset/set an option for which multiple lines match (ret=5), or
67-
. you try to use an invalid regexp (ret=6).
61+
- The config file is invalid (ret=3),
62+
- can not write to the config file (ret=4),
63+
- no section or name was provided (ret=2),
64+
- the section or key is invalid (ret=1),
65+
- you try to unset an option which does not exist (ret=5),
66+
- you try to unset/set an option for which multiple lines match (ret=5), or
67+
- you try to use an invalid regexp (ret=6).
6868

6969
On success, the command returns the exit code 0.
7070

@@ -86,8 +86,7 @@ OPTIONS
8686
found and the last value if multiple key values were found.
8787

8888
--get-all::
89-
Like get, but does not fail if the number of values for the key
90-
is not exactly one.
89+
Like get, but returns all values for a multi-valued key.
9190

9291
--get-regexp::
9392
Like --get-all, but interprets the name as a regular expression and
@@ -102,7 +101,7 @@ OPTIONS
102101
given URL is returned (if no such key exists, the value for
103102
section.key is used as a fallback). When given just the
104103
section as name, do so for all the keys in the section and
105-
list them.
104+
list them. Returns error code 1 if no value is found.
106105

107106
--global::
108107
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
@@ -417,6 +417,7 @@ static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
417417

418418
static int get_urlmatch(const char *var, const char *url)
419419
{
420+
int ret;
420421
char *section_tail;
421422
struct string_list_item *item;
422423
struct urlmatch_config config = { STRING_LIST_INIT_DUP };
@@ -443,6 +444,8 @@ static int get_urlmatch(const char *var, const char *url)
443444
git_config_with_options(urlmatch_config_entry, &config,
444445
&given_config_source, respect_includes);
445446

447+
ret = !values.nr;
448+
446449
for_each_string_list_item(item, &values) {
447450
struct urlmatch_current_candidate_value *matched = item->util;
448451
struct strbuf buf = STRBUF_INIT;
@@ -459,7 +462,7 @@ static int get_urlmatch(const char *var, const char *url)
459462
free(config.url.url);
460463

461464
free((void *)config.section);
462-
return 0;
465+
return ret;
463466
}
464467

465468
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
@@ -1144,6 +1144,9 @@ test_expect_success 'urlmatch' '
11441144
cookieFile = /tmp/cookie.txt
11451145
EOF
11461146
1147+
test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
1148+
test_must_be_empty actual &&
1149+
11471150
echo true >expect &&
11481151
git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
11491152
test_cmp expect actual &&

0 commit comments

Comments
 (0)