Skip to content

Commit 39de0ff

Browse files
committed
Merge branch 'sc/help-autocorrect-one'
"[help] autocorrect = 1" used to be a way to say "please wait for 0.1 second after suggesting a typofix of the command name before running that command"; now it means "yes, if there is a plausible typofix for the command name, please run it immediately". * sc/help-autocorrect-one: help: interpret boolean string values for help.autocorrect
2 parents 0a99ffb + 4e3dd47 commit 39de0ff

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)