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.autocorrectmaint
commit
39de0ffbe3
|
@ -11,13 +11,14 @@ help.autoCorrect::
|
||||||
If git detects typos and can identify exactly one valid command similar
|
If git detects typos and can identify exactly one valid command similar
|
||||||
to the error, git will try to suggest the correct command or even
|
to the error, git will try to suggest the correct command or even
|
||||||
run the suggestion automatically. Possible config values are:
|
run the suggestion automatically. Possible config values are:
|
||||||
- 0 (default): show the suggested command.
|
- 0: show the suggested command (default).
|
||||||
- positive number: run the suggested command after specified
|
- 1, "true", "on", "yes", "immediate": run the suggested command
|
||||||
|
immediately.
|
||||||
|
- positive number > 1: run the suggested command after specified
|
||||||
deciseconds (0.1 sec).
|
deciseconds (0.1 sec).
|
||||||
- "immediate": run the suggested command immediately.
|
- "false", "off", "no", "never": don't run or show any suggested command.
|
||||||
- "prompt": show the suggestion and prompt for confirmation to run
|
- "prompt": show the suggestion and prompt for confirmation to run
|
||||||
the command.
|
the command.
|
||||||
- "never": don't run or show any suggested command.
|
|
||||||
|
|
||||||
help.htmlPath::
|
help.htmlPath::
|
||||||
Specify the path where the HTML documentation resides. File system paths
|
Specify the path where the HTML documentation resides. File system paths
|
||||||
|
|
42
help.c
42
help.c
|
@ -556,6 +556,27 @@ struct help_unknown_cmd_config {
|
||||||
#define AUTOCORRECT_NEVER (-2)
|
#define AUTOCORRECT_NEVER (-2)
|
||||||
#define AUTOCORRECT_IMMEDIATELY (-1)
|
#define AUTOCORRECT_IMMEDIATELY (-1)
|
||||||
|
|
||||||
|
static int parse_autocorrect(const char *value)
|
||||||
|
{
|
||||||
|
switch (git_parse_maybe_bool_text(value)) {
|
||||||
|
case 1:
|
||||||
|
return AUTOCORRECT_IMMEDIATELY;
|
||||||
|
case 0:
|
||||||
|
return AUTOCORRECT_NEVER;
|
||||||
|
default: /* other random text */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(value, "prompt"))
|
||||||
|
return AUTOCORRECT_PROMPT;
|
||||||
|
if (!strcmp(value, "never"))
|
||||||
|
return AUTOCORRECT_NEVER;
|
||||||
|
if (!strcmp(value, "immediate"))
|
||||||
|
return AUTOCORRECT_IMMEDIATELY;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int git_unknown_cmd_config(const char *var, const char *value,
|
static int git_unknown_cmd_config(const char *var, const char *value,
|
||||||
const struct config_context *ctx,
|
const struct config_context *ctx,
|
||||||
void *cb)
|
void *cb)
|
||||||
|
@ -564,20 +585,17 @@ static int git_unknown_cmd_config(const char *var, const char *value,
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if (!strcmp(var, "help.autocorrect")) {
|
if (!strcmp(var, "help.autocorrect")) {
|
||||||
if (!value)
|
int v = parse_autocorrect(value);
|
||||||
return config_error_nonbool(var);
|
|
||||||
if (!strcmp(value, "never")) {
|
if (!v) {
|
||||||
cfg->autocorrect = AUTOCORRECT_NEVER;
|
v = git_config_int(var, value, ctx->kvi);
|
||||||
} else if (!strcmp(value, "immediate")) {
|
if (v < 0 || v == 1)
|
||||||
cfg->autocorrect = AUTOCORRECT_IMMEDIATELY;
|
v = AUTOCORRECT_IMMEDIATELY;
|
||||||
} else if (!strcmp(value, "prompt")) {
|
|
||||||
cfg->autocorrect = AUTOCORRECT_PROMPT;
|
|
||||||
} else {
|
|
||||||
int v = git_config_int(var, value, ctx->kvi);
|
|
||||||
cfg->autocorrect = (v < 0)
|
|
||||||
? AUTOCORRECT_IMMEDIATELY : v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg->autocorrect = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Also use aliases for command lookup */
|
/* Also use aliases for command lookup */
|
||||||
if (skip_prefix(var, "alias.", &p))
|
if (skip_prefix(var, "alias.", &p))
|
||||||
add_cmdname(&cfg->aliases, p, strlen(p));
|
add_cmdname(&cfg->aliases, p, strlen(p));
|
||||||
|
|
Loading…
Reference in New Issue