diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-12-22 12:16:58 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-12-22 12:16:58 -0800 |
commit | 5d509d5e1cf1feb9e218b431f4ea41b10e39d06e (patch) | |
tree | 7c40aabc32458afa6500d585abff62acf4163b5d | |
parent | 447c39a9b25e222a96711f7736078e4f33001388 (diff) | |
parent | cb357221a402c55b23bf99ec9f3b361709d45fa7 (diff) | |
download | git-5d509d5e1cf1feb9e218b431f4ea41b10e39d06e.tar.gz |
Merge branch 'jk/colors-fix' into maint
"git config --get-color" did not parse its command line arguments
carefully.
* jk/colors-fix:
t4026: test "normal" color
config: fix parsing of "git config --get-color some.key -1"
docs: describe ANSI 256-color mode
-rw-r--r-- | Documentation/config.txt | 4 | ||||
-rw-r--r-- | builtin/config.c | 27 | ||||
-rwxr-xr-x | t/t4026-color.sh | 8 |
3 files changed, 25 insertions, 14 deletions
diff --git a/Documentation/config.txt b/Documentation/config.txt index 302d61e76f..9335ff2ae2 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -850,6 +850,10 @@ accepted are `normal`, `black`, `red`, `green`, `yellow`, `blue`, `blink` and `reverse`. The first color given is the foreground; the second is the background. The position of the attribute, if any, doesn't matter. ++ +Colors (foreground and background) may also be given as numbers between +0 and 255; these use ANSI 256-color mode (but note that not all +terminals may support this). color.diff:: Whether to use ANSI escape sequences to add color to patches. diff --git a/builtin/config.c b/builtin/config.c index 8cc2604069..fddafbba36 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -69,8 +69,8 @@ static struct option builtin_config_options[] = { OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), - OPT_STRING(0, "get-color", &get_color_slot, N_("slot"), N_("find the color configured: [default]")), - OPT_STRING(0, "get-colorbool", &get_colorbool_slot, N_("slot"), N_("find the color setting: [stdout-is-tty]")), + OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), + OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), OPT_GROUP(N_("Type")), OPT_BIT(0, "bool", &types, N_("value is \"true\" or \"false\""), TYPE_BOOL), OPT_BIT(0, "int", &types, N_("value is decimal number"), TYPE_INT), @@ -303,8 +303,9 @@ static int git_get_color_config(const char *var, const char *value, void *cb) return 0; } -static void get_color(const char *def_color) +static void get_color(const char *var, const char *def_color) { + get_color_slot = var; get_color_found = 0; parsed_color[0] = '\0'; git_config_with_options(git_get_color_config, NULL, @@ -333,8 +334,9 @@ static int git_get_colorbool_config(const char *var, const char *value, return 0; } -static int get_colorbool(int print) +static int get_colorbool(const char *var, int print) { + get_colorbool_slot = var; get_colorbool_found = -1; get_diff_color_found = -1; get_color_ui_found = -1; @@ -532,12 +534,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_with_options(builtin_config_usage, builtin_config_options); } - if (get_color_slot) - actions |= ACTION_GET_COLOR; - if (get_colorbool_slot) - actions |= ACTION_GET_COLORBOOL; - - if ((get_color_slot || get_colorbool_slot) && types) { + if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && types) { error("--get-color and variable type are incoherent"); usage_with_options(builtin_config_usage, builtin_config_options); } @@ -683,12 +680,14 @@ int cmd_config(int argc, const char **argv, const char *prefix) die("No such section!"); } else if (actions == ACTION_GET_COLOR) { - get_color(argv[0]); + check_argc(argc, 1, 2); + get_color(argv[0], argv[1]); } else if (actions == ACTION_GET_COLORBOOL) { - if (argc == 1) - color_stdout_is_tty = git_config_bool("command line", argv[0]); - return get_colorbool(argc != 0); + check_argc(argc, 1, 2); + if (argc == 2) + color_stdout_is_tty = git_config_bool("command line", argv[1]); + return get_colorbool(argv[0], argc == 2); } return 0; diff --git a/t/t4026-color.sh b/t/t4026-color.sh index 3726a0e201..63e423838f 100755 --- a/t/t4026-color.sh +++ b/t/t4026-color.sh @@ -53,6 +53,14 @@ test_expect_success '256 colors' ' color "254 bold 255" "[1;38;5;254;48;5;255m" ' +test_expect_success '"normal" yields no color at all"' ' + color "normal black" "[40m" +' + +test_expect_success '-1 is a synonym for "normal"' ' + color "-1 black" "[40m" +' + test_expect_success 'color too small' ' invalid_color "-2" ' |