git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] config: fail if --get-urlmatch finds no value

From
John Keeping <john@keeping.me.uk>
Date
Feb 28, 2016, 11:54 UTC
Message-ID
<9ed75bdb80839deaebac642a8abd1da5b6a969d1.1456660027.git.john@keeping.me.uk>
In-Reply-To
<cover.1456660027.git.john@keeping.me.uk>

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 <john@keeping.me.uk>
---
 Documentation/git-config.txt | 2 +-
 builtin/config.c             | 5 ++++-
 t/t1300-repo-config.sh       | 3 +++
 3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index 153b2d8..2a04e87 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -102,7 +102,7 @@ OPTIONS
 	given URL is returned (if no such key exists, the value for
 	section.key is used as a fallback).  When given just the
 	section as name, do so for all the keys in the section and
-	list them.
+	list them.  Returns error code 1 if no value is found.
 
 --global::
 	For writing options: write to global `~/.gitconfig` file
diff --git a/builtin/config.c b/builtin/config.c
index ca9f834..1d7c6ef 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -417,6 +417,7 @@ static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
 
 static int get_urlmatch(const char *var, const char *url)
 {
+	int ret;
 	char *section_tail;
 	struct string_list_item *item;
 	struct urlmatch_config config = { STRING_LIST_INIT_DUP };
@@ -443,6 +444,8 @@ static int get_urlmatch(const char *var, const char *url)
 	git_config_with_options(urlmatch_config_entry, &config,
 				&given_config_source, respect_includes);
 
+	ret = !values.nr;
+
 	for_each_string_list_item(item, &values) {
 		struct urlmatch_current_candidate_value *matched = item->util;
 		struct strbuf buf = STRBUF_INIT;
@@ -459,7 +462,7 @@ static int get_urlmatch(const char *var, const char *url)
 	free(config.url.url);
 
 	free((void *)config.section);
-	return 0;
+	return ret;
 }
 
 static char *default_user_config(void)
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 8867ce1..89d8c47 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -1148,6 +1148,9 @@ test_expect_success 'urlmatch' '
 		cookieFile = /tmp/cookie.txt
 	EOF
 
+	test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
+	test_must_be_empty actual &&
+
 	echo true >expect &&
 	git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual &&
 	test_cmp expect actual &&
-- 
2.7.1.503.g3cfa3ac
Previous: John KeepingNext: John Keeping
Message 5 of 11 in “git config --get-urlmatch does not set exit code 1 when no match is found”
  1. GuilhermeFeb 28, 2016
  2. John KeepingFeb 28, 2016
  3. John KeepingFeb 28, 2016
  4. 0/3 Re: git config --get-urlmatch does not set exit code 1 when no match is foundJohn Keeping, Feb 28, 2016
  5. 1/3 config: fail if --get-urlmatch finds no valueJohn Keeping, Feb 28, 2016
  6. 2/3 Documentation/git-config: use bulleted list for exit codesJohn Keeping, Feb 28, 2016
  7. 3/3 Documentation/git-config: fix --get-all descriptionJohn Keeping, Feb 28, 2016
  8. Junio C HamanoFeb 28, 2016
  9. Jeff KingFeb 29, 2016
  10. GuilhermeFeb 29, 2016
  11. Jeff KingMar 1, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.