11#define USE_THE_REPOSITORY_VARIABLE
22#include "builtin.h"
33#include "abspath.h"
4+ #include "advice.h"
45#include "config.h"
56#include "color.h"
67#include "date.h"
@@ -210,6 +211,22 @@ static void check_argc(int argc, int min, int max)
210211 exit (129 );
211212}
212213
214+ static void advise_setting_with_equals (const char * key , const char * value )
215+ {
216+ const char * last_dot = strrchr (key , '.' );
217+ const char * eq ;
218+
219+ if (!last_dot )
220+ return ;
221+ eq = strchr (last_dot + 1 , '=' );
222+ if (!eq )
223+ return ;
224+ if (!value )
225+ value = eq + 1 ;
226+ advise (_ ("did you mean \"git config set %.*s %s\"?" ),
227+ (int )(eq - key ), key , value );
228+ }
229+
213230static void show_config_origin (const struct config_display_options * opts ,
214231 const struct key_value_info * kvi ,
215232 struct strbuf * buf )
@@ -1133,6 +1150,11 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix,
11331150
11341151 argc = parse_options (argc , argv , prefix , opts , builtin_config_set_usage ,
11351152 PARSE_OPT_STOP_AT_NON_OPTION );
1153+ if (argc == 1 && strchr (argv [0 ], '=' )) {
1154+ error (_ ("wrong number of arguments, should be 2" ));
1155+ advise_setting_with_equals (argv [0 ], NULL );
1156+ exit (129 );
1157+ }
11361158 check_argc (argc , 2 , 2 );
11371159
11381160 if ((flags & CONFIG_FLAGS_FIXED_VALUE ) && !value_pattern )
@@ -1160,6 +1182,8 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix,
11601182 error (_ ("cannot overwrite multiple values with a single value\n"
11611183 " Use --value=<pattern>, --append or --all to change %s." ), argv [0 ]);
11621184 }
1185+ if (ret == CONFIG_INVALID_KEY )
1186+ advise_setting_with_equals (argv [0 ], argv [1 ]);
11631187
11641188 location_options_release (& location_opts );
11651189 free (comment );
@@ -1371,6 +1395,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
13711395 };
13721396 char * value = NULL , * comment = NULL ;
13731397 int ret = 0 ;
1398+ int actions_implicit ;
13741399 struct key_value_info default_kvi = KVI_INIT ;
13751400
13761401 argc = parse_options (argc , argv , prefix , opts ,
@@ -1385,6 +1410,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
13851410 exit (129 );
13861411 }
13871412
1413+ actions_implicit = (actions == 0 );
13881414 if (actions == 0 )
13891415 switch (argc ) {
13901416 case 1 : actions = ACTION_GET ; break ;
@@ -1485,6 +1511,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
14851511 if (ret == CONFIG_NOTHING_SET )
14861512 error (_ ("cannot overwrite multiple values with a single value\n"
14871513 " Use a regexp, --add or --replace-all to change %s." ), argv [0 ]);
1514+ else if (ret == CONFIG_INVALID_KEY )
1515+ advise_setting_with_equals (argv [0 ], argv [1 ]);
14881516 }
14891517 else if (actions == ACTION_SET_ALL ) {
14901518 check_write (& location_opts .source );
@@ -1515,6 +1543,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
15151543 check_argc (argc , 1 , 2 );
15161544 ret = get_value (& location_opts , & display_opts , argv [0 ], argv [1 ],
15171545 0 , flags );
1546+ if (ret == CONFIG_INVALID_KEY && actions_implicit )
1547+ advise_setting_with_equals (argv [0 ], NULL );
15181548 }
15191549 else if (actions == ACTION_GET_ALL ) {
15201550 check_argc (argc , 1 , 2 );
0 commit comments