Skip to content

Commit 4e3dd47

Browse files
schacongitster
authored andcommitted
help: interpret boolean string values for help.autocorrect
A help.autocorrect value of 1 is currently interpreted as "wait 1 decisecond", which can be confusing to users who believe they are setting a boolean value to turn the autocorrect feature on. Interpret the value of help.autocorrect as either one of the accepted list of special values ("never", "immediate", ...), a boolean or an integer. If the value is 1, it is no longer interpreted as a decisecond value of 0.1s but as a true boolean, the equivalent of "immediate". If the value is 2 or more, continue treating it as a decisecond wait time. False boolean string values ("off", "false", "no") are now equivalent to "never", meaning that guessed values are still shown but nothing is executed. True boolean string values are interpreted as "immediate". Signed-off-by: Scott Chacon <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a60673e commit 4e3dd47

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

Documentation/config/help.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ help.autoCorrect::
1111
If git detects typos and can identify exactly one valid command similar
1212
to the error, git will try to suggest the correct command or even
1313
run the suggestion automatically. Possible config values are:
14-
- 0 (default): show the suggested command.
15-
- positive number: run the suggested command after specified
14+
- 0: show the suggested command (default).
15+
- 1, "true", "on", "yes", "immediate": run the suggested command
16+
immediately.
17+
- positive number > 1: run the suggested command after specified
1618
deciseconds (0.1 sec).
17-
- "immediate": run the suggested command immediately.
19+
- "false", "off", "no", "never": don't run or show any suggested command.
1820
- "prompt": show the suggestion and prompt for confirmation to run
1921
the command.
20-
- "never": don't run or show any suggested command.
2122

2223
help.htmlPath::
2324
Specify the path where the HTML documentation resides. File system paths

help.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,27 @@ struct help_unknown_cmd_config {
556556
#define AUTOCORRECT_NEVER (-2)
557557
#define AUTOCORRECT_IMMEDIATELY (-1)
558558

559+
static int parse_autocorrect(const char *value)
560+
{
561+
switch (git_parse_maybe_bool_text(value)) {
562+
case 1:
563+
return AUTOCORRECT_IMMEDIATELY;
564+
case 0:
565+
return AUTOCORRECT_NEVER;
566+
default: /* other random text */
567+
break;
568+
}
569+
570+
if (!strcmp(value, "prompt"))
571+
return AUTOCORRECT_PROMPT;
572+
if (!strcmp(value, "never"))
573+
return AUTOCORRECT_NEVER;
574+
if (!strcmp(value, "immediate"))
575+
return AUTOCORRECT_IMMEDIATELY;
576+
577+
return 0;
578+
}
579+
559580
static int git_unknown_cmd_config(const char *var, const char *value,
560581
const struct config_context *ctx,
561582
void *cb)
@@ -564,20 +585,17 @@ static int git_unknown_cmd_config(const char *var, const char *value,
564585
const char *p;
565586

566587
if (!strcmp(var, "help.autocorrect")) {
567-
if (!value)
568-
return config_error_nonbool(var);
569-
if (!strcmp(value, "never")) {
570-
cfg->autocorrect = AUTOCORRECT_NEVER;
571-
} else if (!strcmp(value, "immediate")) {
572-
cfg->autocorrect = AUTOCORRECT_IMMEDIATELY;
573-
} else if (!strcmp(value, "prompt")) {
574-
cfg->autocorrect = AUTOCORRECT_PROMPT;
575-
} else {
576-
int v = git_config_int(var, value, ctx->kvi);
577-
cfg->autocorrect = (v < 0)
578-
? AUTOCORRECT_IMMEDIATELY : v;
588+
int v = parse_autocorrect(value);
589+
590+
if (!v) {
591+
v = git_config_int(var, value, ctx->kvi);
592+
if (v < 0 || v == 1)
593+
v = AUTOCORRECT_IMMEDIATELY;
579594
}
595+
596+
cfg->autocorrect = v;
580597
}
598+
581599
/* Also use aliases for command lookup */
582600
if (skip_prefix(var, "alias.", &p))
583601
add_cmdname(&cfg->aliases, p, strlen(p));

0 commit comments

Comments
 (0)