help: add prompt-yes setting for autocorrect
PATCH 1/1 help: add prompt-yes setting for autocorrect
From: Chris Howlett <[email protected]>
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
---
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(-)
Documentation/config/help.txt +3 -1
@@ -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::
help.c +15 -0
@@ -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
Signature · 1 line
gitgitgadget
Quoted 17 lines · Chris Howlett via GitGitGadget
From: Chris Howlett <[email protected]>
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.
Quoted 5 lines
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 <[email protected]>
This seems to conflict with the patch “help: interpret boolean string values for help.autocorrect” which is in seen. The latest version (I don’t know what version is applied right now):
Quoted 23 lines · Kristoffer Haugsbakk
Quoted 21 lines · Chris Howlett via GitGitGadget
From: Chris Howlett <[email protected]>
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
Quoted 7 lines
Quoted 1 line
Signed-off-by Chris Howlett <[email protected]>This seems to conflict with the patch “help: interpret boolean string values for help.autocorrect” which is in
seen. The latest version (I don’t know what version is applied right now):
That's unsurprising, as I was inspired to add this option after reading that committer's blog post on help.autocorrect -
https://blog.gitbutler.com/why-is-git-autocorrect-too-fast-for-formula-one-drivers/
I'm happy to wait for their patch to be merged, then rebase and rework against it, if that seems the most sensible option? Presumably I'll have to monitor the mailing list to learn when that happens? This is my first patch to git, so I'm not sure of process.
Quoted 11 lines · Chris Howlett
On Wed, 15 Jan 2025 at 09:51, Kristoffer Haugsbakk
Quoted 1 line
[snip]
That's unsurprising, as I was inspired to add this option after reading that committer's blog post on help.autocorrect -
https://blog.gitbutler.com/why-is-git-autocorrect-too-fast-for-formula-one-drivers/I'm happy to wait for their patch to be merged, then rebase and rework against it, if that seems the most sensible option? Presumably I'll have to monitor the mailing list to learn when that happens? This is my first patch to git, so I'm not sure of process.
You can keep an eye on the “What's cooking” emails.[1] The latest one mentions this other topic as branch sc/help-autocorrect-one (that’s Scott Chacon’s initals followed by the topic name).
If you want to wait for that one to get merged:
• Wait until you see such an email with this “status” under it:
Will merge to 'master'.
Which means that it will be merged to master soon.
(Or maybe run
git branch --remote --contains=origin/sc/help-autocorrect-one \
| grep master
from time to time (I don’t know, I’ve never had to do that).)
Or else you could build on top of it. That’s more advanced though. Not something I’ve done myself.[2]
† 1: Latest: https://lore.kernel.org/git/[email protected]/
† 2: See `Documentation/SubmittingPatches under “select few topic
branches that are” for how to depend on in-flight topics
PATCH v2 1/1 help: add prompt-yes setting for autocorrect
In reply to Chris Howlett via GitGitGadgetFrom: Chris Howlett <[email protected]>
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
---
Add prompt-yes config setting for help.autocorrect
Changes since v1:
* PR rebased against master and fixed up, to account for e21bf2c and e4542d8
------------------------------------------------------------------------
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-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1852/asilano/autocorrect-allow-prompt-default-yes-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1852
Range-diff vs v1:
1: b87c772089e ! 1: cade4f1719e help: add prompt-yes setting for autocorrect
@@ Commit message
- ## Documentation/config/help.txt ##
-@@ Documentation/config/help.txt: help.autoCorrect::
+ ## Documentation/config/help.adoc ##
+@@ Documentation/config/help.adoc: immediately.
deciseconds (0.1 sec).
- - "immediate": run the suggested command immediately.
+ - "never": don't run or show any suggested command.
- "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::
+ Specify the path where the HTML documentation resides. File system paths
## help.c ##
@@ help.c: struct help_unknown_cmd_config {
struct cmdnames aliases;
};
-+#define AUTOCORRECT_PROMPT_YES (-4)
++#define AUTOCORRECT_PROMPT_YES (-5)
+ #define AUTOCORRECT_SHOW (-4)
#define AUTOCORRECT_PROMPT (-3)
#define AUTOCORRECT_NEVER (-2)
- #define AUTOCORRECT_IMMEDIATELY (-1)
-@@ help.c: 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)
+@@ help.c: static int parse_autocorrect(const char *value)
+
+ if (!strcmp(value, "prompt"))
+ return AUTOCORRECT_PROMPT;
++ if (!strcmp(value, "prompt-yes"))
++ return AUTOCORRECT_PROMPT_YES;
+ if (!strcmp(value, "never"))
+ return AUTOCORRECT_NEVER;
+ if (!strcmp(value, "immediate"))
@@ help.c: char *help_unknown_cmd(const char *cmd)
if ((cfg.autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))
cfg.autocorrect = AUTOCORRECT_NEVER;
Documentation/config/help.adoc | 4 +++- help.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-)
Documentation/config/help.adoc +3 -1
@@ -18,7 +18,9 @@ immediately. deciseconds (0.1 sec). - "never": don't run or show any suggested command. - "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" help.htmlPath:: Specify the path where the HTML documentation resides. File system paths
help.c +15 -0
@@ -552,6 +552,7 @@ struct help_unknown_cmd_config {struct cmdnames aliases; }; +#define AUTOCORRECT_PROMPT_YES (-5)#define AUTOCORRECT_SHOW (-4)#define AUTOCORRECT_PROMPT (-3)#define AUTOCORRECT_NEVER (-2)
@@ -570,6 +571,8 @@ static int parse_autocorrect(const char *value)if (!strcmp (value,"prompt" ))return AUTOCORRECT_PROMPT ; +if (!strcmp (value,"prompt-yes" )) +return AUTOCORRECT_PROMPT_YES ;if (!strcmp (value,"never" ))return AUTOCORRECT_NEVER ;if (!strcmp (value,"immediate" ))
@@ -650,6 +653,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 );
@@ -738,6 +744,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: 03944513488db4a81fdb4c21c3b515e4cb260b05
Signature · 1 line
gitgitgadget
I've not seen any interaction with this patch since I posted it a couple of weeks ago. Has it slipped under the radar, or is there no interest in the change?
Thanks!
Chris.
Quoted 168 lines · Chris Howlett via GitGitGadget
From: Chris Howlett <[email protected]>
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 <[email protected]>---
Add prompt-yes config setting for help.autocorrectChanges since v1:
* PR rebased against master and fixed up, to account for e21bf2c and e4542d8
------------------------------------------------------------------------
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-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1852/asilano/autocorrect-allow-prompt-default-yes-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1852Range-diff vs v1:
1:
b87c772089e! 1:cade4f1719ehelp: add prompt-yes setting for autocorrect
@@ Commit messageSigned-off-by Chris Howlett <[email protected]>- ##
Documentation/config/help.txt##
-@@Documentation/config/help.txt: help.autoCorrect::
+ ##Documentation/config/help.adoc##
+@@Documentation/config/help.adoc: immediately.
deciseconds (0.1 sec).
- - "immediate": run the suggested command immediately.
+ - "never": don't run or show any suggested command.
- "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::
+ Specify the path where the HTML documentation resides. File system paths##
help.c##
@@help.c: structhelp_unknown_cmd_config{
struct cmdnames aliases;
};-+#define
AUTOCORRECT_PROMPT_YES(-4)
++#defineAUTOCORRECT_PROMPT_YES(-5)
+ #defineAUTOCORRECT_SHOW(-4)
#defineAUTOCORRECT_PROMPT(-3)
#defineAUTOCORRECT_NEVER(-2)
- #defineAUTOCORRECT_IMMEDIATELY(-1)
-@@help.c: 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)
+@@help.c: static intparse_autocorrect(const char *value)
+
+ if (!strcmp(value, "prompt"))
+ returnAUTOCORRECT_PROMPT;
++ if (!strcmp(value, "prompt-yes"))
++ returnAUTOCORRECT_PROMPT_YES;
+ if (!strcmp(value, "never"))
+ returnAUTOCORRECT_NEVER;
+ if (!strcmp(value, "immediate"))
@@help.c: char *help_unknown_cmd(const char *cmd)
if ((cfg.autocorrect ==AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))
cfg.autocorrect =AUTOCORRECT_NEVER;Documentation/config/help.adoc | 4 +++- help.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-)Documentation/config/help.adoc +3
-1@@ -18,7 +18,9 @@ immediately. deciseconds (0.1 sec). - "never": don't run or show any suggested command. - "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" help.htmlPath:: Specify the path where the HTML documentation resides. File system pathshelp.c +15
-0@@ -552,6 +552,7 @@ struct help_unknown_cmd_config {struct cmdnames aliases; }; +#define AUTOCORRECT_PROMPT_YES (-5)#define AUTOCORRECT_SHOW (-4)#define AUTOCORRECT_PROMPT (-3)#define AUTOCORRECT_NEVER (-2)@@ -570,6 +571,8 @@ static int parse_autocorrect(const char *value)if (!strcmp (value,"prompt" ))return AUTOCORRECT_PROMPT ; +if (!strcmp (value,"prompt-yes" )) +return AUTOCORRECT_PROMPT_YES ;if (!strcmp (value,"never" ))return AUTOCORRECT_NEVER ;if (!strcmp (value,"immediate" ))@@ -650,6 +653,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 );@@ -738,6 +744,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:
03944513488db4a81fdb4c21c3b515e4cb260b05--
gitgitgadget
Quoted 3 lines · Chris Howlett
I've not seen any interaction with this patch since I posted it a couple of weeks ago. Has it slipped under the radar, or is there no interest in the change?
I personally do not find the cause so compelling, and am not myself interested in a patch that pretty much has to duplicate the lines needed to support existing AUTOCORRECT_PROMPT. But others may feel differently.
Around here, people do not react to everything they see, and some may change their mind when asked the same question twice with some interval in between, so it is a good idea to ping after some weeks to reconfirm.
Thanks for pinging.