From: "Chris Howlett via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Chris Howlett <chowlett09@gmail.com>,
Chris Howlett <chowlett09@gmail.com>
Subject: [PATCH] help: add prompt-yes setting for autocorrect
Date: Wed, 15 Jan 2025 09:36:55 +0000 [thread overview]
Message-ID: <pull.1852.git.1736933815236.gitgitgadget@gmail.com> (raw)
From: Chris Howlett <chowlett09@gmail.com>
The help.autocorrect functionality is really useful, saving frustration
when a dev fat-fingers a command, and git has a pretty good idea what
was originally intended. The config settings are a nice selection, with
"prompt" asking the user to confirm that they want to run the assumed
command.
However, with "prompt", the choice defaults to "No" - that is, hitting
return will _not_ run the command. For me at least, if git is confident
it knows which command I wanted, it's usually right, and the golden path
would be to run the command.
Therefore this patch adds "prompt-yes" as a counterpart config setting
for help.autocorrect, which does the same as "prompt", but defaults to
"Yes" - hitting return will run the assumed command.
I have not added any tests because the test suite doesn't have any tests
(that I could find) for the "prompt" behaviour - I'm assuming this is
because it's hard/impossible to simulate the interactive terminal prompt
Signed-off-by: Chris Howlett <chowlett09@gmail.com>
---
Add prompt-yes config setting for help.autocorrect
This is my first patch request to git - please do let me know if I
should be doing something differently!
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1852%2Fasilano%2Fautocorrect-allow-prompt-default-yes-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1852/asilano/autocorrect-allow-prompt-default-yes-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1852
Documentation/config/help.txt | 4 +++-
help.c | 15 +++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/Documentation/config/help.txt b/Documentation/config/help.txt
index 610701f9a37..50ce57892cb 100644
--- a/Documentation/config/help.txt
+++ b/Documentation/config/help.txt
@@ -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::
diff --git a/help.c b/help.c
index 5483ea8fd29..6a28011cb50 100644
--- a/help.c
+++ b/help.c
@@ -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)
@@ -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)
@@ -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);
@@ -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, "
base-commit: fbe8d3079d4a96aeb4e4529cc93cc0043b759a05
--
gitgitgadget
next reply other threads:[~2025-01-15 9:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-15 9:36 Chris Howlett via GitGitGadget [this message]
2025-01-15 9:51 ` [PATCH] help: add prompt-yes setting for autocorrect Kristoffer Haugsbakk
2025-01-15 10:21 ` Chris Howlett
2025-01-15 17:40 ` Kristoffer Haugsbakk
2025-02-17 14:19 ` [PATCH v2] " Chris Howlett via GitGitGadget
[not found] ` <pull.1852.v2.git.1739801702034.gitgitgadget@gmail.com>
2025-03-04 21:41 ` [PREVIEW " Chris Howlett
2025-03-04 22:33 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1852.git.1736933815236.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=chowlett09@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.