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

[add-default-config 2/5] adding default to color

From
Soukaina NAIT HMID <nhsoukaina@gmail.com>
Date
Nov 12, 2017, 15:00 UTC
Message-ID
<0102015fb0bf3002-3462777a-2363-40cf-af37-80e26c0db65b-000000@eu-west-1.amazonses.com>
In-Reply-To
<0102015fb0bf2f74-cb456171-fe65-4d83-8784-b553c7c9e584-000000@eu-west-1.amazonses.com>
From: Soukaina NAIT HMID <snaithmid@bloomberg.net>
Signed-off-by: Soukaina NAIT HMID <snaithmid@bloomberg.net>
---
 builtin/config.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/builtin/config.c b/builtin/config.c
index 124a682d50fa8..9df2d9c43bcad 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -30,6 +30,7 @@ static int end_null;
 static int respect_includes_opt = -1;
 static struct config_options config_options;
 static int show_origin;
+static const char *default_value;
 
 #define ACTION_GET (1<<0)
 #define ACTION_GET_ALL (1<<1)
@@ -47,6 +48,7 @@ static int show_origin;
 #define ACTION_GET_COLOR (1<<13)
 #define ACTION_GET_COLORBOOL (1<<14)
 #define ACTION_GET_URLMATCH (1<<15)
+#define ACTION_GET_COLORORDEFAULT (1<<16)
 
 #define TYPE_BOOL (1<<0)
 #define TYPE_INT (1<<1)
@@ -80,12 +82,13 @@ static struct option builtin_config_options[] = {
 	OPT_BIT(0, "int", &types, N_("value is decimal number"), TYPE_INT),
 	OPT_BIT(0, "bool-or-int", &types, N_("value is --bool or --int"), TYPE_BOOL_OR_INT),
 	OPT_BIT(0, "path", &types, N_("value is a path (file or directory name)"), TYPE_PATH),
-	OPT_BIT(0, "color", &actions, N_("find the color configured"), ACTION_GET_COLOR),
+	OPT_BIT(0, "color", &actions, N_("find the color configured"), ACTION_GET_COLORORDEFAULT),
 	OPT_GROUP(N_("Other")),
 	OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL byte")),
 	OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")),
 	OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
 	OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")),
+	OPT_STRING(0, "default", &default_value, N_("default-value"), N_("sets default for bool/int/path/color when no value is returned from config")),
 	OPT_END(),
 };
 
@@ -331,6 +334,11 @@ static void get_color(const char *var, const char *def_color)
 	fputs(parsed_color, stdout);
 }
 
+static void get_color_default(const char *var)
+{
+	get_color(var, default_value);
+}
+
 static int get_colorbool_found;
 static int get_diff_color_found;
 static int get_color_ui_found;
@@ -726,6 +734,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		check_argc(argc, 1, 2);
 		get_color(argv[0], argv[1]);
 	}
+	else if (actions == ACTION_GET_COLORORDEFAULT) {
+		check_argc(argc, 1, 1);
+		get_color_default(argv[0]);
+	}
 	else if (actions == ACTION_GET_COLORBOOL) {
 		check_argc(argc, 1, 2);
 		if (argc == 2)

--
https://github.com/git/git/pull/431
Previous: Soukaina NAIT HMIDNext: Jeff King
Message 2 of 14 in “[add-default-config 1/5] add --color option to git config”
  1. Soukaina NAIT HMIDNov 12, 2017
  2. 2/5 adding default to colorSoukaina NAIT HMID, Nov 12, 2017
  3. Jeff KingNov 12, 2017
  4. Junio C HamanoNov 13, 2017
  5. Jeff KingNov 13, 2017
  6. 5/5 fix return code on default + add testsSoukaina NAIT HMID, Nov 12, 2017
  7. Jeff KingNov 12, 2017
  8. 4/5 add defaults for path/int/boolSoukaina NAIT HMID, Nov 12, 2017
  9. Jeff KingNov 12, 2017
  10. 3/5 add same test for new command format with --default and --colorSoukaina NAIT HMID, Nov 12, 2017
  11. Jeff KingNov 12, 2017
  12. Jeff KingNov 12, 2017
  13. [add-default-config] add --default option to git config.Soukaina NAIT HMID, Nov 28, 2017
  14. Philip OakleyDec 2, 2017

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.