{"thread":{"id":"47180","subject":"[add-default-config 2/5] adding default to color","startedAt":"2017-11-12T15:00:48Z","lastAt":"2017-12-02T20:33:52Z","messageCount":14,"participants":["Soukaina NAIT HMID","Jeff King","Junio C Hamano","Philip Oakley"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"332335","messageId":"0102015fb0bf3002-3462777a-2363-40cf-af37-80e26c0db65b-000000@eu-west-1.amazonses.com","threadId":"47180","inReplyTo":"0102015fb0bf2f74-cb456171-fe65-4d83-8784-b553c7c9e584-000000@eu-west-1.amazonses.com","subject":"[add-default-config 2/5] adding default to color","fromName":"Soukaina NAIT HMID","fromEmail":"nhsoukaina@gmail.com","sentAt":"2017-11-12T15:00:40Z","receivedAt":"2017-11-12T15:00:48Z","isPatch":false,"sender":{"key":"nhsoukaina@gmail.com","avatar":"https://gravatar.com/avatar/e72cdbbe90e6255ebda147b1cc1943f55f560353de0a91d7bac3fe0d89cd0425?d=mp&s=160"},"body":"From: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n\nSigned-off-by: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n---\n builtin/config.c | 14 +++++++++++++-\n 1 file changed, 13 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 124a682d50fa8..9df2d9c43bcad 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -30,6 +30,7 @@ static int end_null;\n static int respect_includes_opt = -1;\n static struct config_options config_options;\n static int show_origin;\n+static const char *default_value;\n \n #define ACTION_GET (1<<0)\n #define ACTION_GET_ALL (1<<1)\n@@ -47,6 +48,7 @@ static int show_origin;\n #define ACTION_GET_COLOR (1<<13)\n #define ACTION_GET_COLORBOOL (1<<14)\n #define ACTION_GET_URLMATCH (1<<15)\n+#define ACTION_GET_COLORORDEFAULT (1<<16)\n \n #define TYPE_BOOL (1<<0)\n #define TYPE_INT (1<<1)\n@@ -80,12 +82,13 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT(0, \"int\", &types, N_(\"value is decimal number\"), TYPE_INT),\n \tOPT_BIT(0, \"bool-or-int\", &types, N_(\"value is --bool or --int\"), TYPE_BOOL_OR_INT),\n \tOPT_BIT(0, \"path\", &types, N_(\"value is a path (file or directory name)\"), TYPE_PATH),\n-\tOPT_BIT(0, \"color\", &actions, N_(\"find the color configured\"), ACTION_GET_COLOR),\n+\tOPT_BIT(0, \"color\", &actions, N_(\"find the color configured\"), ACTION_GET_COLORORDEFAULT),\n \tOPT_GROUP(N_(\"Other\")),\n \tOPT_BOOL('z', \"null\", &end_null, N_(\"terminate values with NUL byte\")),\n \tOPT_BOOL(0, \"name-only\", &omit_values, N_(\"show variable names only\")),\n \tOPT_BOOL(0, \"includes\", &respect_includes_opt, N_(\"respect include directives on lookup\")),\n \tOPT_BOOL(0, \"show-origin\", &show_origin, N_(\"show origin of config (file, standard input, blob, command line)\")),\n+\tOPT_STRING(0, \"default\", &default_value, N_(\"default-value\"), N_(\"sets default for bool/int/path/color when no value is returned from config\")),\n \tOPT_END(),\n };\n \n@@ -331,6 +334,11 @@ static void get_color(const char *var, const char *def_color)\n \tfputs(parsed_color, stdout);\n }\n \n+static void get_color_default(const char *var)\n+{\n+\tget_color(var, default_value);\n+}\n+\n static int get_colorbool_found;\n static int get_diff_color_found;\n static int get_color_ui_found;\n@@ -726,6 +734,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\tcheck_argc(argc, 1, 2);\n \t\tget_color(argv[0], argv[1]);\n \t}\n+\telse if (actions == ACTION_GET_COLORORDEFAULT) {\n+\t\tcheck_argc(argc, 1, 1);\n+\t\tget_color_default(argv[0]);\n+\t}\n \telse if (actions == ACTION_GET_COLORBOOL) {\n \t\tcheck_argc(argc, 1, 2);\n \t\tif (argc == 2)\n\n--\nhttps://github.com/git/git/pull/431\n"},{"id":"332336","messageId":"0102015fb0bf2f74-cb456171-fe65-4d83-8784-b553c7c9e584-000000@eu-west-1.amazonses.com","threadId":"47180","inReplyTo":null,"subject":"[add-default-config 1/5] add --color option to git config","fromName":"Soukaina NAIT HMID","fromEmail":"nhsoukaina@gmail.com","sentAt":"2017-11-12T15:00:40Z","receivedAt":"2017-11-12T15:00:52Z","isPatch":false,"sender":{"key":"nhsoukaina@gmail.com","avatar":"https://gravatar.com/avatar/e72cdbbe90e6255ebda147b1cc1943f55f560353de0a91d7bac3fe0d89cd0425?d=mp&s=160"},"body":"From: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n\nSigned-off-by: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n---\n Documentation/git-config.txt | 4 ++++\n builtin/config.c             | 1 +\n 2 files changed, 5 insertions(+)\n\ndiff --git a/Documentation/git-config.txt b/Documentation/git-config.txt\nindex 4edd09fc6b074..5d5cd58fdae37 100644\n--- a/Documentation/git-config.txt\n+++ b/Documentation/git-config.txt\n@@ -179,6 +179,10 @@ See also <<FILES>>.\n \tspecified user.  This option has no effect when setting the\n \tvalue (but you can use `git config section.variable ~/`\n \tfrom the command line to let your shell do the expansion).\n+--color::\n+\tFind the color configured for `name` (e.g. `color.diff.new`) and\n+\toutput it as the ANSI color escape sequence to the standard\n+\toutput. \n \n -z::\n --null::\ndiff --git a/builtin/config.c b/builtin/config.c\nindex d13daeeb55927..124a682d50fa8 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -80,6 +80,7 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT(0, \"int\", &types, N_(\"value is decimal number\"), TYPE_INT),\n \tOPT_BIT(0, \"bool-or-int\", &types, N_(\"value is --bool or --int\"), TYPE_BOOL_OR_INT),\n \tOPT_BIT(0, \"path\", &types, N_(\"value is a path (file or directory name)\"), TYPE_PATH),\n+\tOPT_BIT(0, \"color\", &actions, N_(\"find the color configured\"), ACTION_GET_COLOR),\n \tOPT_GROUP(N_(\"Other\")),\n \tOPT_BOOL('z', \"null\", &end_null, N_(\"terminate values with NUL byte\")),\n \tOPT_BOOL(0, \"name-only\", &omit_values, N_(\"show variable names only\")),\n\n--\nhttps://github.com/git/git/pull/431\n"},{"id":"332337","messageId":"0102015fb0bf3103-7448dcb3-ec22-4e67-8995-5cbea349263f-000000@eu-west-1.amazonses.com","threadId":"47180","inReplyTo":"0102015fb0bf2f74-cb456171-fe65-4d83-8784-b553c7c9e584-000000@eu-west-1.amazonses.com","subject":"[add-default-config 5/5] fix return code on default + add tests","fromName":"Soukaina NAIT HMID","fromEmail":"nhsoukaina@gmail.com","sentAt":"2017-11-12T15:00:40Z","receivedAt":"2017-11-12T15:00:54Z","isPatch":false,"sender":{"key":"nhsoukaina@gmail.com","avatar":"https://gravatar.com/avatar/e72cdbbe90e6255ebda147b1cc1943f55f560353de0a91d7bac3fe0d89cd0425?d=mp&s=160"},"body":"From: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n\nSigned-off-by: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n---\n builtin/config.c   |   9 ++-\n t/t9904-default.sh | 232 +++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 238 insertions(+), 3 deletions(-)\n create mode 100755 t/t9904-default.sh\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex eab81c5627091..29c5f55f27a57 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -261,9 +261,12 @@ static int get_value(const char *key_, const char *regex_)\n \n \tif (values.nr == 0 && default_value) {\n \t\tif(types == TYPE_INT || types == TYPE_BOOL || types == TYPE_BOOL_OR_INT || types == TYPE_PATH ) {\n-\t\t\tchar* xstr = normalize_value(key, default_value);\n-\t\t\tfwrite(xstr, 1, strlen(xstr), stdout);\n-\t\t\tfwrite(\"\\n\", 1, 1, stdout);\n+\t\t\tif(strlen(default_value)) {\n+\t\t\t\tchar* xstr = normalize_value(key, default_value);\n+\t\t\t\tfwrite(xstr, 1, strlen(xstr), stdout);\n+\t\t\t\tfwrite(\"\\n\", 1, 1, stdout);\n+\t\t\t\tret = 0;\n+\t\t\t}\n \t\t}\n \t}\n \tfree(values.items);\ndiff --git a/t/t9904-default.sh b/t/t9904-default.sh\nnew file mode 100755\nindex 0000000000000..8e838f512298b\n--- /dev/null\n+++ b/t/t9904-default.sh\n@@ -0,0 +1,232 @@\n+#!/bin/sh\n+\n+test_description='Test default color/boolean/int/path'\n+. ./test-lib.sh\n+\n+boolean()\n+{\n+\tslot=$([ \"$#\" == 3 ] && echo $3 || echo \"no.such.slot\") &&\n+\tactual=$(git config --default \"$1\" --bool \"$slot\") &&\n+\ttest \"$actual\" = \"$2\"\n+}\n+\n+invalid_boolean()\n+{\n+\tslot=$([ \"$#\" == 2 ] && echo $2 || echo \"no.such.slot\") &&\n+\ttest_must_fail git config --default \"$1\" --bool \"$slot\"\n+}\n+\n+test_expect_success 'empty value for boolean' '\n+\tinvalid_boolean \"\"\n+'\n+\n+test_expect_success 'true' '\n+\tboolean \"true\" \"true\"\n+'\n+\n+test_expect_success '1 is true' '\n+\tboolean \"1\" \"true\"\n+'\n+\n+test_expect_success 'non-zero is true' '\n+\tboolean \"5312\" \"true\"\n+'\n+\n+test_expect_success 'false' '\n+\tboolean \"false\" \"false\"\n+'\n+\n+test_expect_success '0 is false' '\n+\tboolean \"0\" \"false\"\n+'\n+\n+test_expect_success 'invalid value' '\n+\tinvalid_boolean \"ab\"\n+'\n+\n+test_expect_success 'existing slot has priority = true' '\n+\tgit config bool.value true &&\n+\tboolean \"false\" \"true\" \"bool.value\"\n+'\n+\n+test_expect_success 'existing slot has priority = false' '\n+\tgit config bool.value false &&\n+\tboolean \"true\" \"false\" \"bool.value\"\n+'\n+\n+int()\n+{\n+\tslot=$([ \"$#\" == 3 ] && echo $3 || echo \"no.such.slot\") &&\n+\tactual=$(git config --default \"$1\" --int \"$slot\") &&\n+\ttest \"$actual\" = \"$2\"\n+}\n+\n+invalid_int()\n+{\n+\tslot=$([ \"$#\" == 2 ] && echo $2 || echo \"no.such.slot\") &&\n+\ttest_must_fail git config \"$1\" --int \"$slot\"\n+}\n+\n+test_expect_success 'empty value for int' '\n+\tinvalid_int \"\" \"\"\n+'\n+\n+test_expect_success 'positive' '\n+\tint \"12345\" \"12345\"\n+'\n+\n+test_expect_success 'negative' '\n+\tint \"-679032\" \"-679032\"\n+'\n+\n+test_expect_success 'invalid value' '\n+\tinvalid_int \"abc\"\n+'\n+test_expect_success 'existing slot has priority = 123' '\n+\tgit config int.value 123 &&\n+\tint \"666\" \"123\" \"int.value\"\n+'\n+\n+test_expect_success 'existing slot with bad value' '\n+\tgit config int.value abc &&\n+\tinvalid_int \"123\" \"int.value\"\n+'\n+\n+path()\n+{\n+\tslot=$([ \"$#\" == 3 ] && echo $3 || echo \"no.such.slot\") &&\n+\tactual=$(git config --default \"$1\" --path \"$slot\") &&\n+\ttest \"$actual\" = \"$2\"\n+}\n+\n+invalid_path()\n+{\n+\tslot=$([ \"$#\" == 2 ] && echo $2 || echo \"no.such.slot\") &&\n+\ttest_must_fail git config \"$1\" --path \"$slot\"\n+}\n+\n+test_expect_success 'empty path is invalid' '\n+\tinvalid_path \"\" \"\"\n+'\n+\n+test_expect_success 'valid path' '\n+\tpath \"/aa/bb/cc\" \"/aa/bb/cc\"\n+'\n+\n+test_expect_success 'existing slot has priority = /to/the/moon' '\n+\tgit config path.value /to/the/moon &&\n+\tpath \"/to/the/sun\" \"/to/the/moon\" \"path.value\"\n+'\n+ESC=$(printf '\\033')\n+\n+color()\n+{\n+\tslot=$([ \"$#\" == 3 ] && echo $3 || echo \"no.such.slot\") &&\n+\tactual=$(git config --default \"$1\" --color \"$slot\" ) &&\n+\ttest \"$actual\" = \"${2:+$ESC}$2\"\n+}\n+\n+invalid_color()\n+{\n+\tslot=$([ \"$#\" == 2 ] && echo $2 || echo \"no.such.slot\") &&\n+\ttest_must_fail git config --default \"$1\" --color \"$slot\"\n+}\n+\n+test_expect_success 'reset' '\n+\tcolor \"reset\" \"[m\"\n+'\n+\n+test_expect_success 'empty color is empty' '\n+\tcolor \"\" \"\"\n+'\n+\n+test_expect_success 'attribute before color name' '\n+\tcolor \"bold red\" \"[1;31m\"\n+'\n+\n+test_expect_success 'color name before attribute' '\n+\tcolor \"red bold\" \"[1;31m\"\n+'\n+\n+test_expect_success 'attr fg bg' '\n+\tcolor \"ul blue red\" \"[4;34;41m\"\n+'\n+\n+test_expect_success 'fg attr bg' '\n+\tcolor \"blue ul red\" \"[4;34;41m\"\n+'\n+\n+test_expect_success 'fg bg attr' '\n+\tcolor \"blue red ul\" \"[4;34;41m\"\n+'\n+\n+test_expect_success 'fg bg attr...' '\n+\tcolor \"blue bold dim ul blink reverse\" \"[1;2;4;5;7;34m\"\n+'\n+\n+# note that nobold and nodim are the same code (22)\n+test_expect_success 'attr negation' '\n+\tcolor \"nobold nodim noul noblink noreverse\" \"[22;24;25;27m\"\n+'\n+\n+test_expect_success '\"no-\" variant of negation' '\n+\tcolor \"no-bold no-blink\" \"[22;25m\"\n+'\n+\n+test_expect_success 'long color specification' '\n+\tcolor \"254 255 bold dim ul blink reverse\" \"[1;2;4;5;7;38;5;254;48;5;255m\"\n+'\n+\n+test_expect_success 'absurdly long color specification' '\n+\tcolor \\\n+\t  \"#ffffff #ffffff bold nobold dim nodim italic noitalic\n+\t   ul noul blink noblink reverse noreverse strike nostrike\" \\\n+\t  \"[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m\"\n+'\n+\n+test_expect_success '0-7 are aliases for basic ANSI color names' '\n+\tcolor \"0 7\" \"[30;47m\"\n+'\n+\n+test_expect_success '256 colors' '\n+\tcolor \"254 bold 255\" \"[1;38;5;254;48;5;255m\"\n+'\n+\n+test_expect_success '24-bit colors' '\n+\tcolor \"#ff00ff black\" \"[38;2;255;0;255;40m\"\n+'\n+\n+test_expect_success '\"normal\" yields no color at all\"' '\n+\tcolor \"normal black\" \"[40m\"\n+'\n+\n+test_expect_success '-1 is a synonym for \"normal\"' '\n+\tcolor \"-1 black\" \"[40m\"\n+'\n+\n+test_expect_success 'color too small' '\n+\tinvalid_color \"-2\"\n+'\n+\n+test_expect_success 'color too big' '\n+\tinvalid_color \"256\"\n+'\n+\n+test_expect_success 'extra character after color number' '\n+\tinvalid_color \"3X\"\n+'\n+\n+test_expect_success 'extra character after color name' '\n+\tinvalid_color \"redX\"\n+'\n+\n+test_expect_success 'extra character after attribute' '\n+\tinvalid_color \"dimX\"\n+'\n+\n+test_expect_success 'existing slot has priority = red' '\n+\tgit config color.value red &&\n+\tpath \"blue\" \"red\" \"color.value\"\n+'\n+\n+test_done\n\n--\nhttps://github.com/git/git/pull/431\n"},{"id":"332338","messageId":"0102015fb0bf3086-fe6c887d-592b-45f0-8f8e-bdbe2d18a218-000000@eu-west-1.amazonses.com","threadId":"47180","inReplyTo":"0102015fb0bf2f74-cb456171-fe65-4d83-8784-b553c7c9e584-000000@eu-west-1.amazonses.com","subject":"[add-default-config 4/5] add defaults for path/int/bool","fromName":"Soukaina NAIT HMID","fromEmail":"nhsoukaina@gmail.com","sentAt":"2017-11-12T15:00:40Z","receivedAt":"2017-11-12T15:00:56Z","isPatch":false,"sender":{"key":"nhsoukaina@gmail.com","avatar":"https://gravatar.com/avatar/e72cdbbe90e6255ebda147b1cc1943f55f560353de0a91d7bac3fe0d89cd0425?d=mp&s=160"},"body":"From: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n\nSigned-off-by: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n---\n builtin/config.c  |  12 ++++-\n t/t4026-color2.sh | 129 ------------------------------------------------------\n 2 files changed, 11 insertions(+), 130 deletions(-)\n delete mode 100755 t/t4026-color2.sh\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 9df2d9c43bcad..eab81c5627091 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -55,6 +55,8 @@ static const char *default_value;\n #define TYPE_BOOL_OR_INT (1<<2)\n #define TYPE_PATH (1<<3)\n \n+static char *normalize_value(const char *key, const char *value);\n+\n static struct option builtin_config_options[] = {\n \tOPT_GROUP(N_(\"Config file location\")),\n \tOPT_BOOL(0, \"global\", &use_global_config, N_(\"use global config file\")),\n@@ -256,8 +258,15 @@ static int get_value(const char *key_, const char *regex_)\n \t\t\tfwrite(buf->buf, 1, buf->len, stdout);\n \t\tstrbuf_release(buf);\n \t}\n-\tfree(values.items);\n \n+\tif (values.nr == 0 && default_value) {\n+\t\tif(types == TYPE_INT || types == TYPE_BOOL || types == TYPE_BOOL_OR_INT || types == TYPE_PATH ) {\n+\t\t\tchar* xstr = normalize_value(key, default_value);\n+\t\t\tfwrite(xstr, 1, strlen(xstr), stdout);\n+\t\t\tfwrite(\"\\n\", 1, 1, stdout);\n+\t\t}\n+\t}\n+\tfree(values.items);\n free_strings:\n \tfree(key);\n \tif (key_regexp) {\n@@ -272,6 +281,7 @@ static int get_value(const char *key_, const char *regex_)\n \treturn ret;\n }\n \n+\n static char *normalize_value(const char *key, const char *value)\n {\n \tif (!value)\ndiff --git a/t/t4026-color2.sh b/t/t4026-color2.sh\ndeleted file mode 100755\nindex 695ce9dd6f8d4..0000000000000\n--- a/t/t4026-color2.sh\n+++ /dev/null\n@@ -1,129 +0,0 @@\n-#!/bin/sh\n-#\n-# Copyright (c) 2008 Timo Hirvonen\n-#\n-\n-test_description='Test diff/status color escape codes'\n-. ./test-lib.sh\n-\n-ESC=$(printf '\\033')\n-color()\n-{\n-\tactual=$(git config --default \"$1\" --color no.such.slot) &&\n-\ttest \"$actual\" = \"${2:+$ESC}$2\"\n-}\n-\n-invalid_color()\n-{\n-\ttest_must_fail git config --get-color no.such.slot \"$1\"\n-}\n-\n-test_expect_success 'reset' '\n-\tcolor \"reset\" \"[m\"\n-'\n-\n-test_expect_success 'empty color is empty' '\n-\tcolor \"\" \"\"\n-'\n-\n-test_expect_success 'attribute before color name' '\n-\tcolor \"bold red\" \"[1;31m\"\n-'\n-\n-test_expect_success 'color name before attribute' '\n-\tcolor \"red bold\" \"[1;31m\"\n-'\n-\n-test_expect_success 'attr fg bg' '\n-\tcolor \"ul blue red\" \"[4;34;41m\"\n-'\n-\n-test_expect_success 'fg attr bg' '\n-\tcolor \"blue ul red\" \"[4;34;41m\"\n-'\n-\n-test_expect_success 'fg bg attr' '\n-\tcolor \"blue red ul\" \"[4;34;41m\"\n-'\n-\n-test_expect_success 'fg bg attr...' '\n-\tcolor \"blue bold dim ul blink reverse\" \"[1;2;4;5;7;34m\"\n-'\n-\n-# note that nobold and nodim are the same code (22)\n-test_expect_success 'attr negation' '\n-\tcolor \"nobold nodim noul noblink noreverse\" \"[22;24;25;27m\"\n-'\n-\n-test_expect_success '\"no-\" variant of negation' '\n-\tcolor \"no-bold no-blink\" \"[22;25m\"\n-'\n-\n-test_expect_success 'long color specification' '\n-\tcolor \"254 255 bold dim ul blink reverse\" \"[1;2;4;5;7;38;5;254;48;5;255m\"\n-'\n-\n-test_expect_success 'absurdly long color specification' '\n-\tcolor \\\n-\t  \"#ffffff #ffffff bold nobold dim nodim italic noitalic\n-\t   ul noul blink noblink reverse noreverse strike nostrike\" \\\n-\t  \"[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m\"\n-'\n-\n-test_expect_success '0-7 are aliases for basic ANSI color names' '\n-\tcolor \"0 7\" \"[30;47m\"\n-'\n-\n-test_expect_success '256 colors' '\n-\tcolor \"254 bold 255\" \"[1;38;5;254;48;5;255m\"\n-'\n-\n-test_expect_success '24-bit colors' '\n-\tcolor \"#ff00ff black\" \"[38;2;255;0;255;40m\"\n-'\n-\n-test_expect_success '\"normal\" yields no color at all\"' '\n-\tcolor \"normal black\" \"[40m\"\n-'\n-\n-test_expect_success '-1 is a synonym for \"normal\"' '\n-\tcolor \"-1 black\" \"[40m\"\n-'\n-\n-test_expect_success 'color too small' '\n-\tinvalid_color \"-2\"\n-'\n-\n-test_expect_success 'color too big' '\n-\tinvalid_color \"256\"\n-'\n-\n-test_expect_success 'extra character after color number' '\n-\tinvalid_color \"3X\"\n-'\n-\n-test_expect_success 'extra character after color name' '\n-\tinvalid_color \"redX\"\n-'\n-\n-test_expect_success 'extra character after attribute' '\n-\tinvalid_color \"dimX\"\n-'\n-\n-test_expect_success 'unknown color slots are ignored (diff)' '\n-\tgit config color.diff.nosuchslotwilleverbedefined white &&\n-\tgit diff --color\n-'\n-\n-test_expect_success 'unknown color slots are ignored (branch)' '\n-\tgit config color.branch.nosuchslotwilleverbedefined white &&\n-\tgit branch -a\n-'\n-\n-test_expect_success 'unknown color slots are ignored (status)' '\n-\tgit config color.status.nosuchslotwilleverbedefined white &&\n-\t{ git status; ret=$?; } &&\n-\tcase $ret in 0|1) : ok ;; *) false ;; esac\n-'\n-\n-test_done\n\n--\nhttps://github.com/git/git/pull/431\n"},{"id":"332339","messageId":"0102015fb0bf30cb-b3c720d6-c508-4771-a0f1-8c4b2e84f20f-000000@eu-west-1.amazonses.com","threadId":"47180","inReplyTo":"0102015fb0bf2f74-cb456171-fe65-4d83-8784-b553c7c9e584-000000@eu-west-1.amazonses.com","subject":"[add-default-config 3/5] add same test for new command format with --default and --color","fromName":"Soukaina NAIT HMID","fromEmail":"nhsoukaina@gmail.com","sentAt":"2017-11-12T15:00:40Z","receivedAt":"2017-11-12T15:00:58Z","isPatch":false,"sender":{"key":"nhsoukaina@gmail.com","avatar":"https://gravatar.com/avatar/e72cdbbe90e6255ebda147b1cc1943f55f560353de0a91d7bac3fe0d89cd0425?d=mp&s=160"},"body":"From: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n\nSigned-off-by: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n---\n t/t4026-color2.sh | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 129 insertions(+)\n create mode 100755 t/t4026-color2.sh\n\ndiff --git a/t/t4026-color2.sh b/t/t4026-color2.sh\nnew file mode 100755\nindex 0000000000000..695ce9dd6f8d4\n--- /dev/null\n+++ b/t/t4026-color2.sh\n@@ -0,0 +1,129 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2008 Timo Hirvonen\n+#\n+\n+test_description='Test diff/status color escape codes'\n+. ./test-lib.sh\n+\n+ESC=$(printf '\\033')\n+color()\n+{\n+\tactual=$(git config --default \"$1\" --color no.such.slot) &&\n+\ttest \"$actual\" = \"${2:+$ESC}$2\"\n+}\n+\n+invalid_color()\n+{\n+\ttest_must_fail git config --get-color no.such.slot \"$1\"\n+}\n+\n+test_expect_success 'reset' '\n+\tcolor \"reset\" \"[m\"\n+'\n+\n+test_expect_success 'empty color is empty' '\n+\tcolor \"\" \"\"\n+'\n+\n+test_expect_success 'attribute before color name' '\n+\tcolor \"bold red\" \"[1;31m\"\n+'\n+\n+test_expect_success 'color name before attribute' '\n+\tcolor \"red bold\" \"[1;31m\"\n+'\n+\n+test_expect_success 'attr fg bg' '\n+\tcolor \"ul blue red\" \"[4;34;41m\"\n+'\n+\n+test_expect_success 'fg attr bg' '\n+\tcolor \"blue ul red\" \"[4;34;41m\"\n+'\n+\n+test_expect_success 'fg bg attr' '\n+\tcolor \"blue red ul\" \"[4;34;41m\"\n+'\n+\n+test_expect_success 'fg bg attr...' '\n+\tcolor \"blue bold dim ul blink reverse\" \"[1;2;4;5;7;34m\"\n+'\n+\n+# note that nobold and nodim are the same code (22)\n+test_expect_success 'attr negation' '\n+\tcolor \"nobold nodim noul noblink noreverse\" \"[22;24;25;27m\"\n+'\n+\n+test_expect_success '\"no-\" variant of negation' '\n+\tcolor \"no-bold no-blink\" \"[22;25m\"\n+'\n+\n+test_expect_success 'long color specification' '\n+\tcolor \"254 255 bold dim ul blink reverse\" \"[1;2;4;5;7;38;5;254;48;5;255m\"\n+'\n+\n+test_expect_success 'absurdly long color specification' '\n+\tcolor \\\n+\t  \"#ffffff #ffffff bold nobold dim nodim italic noitalic\n+\t   ul noul blink noblink reverse noreverse strike nostrike\" \\\n+\t  \"[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m\"\n+'\n+\n+test_expect_success '0-7 are aliases for basic ANSI color names' '\n+\tcolor \"0 7\" \"[30;47m\"\n+'\n+\n+test_expect_success '256 colors' '\n+\tcolor \"254 bold 255\" \"[1;38;5;254;48;5;255m\"\n+'\n+\n+test_expect_success '24-bit colors' '\n+\tcolor \"#ff00ff black\" \"[38;2;255;0;255;40m\"\n+'\n+\n+test_expect_success '\"normal\" yields no color at all\"' '\n+\tcolor \"normal black\" \"[40m\"\n+'\n+\n+test_expect_success '-1 is a synonym for \"normal\"' '\n+\tcolor \"-1 black\" \"[40m\"\n+'\n+\n+test_expect_success 'color too small' '\n+\tinvalid_color \"-2\"\n+'\n+\n+test_expect_success 'color too big' '\n+\tinvalid_color \"256\"\n+'\n+\n+test_expect_success 'extra character after color number' '\n+\tinvalid_color \"3X\"\n+'\n+\n+test_expect_success 'extra character after color name' '\n+\tinvalid_color \"redX\"\n+'\n+\n+test_expect_success 'extra character after attribute' '\n+\tinvalid_color \"dimX\"\n+'\n+\n+test_expect_success 'unknown color slots are ignored (diff)' '\n+\tgit config color.diff.nosuchslotwilleverbedefined white &&\n+\tgit diff --color\n+'\n+\n+test_expect_success 'unknown color slots are ignored (branch)' '\n+\tgit config color.branch.nosuchslotwilleverbedefined white &&\n+\tgit branch -a\n+'\n+\n+test_expect_success 'unknown color slots are ignored (status)' '\n+\tgit config color.status.nosuchslotwilleverbedefined white &&\n+\t{ git status; ret=$?; } &&\n+\tcase $ret in 0|1) : ok ;; *) false ;; esac\n+'\n+\n+test_done\n\n--\nhttps://github.com/git/git/pull/431\n"},{"id":"332340","messageId":"20171112152245.fetxqionsqqg2obp@sigill.intra.peff.net","threadId":"47180","inReplyTo":"0102015fb0bf2f74-cb456171-fe65-4d83-8784-b553c7c9e584-000000@eu-west-1.amazonses.com","subject":"Re: [add-default-config 1/5] add --color option to git config","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-11-12T15:22:46Z","receivedAt":"2017-11-12T15:22:53Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 12, 2017 at 03:00:40PM +0000, Soukaina NAIT HMID wrote:\n\n> From: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n> \n> Signed-off-by: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n\nHi Soukaina, and welcome to the list! Thanks for working on these\npatches.\n\nI'll go through and make inline comments on your patches, but first a\nfew overall issues:\n\n - you have five patches in your series, some of which are backing out\n   changes made by the other patches. It's normal in the Git community\n   to use \"git rebase -i\" to squash down your changes to \"clean\" patches\n   that form a sequence. For your topic, I'd expect to see two patches\n   in the end:\n\n     1. Add a \"config --default\" option (and documentation and tests).\n\n     2. Add a \"config --color\" type (and documentation and tests).\n\n - your commit messages are mostly empty. :) This is a good place to\n   describe the motivation for the patch, document any design decisions,\n   discuss any alternatives, etc. This is helpful for reviewers to\n   understand what you're trying to achieve, and for people later who\n   discover your commit from \"git log\".\n\n> diff --git a/builtin/config.c b/builtin/config.c\n> index d13daeeb55927..124a682d50fa8 100644\n> --- a/builtin/config.c\n> +++ b/builtin/config.c\n> @@ -80,6 +80,7 @@ static struct option builtin_config_options[] = {\n>  \tOPT_BIT(0, \"int\", &types, N_(\"value is decimal number\"), TYPE_INT),\n>  \tOPT_BIT(0, \"bool-or-int\", &types, N_(\"value is --bool or --int\"), TYPE_BOOL_OR_INT),\n>  \tOPT_BIT(0, \"path\", &types, N_(\"value is a path (file or directory name)\"), TYPE_PATH),\n> +\tOPT_BIT(0, \"color\", &actions, N_(\"find the color configured\"), ACTION_GET_COLOR),\n\nI think we'd want this \"--color\" to actually be a type, not a separate\naction. I.e., so that it behaves --int, --bool, etc. Part of the goal\n(well, my goal) was to make accessing color config more like other types\nof config.\n\n-Peff\n"},{"id":"332343","messageId":"20171112153659.lt77rn6h6faeqfpb@sigill.intra.peff.net","threadId":"47180","inReplyTo":"0102015fb0bf3002-3462777a-2363-40cf-af37-80e26c0db65b-000000@eu-west-1.amazonses.com","subject":"Re: [add-default-config 2/5] adding default to color","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-11-12T15:37:00Z","receivedAt":"2017-11-12T15:37:07Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 12, 2017 at 03:00:40PM +0000, Soukaina NAIT HMID wrote:\n\n> diff --git a/builtin/config.c b/builtin/config.c\n> index 124a682d50fa8..9df2d9c43bcad 100644\n> --- a/builtin/config.c\n> +++ b/builtin/config.c\n> @@ -30,6 +30,7 @@ static int end_null;\n>  static int respect_includes_opt = -1;\n>  static struct config_options config_options;\n>  static int show_origin;\n> +static const char *default_value;\n> [...]\n> +\tOPT_STRING(0, \"default\", &default_value, N_(\"default-value\"), N_(\"sets default for bool/int/path/color when no value is returned from config\")),\n\nThese hunks make sense. We're adding a new \"--default\" option that would\nkick in when you try to look up a key and it isn't present.\n\nI think we can skip the \"bool/int/path/color\" thing in the help string.\nWe would want this to kick in for every type, right?  The only\nconstraint is that we are doing a \"get\" operation. It wouldn't make any\nsense to use \"--default\" when setting a variable, listing, etc. Should\nwe catch these cases and return an error?\n\nWe'd also want to mention this in Documentation/git-config.txt.\n\n> @@ -47,6 +48,7 @@ static int show_origin;\n>  #define ACTION_GET_COLOR (1<<13)\n>  #define ACTION_GET_COLORBOOL (1<<14)\n>  #define ACTION_GET_URLMATCH (1<<15)\n> +#define ACTION_GET_COLORORDEFAULT (1<<16)\n\nI'm not sure I understand this part, though. Providing a default should\nbe something that goes along with a \"get\" action, but isn't its own\naction.\n\n> +static void get_color_default(const char *var)\n> +{\n> +\tget_color(var, default_value);\n> +}\n> +\n\nAnd here we're just applying --default to colors, but we'd eventually\nwant them for everything. I think that's fixed later in the series, so\nI'll keep reading. But I'd expect a function like get_value() to be\ndetecting the case where we got no hits and filling in the default_value\nthere, as if we had read it from the config file.\n\n-Peff\n"},{"id":"332344","messageId":"20171112153725.xnactqmdpir5fgql@sigill.intra.peff.net","threadId":"47180","inReplyTo":"0102015fb0bf30cb-b3c720d6-c508-4771-a0f1-8c4b2e84f20f-000000@eu-west-1.amazonses.com","subject":"Re: [add-default-config 3/5] add same test for new command format with --default and --color","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-11-12T15:37:26Z","receivedAt":"2017-11-12T15:37:33Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 12, 2017 at 03:00:40PM +0000, Soukaina NAIT HMID wrote:\n\n> ---\n>  t/t4026-color2.sh | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  1 file changed, 129 insertions(+)\n>  create mode 100755 t/t4026-color2.sh\n\nI'll skip reviewing this one, since the file goes away later in the\nseries.\n\n-Peff\n"},{"id":"332345","messageId":"20171112154518.ozbbebzazhko7byl@sigill.intra.peff.net","threadId":"47180","inReplyTo":"0102015fb0bf3086-fe6c887d-592b-45f0-8f8e-bdbe2d18a218-000000@eu-west-1.amazonses.com","subject":"Re: [add-default-config 4/5] add defaults for path/int/bool","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-11-12T15:45:18Z","receivedAt":"2017-11-12T15:45:25Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 12, 2017 at 03:00:40PM +0000, Soukaina NAIT HMID wrote:\n\n> @@ -256,8 +258,15 @@ static int get_value(const char *key_, const char *regex_)\n>  \t\t\tfwrite(buf->buf, 1, buf->len, stdout);\n>  \t\tstrbuf_release(buf);\n>  \t}\n> -\tfree(values.items);\n>  \n> +\tif (values.nr == 0 && default_value) {\n> +\t\tif(types == TYPE_INT || types == TYPE_BOOL || types == TYPE_BOOL_OR_INT || types == TYPE_PATH ) {\n> +\t\t\tchar* xstr = normalize_value(key, default_value);\n> +\t\t\tfwrite(xstr, 1, strlen(xstr), stdout);\n> +\t\t\tfwrite(\"\\n\", 1, 1, stdout);\n> +\t\t}\n> +\t}\n> +\tfree(values.items);\n\nOK, this location makes more sense to me for handling --default. I think\nit's still a bit lower in the function than I'd expect, though.\n\nThe loop just above the code you added is showing all of the values we\nfound. So I think that's the spot where'd say \"we didn't find any\nvalues; pretend like we found default_value\". Including, I think, making\nsure that the return value from the function is still 0. So realy right\nafter config_with_options() returns, I'd expect to check something like:\n\n  if (!values.nr && default_value) {\n          /* insert default_value into values list */\n  }\n\nWe'd also want to use format_config(), not normalize_config(). We do\nformat_config() to show values, whereas normalize_config() is usually\nfor values we're putting into a config file (so for example TYPE_PATH\ndoesn't get normalized, but we would want it converted here to show the\nuser).\n\nI'm also not sure that we need to check \"types\" as you have here.\nWouldn't we want to apply the default regardless of type, and let\nformat_config() handle it?\n\n> @@ -272,6 +281,7 @@ static int get_value(const char *key_, const char *regex_)\n>  \treturn ret;\n>  }\n>  \n> +\n>  static char *normalize_value(const char *key, const char *value)\n\nWatch out for stray changes like this one creeping into your commits.\n\n> diff --git a/t/t4026-color2.sh b/t/t4026-color2.sh\n> deleted file mode 100755\n> index 695ce9dd6f8d4..0000000000000\n\nThis part is obviously good and rectifying the problem from patch 3.\nOnce they're squashed together, we won't see it at all. :)\n\n-Peff\n"},{"id":"332346","messageId":"20171112160401.qeimqv234ojben5e@sigill.intra.peff.net","threadId":"47180","inReplyTo":"0102015fb0bf3103-7448dcb3-ec22-4e67-8995-5cbea349263f-000000@eu-west-1.amazonses.com","subject":"Re: [add-default-config 5/5] fix return code on default + add tests","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-11-12T16:04:02Z","receivedAt":"2017-11-12T16:04:19Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 12, 2017 at 03:00:40PM +0000, Soukaina NAIT HMID wrote:\n\n> diff --git a/builtin/config.c b/builtin/config.c\n> index eab81c5627091..29c5f55f27a57 100644\n> --- a/builtin/config.c\n> +++ b/builtin/config.c\n> @@ -261,9 +261,12 @@ static int get_value(const char *key_, const char *regex_)\n>  \n>  \tif (values.nr == 0 && default_value) {\n>  \t\tif(types == TYPE_INT || types == TYPE_BOOL || types == TYPE_BOOL_OR_INT || types == TYPE_PATH ) {\n> -\t\t\tchar* xstr = normalize_value(key, default_value);\n> -\t\t\tfwrite(xstr, 1, strlen(xstr), stdout);\n> -\t\t\tfwrite(\"\\n\", 1, 1, stdout);\n> +\t\t\tif(strlen(default_value)) {\n> +\t\t\t\tchar* xstr = normalize_value(key, default_value);\n> +\t\t\t\tfwrite(xstr, 1, strlen(xstr), stdout);\n> +\t\t\t\tfwrite(\"\\n\", 1, 1, stdout);\n> +\t\t\t\tret = 0;\n> +\t\t\t}\n>  \t\t}\n\nOK, fixing up the return value is a good thing (though again, I think if\nwe place our default_value in the list earlier that will just fall out\nnaturally).\n\nI'm not sure why we care if the default_value string is empty or not. It\nshould be allowed to default to an empty string, I'd think.\n\n> diff --git a/t/t9904-default.sh b/t/t9904-default.sh\n> new file mode 100755\n> index 0000000000000..8e838f512298b\n> --- /dev/null\n> +++ b/t/t9904-default.sh\n\nWe usually try to group tests with similar-numbered ones. Most of the\nconfig tests are in the t13xx area. Probably \"t1310-config-default.sh\"\nwould be the right place (or if there really are just a few tests, which\nI think may be all we need, they can just go into t1300).\n\n> +boolean()\n> +{\n> +\tslot=$([ \"$#\" == 3 ] && echo $3 || echo \"no.such.slot\") &&\n> +\tactual=$(git config --default \"$1\" --bool \"$slot\") &&\n> +\ttest \"$actual\" = \"$2\"\n> +}\n\nA minor style nit, but we usually prefer \"test\" instead of \"[\" for\nconditionals. It took me a while to figure out how this function was\nmeant to be used. It might be worth adding a comment. Though most of it\nwas due to the first line, which I think can just be written as:\n\n  slot=${3:-no.such.slot}\n\n(or you could even just write that directly in the second line).\n\nThat's a bit more idiomatic for our shell scripts.\n\n> +test_expect_success 'empty value for boolean' '\n> +\tinvalid_boolean \"\"\n> +'\n\nThere are a lot of tests here about type interpretation, but I think\nthat should be largely orthogonal to the --default feature. Once it's\nwritten in a way that's independent of the type, I think we can assume\nthat if \"--default\" works for one type, it should work with others\nwithout being exhaustive.\n\nSo I think what we really want to test from this series is:\n\n  1. --default kicks in when no matching config is found\n\n  2. --default does not kick in when config _is_ found\n\n  3. (optional) we complain about --default with non-get actions\n\n  4. --color works as a type for \"get\" operations\n\n  5. --color is not normalized for \"set\" operations; if you do:\n\n       git config --color some.key red\n\n     we should write \"red\" into the config file, not the ANSI codes.\n\nI know the reason you were looking into t4026 originally because it was\nthe only spot that used --get-color in the whole test suite. But its use\nof \"--get-color\" is largely orthogonal to what it's testing. It cares\nabout parsing the specific colors, but just didn't have another easy way\nto convince Git to parse a bunch of colors without having to pick the\nresults out of diff or log output.\n\nI'd be OK with converting that to use \"--color --default\" instead of\n--get-color, but if we do so we should make sure that there's some\ncoverage of \"--get-color\" elsewhere in the config tests (not checking\nevery possible color variation, but just making sure that it can\nactually look up any color with it).\n\n-Peff\n"},{"id":"332386","messageId":"xmqqvaiealsv.fsf@gitster.mtv.corp.google.com","threadId":"47180","inReplyTo":"20171112153659.lt77rn6h6faeqfpb@sigill.intra.peff.net","subject":"Re: [add-default-config 2/5] adding default to color","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-11-13T03:40:16Z","receivedAt":"2017-11-13T03:40:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n>> @@ -47,6 +48,7 @@ static int show_origin;\n>>  #define ACTION_GET_COLOR (1<<13)\n>>  #define ACTION_GET_COLORBOOL (1<<14)\n>>  #define ACTION_GET_URLMATCH (1<<15)\n>> +#define ACTION_GET_COLORORDEFAULT (1<<16)\n>\n> I'm not sure I understand this part, though. Providing a default should\n> be something that goes along with a \"get\" action, but isn't its own\n> action.\n\nI agree that it is not.\n\nAs an aside.  Over time we accumulated quite a many actions that are\nall mutually exclusive by nature.  I have a feeling that we might be\nbetter off to move away from this implementation.  The only thing\nthat we are getting from the current one-bit-in-a-flag-word is that\nwe can name the variable \"actions\" (instead of \"action\") to pretend\nas if we can be given more than one, and then having to check its\nvalue with HAS_MULTI_BITS(actions) to confuse ourselves.\n\nInstead, perhaps we should introduce an \"enum action\" that includes\nACTION_UNSPECIFIED that is the initial value for the \"action\"\nvariable, which gets set to ACTION_GET, etc. with OPT_SET_INT().  If\nwe really care about erroring out when given\n\n\t$ git config --add --get foo.bar\n\ninstead of the \"last one wins\" semantics, we can use OPT_CMDMODE.\n\nThe above is of course outside the scope of this series, and I am\nnot sure if it should be done as a preparatory or a follow-up\nclean-up.\n"},{"id":"332389","messageId":"20171113035516.446uznhfl6xlfvmi@sigill.intra.peff.net","threadId":"47180","inReplyTo":"xmqqvaiealsv.fsf@gitster.mtv.corp.google.com","subject":"Re: [add-default-config 2/5] adding default to color","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-11-13T03:55:17Z","receivedAt":"2017-11-13T03:55:25Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Nov 13, 2017 at 12:40:16PM +0900, Junio C Hamano wrote:\n\n> As an aside.  Over time we accumulated quite a many actions that are\n> all mutually exclusive by nature.  I have a feeling that we might be\n> better off to move away from this implementation.  The only thing\n> that we are getting from the current one-bit-in-a-flag-word is that\n> we can name the variable \"actions\" (instead of \"action\") to pretend\n> as if we can be given more than one, and then having to check its\n> value with HAS_MULTI_BITS(actions) to confuse ourselves.\n> \n> Instead, perhaps we should introduce an \"enum action\" that includes\n> ACTION_UNSPECIFIED that is the initial value for the \"action\"\n> variable, which gets set to ACTION_GET, etc. with OPT_SET_INT().  If\n> we really care about erroring out when given\n> \n> \t$ git config --add --get foo.bar\n> \n> instead of the \"last one wins\" semantics, we can use OPT_CMDMODE.\n> \n> The above is of course outside the scope of this series, and I am\n> not sure if it should be done as a preparatory or a follow-up\n> clean-up.\n\nYes, I agree that it's a little confusing, and that an enum is a better\nrepresentation.  The TYPE constants have the same problem.\n\nI _think_ we could use OPT_CMDMODE() for those, too. Despite the name,\nthere is nothing in the parse-options error message that would be\ninappropriate for something that isn't a cmdmode. Though I care a lot\nless about \"--bool --int\" reporting an error (instead of last-one-wins)\nthan I do about \"--get --set\".\n\n-Peff\n"},{"id":"333709","messageId":"0102016004959a28-410f021b-ac2b-4756-8e55-244071c074b5-000000@eu-west-1.amazonses.com","threadId":"47180","inReplyTo":"0102015fb0bf2f74-cb456171-fe65-4d83-8784-b553c7c9e584-000000@eu-west-1.amazonses.com","subject":"[add-default-config] add --default option to git config.","fromName":"Soukaina NAIT HMID","fromEmail":"nhsoukaina@gmail.com","sentAt":"2017-11-28T21:43:21Z","receivedAt":"2017-11-28T21:43:28Z","isPatch":false,"sender":{"key":"nhsoukaina@gmail.com","avatar":"https://gravatar.com/avatar/e72cdbbe90e6255ebda147b1cc1943f55f560353de0a91d7bac3fe0d89cd0425?d=mp&s=160"},"body":"From: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n\nSigned-off-by: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n---\n Documentation/git-config.txt |   4 ++\n builtin/config.c             |  34 ++++++++-\n config.c                     |  10 +++\n config.h                     |   1 +\n t/t1300-repo-config.sh       | 161 +++++++++++++++++++++++++++++++++++++++++++\n 5 files changed, 209 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-config.txt b/Documentation/git-config.txt\nindex 4edd09fc6b074..5d5cd58fdae37 100644\n--- a/Documentation/git-config.txt\n+++ b/Documentation/git-config.txt\n@@ -179,6 +179,10 @@ See also <<FILES>>.\n \tspecified user.  This option has no effect when setting the\n \tvalue (but you can use `git config section.variable ~/`\n \tfrom the command line to let your shell do the expansion).\n+--color::\n+\tFind the color configured for `name` (e.g. `color.diff.new`) and\n+\toutput it as the ANSI color escape sequence to the standard\n+\toutput. \n \n -z::\n --null::\ndiff --git a/builtin/config.c b/builtin/config.c\nindex d13daeeb55927..5e5b998b7c892 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -30,6 +30,7 @@ static int end_null;\n static int respect_includes_opt = -1;\n static struct config_options config_options;\n static int show_origin;\n+static const char *default_value;\n \n #define ACTION_GET (1<<0)\n #define ACTION_GET_ALL (1<<1)\n@@ -52,6 +53,8 @@ static int show_origin;\n #define TYPE_INT (1<<1)\n #define TYPE_BOOL_OR_INT (1<<2)\n #define TYPE_PATH (1<<3)\n+#define TYPE_COLOR (1<<4)\n+\n \n static struct option builtin_config_options[] = {\n \tOPT_GROUP(N_(\"Config file location\")),\n@@ -80,11 +83,13 @@ static struct option builtin_config_options[] = {\n \tOPT_BIT(0, \"int\", &types, N_(\"value is decimal number\"), TYPE_INT),\n \tOPT_BIT(0, \"bool-or-int\", &types, N_(\"value is --bool or --int\"), TYPE_BOOL_OR_INT),\n \tOPT_BIT(0, \"path\", &types, N_(\"value is a path (file or directory name)\"), TYPE_PATH),\n+\tOPT_BIT(0, \"color\", &types, N_(\"find the color configured\"), TYPE_COLOR),\n \tOPT_GROUP(N_(\"Other\")),\n \tOPT_BOOL('z', \"null\", &end_null, N_(\"terminate values with NUL byte\")),\n \tOPT_BOOL(0, \"name-only\", &omit_values, N_(\"show variable names only\")),\n \tOPT_BOOL(0, \"includes\", &respect_includes_opt, N_(\"respect include directives on lookup\")),\n \tOPT_BOOL(0, \"show-origin\", &show_origin, N_(\"show origin of config (file, standard input, blob, command line)\")),\n+\tOPT_STRING(0, \"default\", &default_value, N_(\"default-value\"), N_(\"sets default value when no value is returned from config\")),\n \tOPT_END(),\n };\n \n@@ -159,6 +164,13 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value\n \t\t\t\treturn -1;\n \t\t\tstrbuf_addstr(buf, v);\n \t\t\tfree((char *)v);\n+\t\t}\n+\t\telse if (types == TYPE_COLOR) {\n+\t\t\tchar *v = xmalloc(COLOR_MAXLEN);\n+\t\t\tif (git_config_color(&v, key_, value_) < 0)\n+\t\t\t\treturn -1;\n+\t\t\tstrbuf_addstr(buf, v);\n+\t\t\tfree((char *)v);\n \t\t} else if (value_) {\n \t\t\tstrbuf_addstr(buf, value_);\n \t\t} else {\n@@ -244,8 +256,16 @@ static int get_value(const char *key_, const char *regex_)\n \tconfig_with_options(collect_config, &values,\n \t\t\t    &given_config_source, &config_options);\n \n-\tret = !values.nr;\n+\tif (!values.nr && default_value && types) {\n+\t\tstruct strbuf *item;\n+\t\tALLOC_GROW(values.items, values.nr + 1, values.alloc);\n+\t\titem = &values.items[values.nr++];\n+\t\tif(format_config(item, key_, default_value) < 0){\n+\t\t\tvalues.nr = 0;\n+\t\t}\n+\t}\n \n+\tret = !values.nr;\n \tfor (i = 0; i < values.nr; i++) {\n \t\tstruct strbuf *buf = values.items + i;\n \t\tif (do_all || i == values.nr - 1)\n@@ -268,6 +288,7 @@ static int get_value(const char *key_, const char *regex_)\n \treturn ret;\n }\n \n+\n static char *normalize_value(const char *key, const char *value)\n {\n \tif (!value)\n@@ -281,6 +302,17 @@ static char *normalize_value(const char *key, const char *value)\n \t\t * when retrieving the value.\n \t\t */\n \t\treturn xstrdup(value);\n+\tif (types == TYPE_COLOR)\n+\t{\n+\t\tchar *v = xmalloc(COLOR_MAXLEN);\n+\t\tif (git_config_color(&v, key, value) == 0)\n+\t\t{\n+\t\t\tfree((char *)v);\n+\t\t\treturn xstrdup(value);\n+\t\t}\n+\t\tfree((char *)v);\n+\t\tdie(\"cannot parse color '%s'\", value);\n+\t}\n \tif (types == TYPE_INT)\n \t\treturn xstrfmt(\"%\"PRId64, git_config_int64(key, value));\n \tif (types == TYPE_BOOL)\ndiff --git a/config.c b/config.c\nindex 903abf9533b18..5c5daffeb6723 100644\n--- a/config.c\n+++ b/config.c\n@@ -16,6 +16,7 @@\n #include \"string-list.h\"\n #include \"utf8.h\"\n #include \"dir.h\"\n+#include \"color.h\"\n \n struct config_source {\n \tstruct config_source *prev;\n@@ -990,6 +991,15 @@ int git_config_pathname(const char **dest, const char *var, const char *value)\n \treturn 0;\n }\n \n+int git_config_color(char **dest, const char *var, const char *value)\n+{\n+\tif (!value)\n+\t\treturn config_error_nonbool(var);\n+\tif (color_parse(value, *dest) < 0)\n+\t\treturn -1;\n+\treturn 0;\n+}\n+\n static int git_default_core_config(const char *var, const char *value)\n {\n \t/* This needs a better name */\ndiff --git a/config.h b/config.h\nindex a49d264416225..8f8ca6a9b0741 100644\n--- a/config.h\n+++ b/config.h\n@@ -72,6 +72,7 @@ extern int git_config_rename_section(const char *, const char *);\n extern int git_config_rename_section_in_file(const char *, const char *, const char *);\n extern int git_config_copy_section(const char *, const char *);\n extern int git_config_copy_section_in_file(const char *, const char *, const char *);\n+extern int git_config_color(char ** dest, const char *var, const char *value);\n extern const char *git_etc_gitconfig(void);\n extern int git_env_bool(const char *, int);\n extern unsigned long git_env_ulong(const char *, unsigned long);\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex 364a537000bbb..b5804ab05ee3a 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -1558,4 +1558,165 @@ test_expect_success '--local requires a repo' '\n \ttest_expect_code 128 nongit git config --local foo.bar\n '\n \n+boolean()\n+{\n+\tslot=${3:-no.such.slot} &&\n+\tactual=$(git config --default \"$1\" --bool \"$slot\") &&\n+\ttest \"$actual\" = \"$2\"\n+}\n+\n+invalid_boolean()\n+{\n+\tslot=${2:-no.such.slot} &&\n+\ttest_must_fail git config --default \"$1\" --bool \"$slot\"\n+}\n+\n+test_expect_success 'empty value for boolean' '\n+\tboolean \"\" \"false\"\n+'\n+\n+test_expect_success 'true' '\n+\tboolean \"true\" \"true\"\n+'\n+\n+test_expect_success '1 is true' '\n+\tboolean \"1\" \"true\"\n+'\n+\n+test_expect_success 'non-zero is true' '\n+\tboolean \"5312\" \"true\"\n+'\n+\n+test_expect_success 'false' '\n+\tboolean \"false\" \"false\"\n+'\n+\n+test_expect_success '0 is false' '\n+\tboolean \"0\" \"false\"\n+'\n+\n+test_expect_success 'invalid value' '\n+\tinvalid_boolean \"ab\"\n+'\n+\n+test_expect_success 'existing slot has priority = true' '\n+\tgit config bool.value true &&\n+\tboolean \"false\" \"true\" \"bool.value\"\n+'\n+\n+test_expect_success 'existing slot has priority = false' '\n+\tgit config bool.value false &&\n+\tboolean \"true\" \"false\" \"bool.value\"\n+'\n+\n+int()\n+{\n+\tslot=${3:-no.such.slot} &&\n+\tactual=$(git config --default \"$1\" --int \"$slot\") &&\n+\ttest \"$actual\" = \"$2\"\n+}\n+\n+invalid_int()\n+{\n+\tslot=${2:-no.such.slot} &&\n+\ttest_must_fail git config \"$1\" --int \"$slot\"\n+}\n+\n+test_expect_success 'empty value for int' '\n+\tinvalid_int \"\" \"\"\n+'\n+\n+test_expect_success 'positive' '\n+\tint \"12345\" \"12345\"\n+'\n+\n+test_expect_success 'negative' '\n+\tint \"-679032\" \"-679032\"\n+'\n+\n+test_expect_success 'invalid value' '\n+\tinvalid_int \"abc\"\n+'\n+test_expect_success 'existing slot has priority = 123' '\n+\tgit config int.value 123 &&\n+\tint \"666\" \"123\" \"int.value\"\n+'\n+\n+test_expect_success 'existing slot with bad value' '\n+\tgit config int.value abc &&\n+\tinvalid_int \"123\" \"int.value\"\n+'\n+\n+path()\n+{\n+\tslot=${3:-no.such.slot} &&\n+\tactual=$(git config --default \"$1\" --path \"$slot\") &&\n+\ttest \"$actual\" = \"$2\"\n+}\n+\n+invalid_path()\n+{\n+\tslot=${2:-no.such.slot} &&\n+\ttest_must_fail git config \"$1\" --path \"$slot\"\n+}\n+\n+test_expect_success 'empty path is invalid' '\n+\tinvalid_path \"\" \"\"\n+'\n+\n+test_expect_success 'valid path' '\n+\tpath \"/aa/bb/cc\" \"/aa/bb/cc\"\n+'\n+\n+test_expect_success 'existing slot has priority = /to/the/moon' '\n+\tgit config path.value /to/the/moon &&\n+\tpath \"/to/the/sun\" \"/to/the/moon\" \"path.value\"\n+'\n+ESC=$(printf '\\033')\n+\n+color()\n+{\n+\tslot=${3:-no.such.slot} &&\n+\tactual=$(git config --default \"$1\" --color \"$slot\" ) &&\n+\ttest \"$actual\" = \"${2:+$ESC}$2\"\n+}\n+\n+invalid_color()\n+{\n+\tslot=${2:-no.such.slot} &&\n+\ttest_must_fail git config --default \"$1\" --color \"$slot\"\n+}\n+\n+test_expect_success 'reset' '\n+\tcolor \"reset\" \"[m\"\n+'\n+\n+test_expect_success 'empty color is empty' '\n+\tcolor \"\" \"\"\n+'\n+\n+test_expect_success 'absurdly long color specification' '\n+\tcolor \\\n+\t  \"#ffffff #ffffff bold nobold dim nodim italic noitalic\n+\t   ul noul blink noblink reverse noreverse strike nostrike\" \\\n+\t  \"[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m\"\n+'\n+\n+test_expect_success 'color too small' '\n+\tinvalid_color \"-2\"\n+'\n+\n+test_expect_success 'color too big' '\n+\tinvalid_color \"256\"\n+'\n+\n+test_expect_success 'extra character after color name' '\n+\tinvalid_color \"redX\"\n+'\n+\n+test_expect_success 'existing slot has priority = red' '\n+\tgit config color.value red &&\n+\tcolor \"blue\" \"[31m\" \"color.value\"\n+'\n+\n test_done\n\n--\nhttps://github.com/git/git/pull/431\n"},{"id":"333967","messageId":"2F0DEC42CD974A5581860DB9CA2944CA@PhilipOakley","threadId":"47180","inReplyTo":"0102016004959a28-410f021b-ac2b-4756-8e55-244071c074b5-000000@eu-west-1.amazonses.com","subject":"Re: [add-default-config] add --default option to git config.","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":null,"receivedAt":"2017-12-02T20:33:52Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"From: \"Soukaina NAIT HMID\" <nhsoukaina@gmail.com>\n> From: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n>\n\nFrom a coursory read, there does need a bit more explanation.\n\nI see you also add a --color description and code, and don't say what the \nproblem being solved is.\n\nIf it is trickty to explain, then a two patch series may tease apart the \nissues. perhaps add the --color option first (noting you'll use it in the \nnext patch), then a second patch that explains about the --default problem.\n\nThe patch title should be something like \"[PATCH 1/n] config: add --default \noption\"\n\nYou may also want to explain the test rationale, and maybe split them if \nappropriate.\n\n--\nPhilip\n\n\n> Signed-off-by: Soukaina NAIT HMID <snaithmid@bloomberg.net>\n> ---\n> Documentation/git-config.txt |   4 ++\n> builtin/config.c             |  34 ++++++++-\n> config.c                     |  10 +++\n> config.h                     |   1 +\n> t/t1300-repo-config.sh       | 161 \n> +++++++++++++++++++++++++++++++++++++++++++\n> 5 files changed, 209 insertions(+), 1 deletion(-)\n>\n> diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt\n> index 4edd09fc6b074..5d5cd58fdae37 100644\n> --- a/Documentation/git-config.txt\n> +++ b/Documentation/git-config.txt\n> @@ -179,6 +179,10 @@ See also <<FILES>>.\n>  specified user.  This option has no effect when setting the\n>  value (but you can use `git config section.variable ~/`\n>  from the command line to let your shell do the expansion).\n> +--color::\n> + Find the color configured for `name` (e.g. `color.diff.new`) and\n> + output it as the ANSI color escape sequence to the standard\n> + output.\n>\n> -z::\n> --null::\n> diff --git a/builtin/config.c b/builtin/config.c\n> index d13daeeb55927..5e5b998b7c892 100644\n> --- a/builtin/config.c\n> +++ b/builtin/config.c\n> @@ -30,6 +30,7 @@ static int end_null;\n> static int respect_includes_opt = -1;\n> static struct config_options config_options;\n> static int show_origin;\n> +static const char *default_value;\n>\n> #define ACTION_GET (1<<0)\n> #define ACTION_GET_ALL (1<<1)\n> @@ -52,6 +53,8 @@ static int show_origin;\n> #define TYPE_INT (1<<1)\n> #define TYPE_BOOL_OR_INT (1<<2)\n> #define TYPE_PATH (1<<3)\n> +#define TYPE_COLOR (1<<4)\n> +\n>\n> static struct option builtin_config_options[] = {\n>  OPT_GROUP(N_(\"Config file location\")),\n> @@ -80,11 +83,13 @@ static struct option builtin_config_options[] = {\n>  OPT_BIT(0, \"int\", &types, N_(\"value is decimal number\"), TYPE_INT),\n>  OPT_BIT(0, \"bool-or-int\", &types, N_(\"value is --bool or --int\"), \n> TYPE_BOOL_OR_INT),\n>  OPT_BIT(0, \"path\", &types, N_(\"value is a path (file or directory \n> name)\"), TYPE_PATH),\n> + OPT_BIT(0, \"color\", &types, N_(\"find the color configured\"), \n> TYPE_COLOR),\n>  OPT_GROUP(N_(\"Other\")),\n>  OPT_BOOL('z', \"null\", &end_null, N_(\"terminate values with NUL byte\")),\n>  OPT_BOOL(0, \"name-only\", &omit_values, N_(\"show variable names only\")),\n>  OPT_BOOL(0, \"includes\", &respect_includes_opt, N_(\"respect include \n> directives on lookup\")),\n>  OPT_BOOL(0, \"show-origin\", &show_origin, N_(\"show origin of config (file, \n> standard input, blob, command line)\")),\n> + OPT_STRING(0, \"default\", &default_value, N_(\"default-value\"), N_(\"sets \n> default value when no value is returned from config\")),\n>  OPT_END(),\n> };\n>\n> @@ -159,6 +164,13 @@ static int format_config(struct strbuf *buf, const \n> char *key_, const char *value\n>  return -1;\n>  strbuf_addstr(buf, v);\n>  free((char *)v);\n> + }\n> + else if (types == TYPE_COLOR) {\n> + char *v = xmalloc(COLOR_MAXLEN);\n> + if (git_config_color(&v, key_, value_) < 0)\n> + return -1;\n> + strbuf_addstr(buf, v);\n> + free((char *)v);\n>  } else if (value_) {\n>  strbuf_addstr(buf, value_);\n>  } else {\n> @@ -244,8 +256,16 @@ static int get_value(const char *key_, const char \n> *regex_)\n>  config_with_options(collect_config, &values,\n>      &given_config_source, &config_options);\n>\n> - ret = !values.nr;\n> + if (!values.nr && default_value && types) {\n> + struct strbuf *item;\n> + ALLOC_GROW(values.items, values.nr + 1, values.alloc);\n> + item = &values.items[values.nr++];\n> + if(format_config(item, key_, default_value) < 0){\n> + values.nr = 0;\n> + }\n> + }\n>\n> + ret = !values.nr;\n>  for (i = 0; i < values.nr; i++) {\n>  struct strbuf *buf = values.items + i;\n>  if (do_all || i == values.nr - 1)\n> @@ -268,6 +288,7 @@ static int get_value(const char *key_, const char \n> *regex_)\n>  return ret;\n> }\n>\n> +\n> static char *normalize_value(const char *key, const char *value)\n> {\n>  if (!value)\n> @@ -281,6 +302,17 @@ static char *normalize_value(const char *key, const \n> char *value)\n>  * when retrieving the value.\n>  */\n>  return xstrdup(value);\n> + if (types == TYPE_COLOR)\n> + {\n> + char *v = xmalloc(COLOR_MAXLEN);\n> + if (git_config_color(&v, key, value) == 0)\n> + {\n> + free((char *)v);\n> + return xstrdup(value);\n> + }\n> + free((char *)v);\n> + die(\"cannot parse color '%s'\", value);\n> + }\n>  if (types == TYPE_INT)\n>  return xstrfmt(\"%\"PRId64, git_config_int64(key, value));\n>  if (types == TYPE_BOOL)\n> diff --git a/config.c b/config.c\n> index 903abf9533b18..5c5daffeb6723 100644\n> --- a/config.c\n> +++ b/config.c\n> @@ -16,6 +16,7 @@\n> #include \"string-list.h\"\n> #include \"utf8.h\"\n> #include \"dir.h\"\n> +#include \"color.h\"\n>\n> struct config_source {\n>  struct config_source *prev;\n> @@ -990,6 +991,15 @@ int git_config_pathname(const char **dest, const char \n> *var, const char *value)\n>  return 0;\n> }\n>\n> +int git_config_color(char **dest, const char *var, const char *value)\n> +{\n> + if (!value)\n> + return config_error_nonbool(var);\n> + if (color_parse(value, *dest) < 0)\n> + return -1;\n> + return 0;\n> +}\n> +\n> static int git_default_core_config(const char *var, const char *value)\n> {\n>  /* This needs a better name */\n> diff --git a/config.h b/config.h\n> index a49d264416225..8f8ca6a9b0741 100644\n> --- a/config.h\n> +++ b/config.h\n> @@ -72,6 +72,7 @@ extern int git_config_rename_section(const char *, const \n> char *);\n> extern int git_config_rename_section_in_file(const char *, const char *, \n> const char *);\n> extern int git_config_copy_section(const char *, const char *);\n> extern int git_config_copy_section_in_file(const char *, const char *, \n> const char *);\n> +extern int git_config_color(char ** dest, const char *var, const char \n> *value);\n> extern const char *git_etc_gitconfig(void);\n> extern int git_env_bool(const char *, int);\n> extern unsigned long git_env_ulong(const char *, unsigned long);\n> diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\n> index 364a537000bbb..b5804ab05ee3a 100755\n> --- a/t/t1300-repo-config.sh\n> +++ b/t/t1300-repo-config.sh\n> @@ -1558,4 +1558,165 @@ test_expect_success '--local requires a repo' '\n>  test_expect_code 128 nongit git config --local foo.bar\n> '\n>\n> +boolean()\n> +{\n> + slot=${3:-no.such.slot} &&\n> + actual=$(git config --default \"$1\" --bool \"$slot\") &&\n> + test \"$actual\" = \"$2\"\n> +}\n> +\n> +invalid_boolean()\n> +{\n> + slot=${2:-no.such.slot} &&\n> + test_must_fail git config --default \"$1\" --bool \"$slot\"\n> +}\n> +\n> +test_expect_success 'empty value for boolean' '\n> + boolean \"\" \"false\"\n> +'\n> +\n> +test_expect_success 'true' '\n> + boolean \"true\" \"true\"\n> +'\n> +\n> +test_expect_success '1 is true' '\n> + boolean \"1\" \"true\"\n> +'\n> +\n> +test_expect_success 'non-zero is true' '\n> + boolean \"5312\" \"true\"\n> +'\n> +\n> +test_expect_success 'false' '\n> + boolean \"false\" \"false\"\n> +'\n> +\n> +test_expect_success '0 is false' '\n> + boolean \"0\" \"false\"\n> +'\n> +\n> +test_expect_success 'invalid value' '\n> + invalid_boolean \"ab\"\n> +'\n> +\n> +test_expect_success 'existing slot has priority = true' '\n> + git config bool.value true &&\n> + boolean \"false\" \"true\" \"bool.value\"\n> +'\n> +\n> +test_expect_success 'existing slot has priority = false' '\n> + git config bool.value false &&\n> + boolean \"true\" \"false\" \"bool.value\"\n> +'\n> +\n> +int()\n> +{\n> + slot=${3:-no.such.slot} &&\n> + actual=$(git config --default \"$1\" --int \"$slot\") &&\n> + test \"$actual\" = \"$2\"\n> +}\n> +\n> +invalid_int()\n> +{\n> + slot=${2:-no.such.slot} &&\n> + test_must_fail git config \"$1\" --int \"$slot\"\n> +}\n> +\n> +test_expect_success 'empty value for int' '\n> + invalid_int \"\" \"\"\n> +'\n> +\n> +test_expect_success 'positive' '\n> + int \"12345\" \"12345\"\n> +'\n> +\n> +test_expect_success 'negative' '\n> + int \"-679032\" \"-679032\"\n> +'\n> +\n> +test_expect_success 'invalid value' '\n> + invalid_int \"abc\"\n> +'\n> +test_expect_success 'existing slot has priority = 123' '\n> + git config int.value 123 &&\n> + int \"666\" \"123\" \"int.value\"\n> +'\n> +\n> +test_expect_success 'existing slot with bad value' '\n> + git config int.value abc &&\n> + invalid_int \"123\" \"int.value\"\n> +'\n> +\n> +path()\n> +{\n> + slot=${3:-no.such.slot} &&\n> + actual=$(git config --default \"$1\" --path \"$slot\") &&\n> + test \"$actual\" = \"$2\"\n> +}\n> +\n> +invalid_path()\n> +{\n> + slot=${2:-no.such.slot} &&\n> + test_must_fail git config \"$1\" --path \"$slot\"\n> +}\n> +\n> +test_expect_success 'empty path is invalid' '\n> + invalid_path \"\" \"\"\n> +'\n> +\n> +test_expect_success 'valid path' '\n> + path \"/aa/bb/cc\" \"/aa/bb/cc\"\n> +'\n> +\n> +test_expect_success 'existing slot has priority = /to/the/moon' '\n> + git config path.value /to/the/moon &&\n> + path \"/to/the/sun\" \"/to/the/moon\" \"path.value\"\n> +'\n> +ESC=$(printf '\\033')\n> +\n> +color()\n> +{\n> + slot=${3:-no.such.slot} &&\n> + actual=$(git config --default \"$1\" --color \"$slot\" ) &&\n> + test \"$actual\" = \"${2:+$ESC}$2\"\n> +}\n> +\n> +invalid_color()\n> +{\n> + slot=${2:-no.such.slot} &&\n> + test_must_fail git config --default \"$1\" --color \"$slot\"\n> +}\n> +\n> +test_expect_success 'reset' '\n> + color \"reset\" \"[m\"\n> +'\n> +\n> +test_expect_success 'empty color is empty' '\n> + color \"\" \"\"\n> +'\n> +\n> +test_expect_success 'absurdly long color specification' '\n> + color \\\n> +   \"#ffffff #ffffff bold nobold dim nodim italic noitalic\n> +    ul noul blink noblink reverse noreverse strike nostrike\" \\\n> +   \"[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m\"\n> +'\n> +\n> +test_expect_success 'color too small' '\n> + invalid_color \"-2\"\n> +'\n> +\n> +test_expect_success 'color too big' '\n> + invalid_color \"256\"\n> +'\n> +\n> +test_expect_success 'extra character after color name' '\n> + invalid_color \"redX\"\n> +'\n> +\n> +test_expect_success 'existing slot has priority = red' '\n> + git config color.value red &&\n> + color \"blue\" \"[31m\" \"color.value\"\n> +'\n> +\n> test_done\n>\n> --\n> https://github.com/git/git/pull/431 \n\n"}]}