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

[PATCH/RFC] config: Give error message when not changing a multivar

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
May 17, 2011, 11:34 UTC
Message-ID
<42ab57ae5a2cb7d6860e43e7c3061f9c38cf1b99.1305632091.git.git@drmicha.warpmail.net>

When trying to set a multivar with "git config var value", "git config" issues

warning: remote.repoor.push has multiple values

leaving the user under the impression that the operation succeeded, unless one checks the return value.

Instead, make it

warning: remote.repoor.push has multiple values error: Use a regexp, --add or --set-all to change remote.repoor.push.

to be clear and helpful.
Note: The "warning" is raised through other code paths also so that it
needs to remain a warning for these (which do not raise the error). Only
the caller can determine how to go on from that.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 builtin/config.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/builtin/config.c b/builtin/config.c
index 3e3c528..c438ef4 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -436,9 +436,13 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 			      NULL, NULL);
 	}
 	else if (actions == ACTION_SET) {
+		int ret;
 		check_argc(argc, 2, 2);
 		value = normalize_value(argv[0], argv[1]);
-		return git_config_set(argv[0], value);
+		ret = git_config_set(argv[0], value);
+		if (ret == 5)
+			error("Use a regexp, --add or --set-all to change %s.", argv[0]);
+		return ret;
 	}
 	else if (actions == ACTION_SET_ALL) {
 		check_argc(argc, 2, 3);
-- 
1.7.5.1.514.gd181fb
Next: Jeff King
Message 1 of 11 in “config: Give error message when not changing a multivar”
  1. config: Give error message when not changing a multivarMichael J Gruber, May 17, 2011
  2. Jeff KingMay 17, 2011
  3. Michael J GruberMay 17, 2011
  4. Jeff KingMay 17, 2011
  5. 1/2 config: define and document exit codesMichael J Gruber, May 17, 2011
  6. Thiago FarinaMay 17, 2011
  7. Michael J GruberMay 17, 2011
  8. Jeff KingMay 18, 2011
  9. Junio C HamanoMay 18, 2011
  10. Michael J GruberMay 18, 2011
  11. 2/2 config: Give error message when not changing a multivarMichael J Gruber, May 17, 2011

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.