Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prompt-yes config setting for help.autocorrect #1852

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Documentation/config/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ help.autoCorrect::
deciseconds (0.1 sec).
- "immediate": run the suggested command immediately.
- "prompt": show the suggestion and prompt for confirmation to run
the command.
the command. The default choice at the prompt is "No"
- "prompt-yes": show the suggestion and prompt for confirmation to run
the command. The default choice at the prompt is "Yes"
- "never": don't run or show any suggested command.

help.htmlPath::
Expand Down
15 changes: 15 additions & 0 deletions help.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ struct help_unknown_cmd_config {
struct cmdnames aliases;
};

#define AUTOCORRECT_PROMPT_YES (-4)
#define AUTOCORRECT_PROMPT (-3)
#define AUTOCORRECT_NEVER (-2)
#define AUTOCORRECT_IMMEDIATELY (-1)
Expand All @@ -572,6 +573,8 @@ static int git_unknown_cmd_config(const char *var, const char *value,
cfg->autocorrect = AUTOCORRECT_IMMEDIATELY;
} else if (!strcmp(value, "prompt")) {
cfg->autocorrect = AUTOCORRECT_PROMPT;
} else if (!strcmp(value, "prompt-yes")) {
cfg->autocorrect = AUTOCORRECT_PROMPT_YES;
} else {
int v = git_config_int(var, value, ctx->kvi);
cfg->autocorrect = (v < 0)
Expand Down Expand Up @@ -629,6 +632,9 @@ char *help_unknown_cmd(const char *cmd)
if ((cfg.autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))
cfg.autocorrect = AUTOCORRECT_NEVER;

if ((cfg.autocorrect == AUTOCORRECT_PROMPT_YES) && (!isatty(0) || !isatty(2)))
cfg.autocorrect = AUTOCORRECT_IMMEDIATELY;

if (cfg.autocorrect == AUTOCORRECT_NEVER) {
fprintf_ln(stderr, _("git: '%s' is not a git command. See 'git --help'."), cmd);
exit(1);
Expand Down Expand Up @@ -716,6 +722,15 @@ char *help_unknown_cmd(const char *cmd)
if (!(starts_with(answer, "y") ||
starts_with(answer, "Y")))
exit(1);
} else if (cfg.autocorrect == AUTOCORRECT_PROMPT_YES) {
char *answer;
struct strbuf msg = STRBUF_INIT;
strbuf_addf(&msg, _("Run '%s' instead [Y/n]? "), assumed);
answer = git_prompt(msg.buf, PROMPT_ECHO);
strbuf_release(&msg);
if (starts_with(answer, "n") ||
starts_with(answer, "N"))
exit(1);
} else {
fprintf_ln(stderr,
_("Continuing in %0.1f seconds, "
Expand Down
Loading