diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-10-02 12:26:12 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-10-02 12:26:12 -0700 |
| commit | 2ddbf1431dd3419e0857375724e96c6449575fc6 (patch) | |
| tree | 1bb14506ddb9052397d6910cd258a275970b133e /builtin | |
| parent | f2d464b9f5a3983b3c5208ae41c81de6b2fdc4cf (diff) | |
| parent | e4dabf4fd62470f03b5aa3f1ad615cd7121cb5c5 (diff) | |
| download | git-2ddbf1431dd3419e0857375724e96c6449575fc6.tar.gz | |
Merge branch 'ps/config-get-color-fixes'
The use of "git config get" command to learn how ANSI color
sequence is for a particular type, e.g., "git config get
--type=color --default=reset no.such.thing", isn't very ergonomic.
* ps/config-get-color-fixes:
builtin/config: do not spawn pager when printing color codes
builtin/config: special-case retrieving colors without a key
builtin/config: do not die in `get_color()`
t1300: small style fixups
t1300: write test expectations in the test's body
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/config.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/builtin/config.c b/builtin/config.c index 2348a99dd4..75852bd79d 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -547,24 +547,31 @@ static int git_get_color_config(const char *var, const char *value, return 0; } -static void get_color(const struct config_location_options *opts, +static int get_color(const struct config_location_options *opts, const char *var, const char *def_color) { struct get_color_config_data data = { .get_color_slot = var, .parsed_color[0] = '\0', }; + int ret; config_with_options(git_get_color_config, &data, &opts->source, the_repository, &opts->options); if (!data.get_color_found && def_color) { - if (color_parse(def_color, data.parsed_color) < 0) - die(_("unable to parse default color value")); + if (color_parse(def_color, data.parsed_color) < 0) { + ret = error(_("unable to parse default color value")); + goto out; + } } + ret = 0; + +out: fputs(data.parsed_color, stdout); + return ret; } struct get_colorbool_config_data { @@ -913,10 +920,13 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix, location_options_init(&location_opts, prefix); display_options_init(&display_opts); - setup_auto_pager("config", 1); + if (display_opts.type != TYPE_COLOR) + setup_auto_pager("config", 1); if (url) ret = get_urlmatch(&location_opts, &display_opts, argv[0], url); + else if (display_opts.type == TYPE_COLOR && !strlen(argv[0]) && display_opts.default_value) + ret = get_color(&location_opts, "", display_opts.default_value); else ret = get_value(&location_opts, &display_opts, argv[0], value_pattern, get_value_flags, flags); @@ -1391,7 +1401,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_GET_COLOR) { check_argc(argc, 1, 2); - get_color(&location_opts, argv[0], argv[1]); + ret = get_color(&location_opts, argv[0], argv[1]); } else if (actions == ACTION_GET_COLORBOOL) { check_argc(argc, 1, 2); |
