@@ -69,8 +69,8 @@ static struct option builtin_config_options[] = {
6969 OPT_BIT (0 , "remove-section" , & actions , N_ ("remove a section: name" ), ACTION_REMOVE_SECTION ),
7070 OPT_BIT ('l' , "list" , & actions , N_ ("list all" ), ACTION_LIST ),
7171 OPT_BIT ('e' , "edit" , & actions , N_ ("open an editor" ), ACTION_EDIT ),
72- OPT_STRING (0 , "get-color" , & get_color_slot , N_ ("slot" ), N_ ( " find the color configured: [default]" )),
73- OPT_STRING (0 , "get-colorbool" , & get_colorbool_slot , N_ ("slot" ), N_ ( " find the color setting: [stdout-is-tty]" )),
72+ OPT_BIT (0 , "get-color" , & actions , N_ ("find the color configured: slot [default]" ), ACTION_GET_COLOR ),
73+ OPT_BIT (0 , "get-colorbool" , & actions , N_ ("find the color setting: slot [stdout-is-tty]" ), ACTION_GET_COLORBOOL ),
7474 OPT_GROUP (N_ ("Type" )),
7575 OPT_BIT (0 , "bool" , & types , N_ ("value is \"true\" or \"false\"" ), TYPE_BOOL ),
7676 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)
303303 return 0 ;
304304}
305305
306- static void get_color (const char * def_color )
306+ static void get_color (const char * var , const char * def_color )
307307{
308+ get_color_slot = var ;
308309 get_color_found = 0 ;
309310 parsed_color [0 ] = '\0' ;
310311 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,
333334 return 0 ;
334335}
335336
336- static int get_colorbool (int print )
337+ static int get_colorbool (const char * var , int print )
337338{
339+ get_colorbool_slot = var ;
338340 get_colorbool_found = -1 ;
339341 get_diff_color_found = -1 ;
340342 get_color_ui_found = -1 ;
@@ -532,12 +534,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
532534 usage_with_options (builtin_config_usage , builtin_config_options );
533535 }
534536
535- if (get_color_slot )
536- actions |= ACTION_GET_COLOR ;
537- if (get_colorbool_slot )
538- actions |= ACTION_GET_COLORBOOL ;
539-
540- if ((get_color_slot || get_colorbool_slot ) && types ) {
537+ if ((actions & (ACTION_GET_COLOR |ACTION_GET_COLORBOOL )) && types ) {
541538 error ("--get-color and variable type are incoherent" );
542539 usage_with_options (builtin_config_usage , builtin_config_options );
543540 }
@@ -683,12 +680,14 @@ int cmd_config(int argc, const char **argv, const char *prefix)
683680 die ("No such section!" );
684681 }
685682 else if (actions == ACTION_GET_COLOR ) {
686- get_color (argv [0 ]);
683+ check_argc (argc , 1 , 2 );
684+ get_color (argv [0 ], argv [1 ]);
687685 }
688686 else if (actions == ACTION_GET_COLORBOOL ) {
689- if (argc == 1 )
690- color_stdout_is_tty = git_config_bool ("command line" , argv [0 ]);
691- return get_colorbool (argc != 0 );
687+ check_argc (argc , 1 , 2 );
688+ if (argc == 2 )
689+ color_stdout_is_tty = git_config_bool ("command line" , argv [1 ]);
690+ return get_colorbool (argv [0 ], argc == 2 );
692691 }
693692
694693 return 0 ;
0 commit comments