Skip to content

Commit 2ddbf14

Browse files
committed
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
2 parents f2d464b + e4dabf4 commit 2ddbf14

File tree

2 files changed

+187
-182
lines changed

2 files changed

+187
-182
lines changed

builtin/config.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,24 +547,31 @@ static int git_get_color_config(const char *var, const char *value,
547547
return 0;
548548
}
549549

550-
static void get_color(const struct config_location_options *opts,
550+
static int get_color(const struct config_location_options *opts,
551551
const char *var, const char *def_color)
552552
{
553553
struct get_color_config_data data = {
554554
.get_color_slot = var,
555555
.parsed_color[0] = '\0',
556556
};
557+
int ret;
557558

558559
config_with_options(git_get_color_config, &data,
559560
&opts->source, the_repository,
560561
&opts->options);
561562

562563
if (!data.get_color_found && def_color) {
563-
if (color_parse(def_color, data.parsed_color) < 0)
564-
die(_("unable to parse default color value"));
564+
if (color_parse(def_color, data.parsed_color) < 0) {
565+
ret = error(_("unable to parse default color value"));
566+
goto out;
567+
}
565568
}
566569

570+
ret = 0;
571+
572+
out:
567573
fputs(data.parsed_color, stdout);
574+
return ret;
568575
}
569576

570577
struct get_colorbool_config_data {
@@ -913,10 +920,13 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix,
913920
location_options_init(&location_opts, prefix);
914921
display_options_init(&display_opts);
915922

916-
setup_auto_pager("config", 1);
923+
if (display_opts.type != TYPE_COLOR)
924+
setup_auto_pager("config", 1);
917925

918926
if (url)
919927
ret = get_urlmatch(&location_opts, &display_opts, argv[0], url);
928+
else if (display_opts.type == TYPE_COLOR && !strlen(argv[0]) && display_opts.default_value)
929+
ret = get_color(&location_opts, "", display_opts.default_value);
920930
else
921931
ret = get_value(&location_opts, &display_opts, argv[0], value_pattern,
922932
get_value_flags, flags);
@@ -1391,7 +1401,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
13911401
}
13921402
else if (actions == ACTION_GET_COLOR) {
13931403
check_argc(argc, 1, 2);
1394-
get_color(&location_opts, argv[0], argv[1]);
1404+
ret = get_color(&location_opts, argv[0], argv[1]);
13951405
}
13961406
else if (actions == ACTION_GET_COLORBOOL) {
13971407
check_argc(argc, 1, 2);

0 commit comments

Comments
 (0)