{"thread":{"id":"62812","subject":"[PATCH] help: add prompt-yes setting for autocorrect","startedAt":"2025-01-15T09:36:58Z","lastAt":"2025-03-04T22:33:47Z","messageCount":7,"participants":["Chris Howlett via GitGitGadget","Kristoffer Haugsbakk","Chris Howlett","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"510562","messageId":"pull.1852.git.1736933815236.gitgitgadget@gmail.com","threadId":"62812","inReplyTo":null,"subject":"[PATCH] help: add prompt-yes setting for autocorrect","fromName":"Chris Howlett via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2025-01-15T09:36:55Z","receivedAt":"2025-01-15T09:36:58Z","isPatch":true,"sender":{"key":"chowlett09@gmail.com","avatar":"https://gravatar.com/avatar/b577ffbe67f2f1a56230f18c1040bce4527501f44858e9e7ce1559ee021abda4?d=mp&s=160"},"body":"From: Chris Howlett <chowlett09@gmail.com>\n\nThe help.autocorrect functionality is really useful, saving frustration\nwhen a dev fat-fingers a command, and git has a pretty good idea what\nwas originally intended. The config settings are a nice selection, with\n\"prompt\" asking the user to confirm that they want to run the assumed\ncommand.\n\nHowever, with \"prompt\", the choice defaults to \"No\" - that is, hitting\nreturn will _not_ run the command. For me at least, if git is confident\nit knows which command I wanted, it's usually right, and the golden path\nwould be to run the command.\n\nTherefore this patch adds \"prompt-yes\" as a counterpart config setting\nfor help.autocorrect, which does the same as \"prompt\", but defaults to\n\"Yes\" - hitting return will run the assumed command.\n\nI have not added any tests because the test suite doesn't have any tests\n(that I could find) for the \"prompt\" behaviour - I'm assuming this is\nbecause it's hard/impossible to simulate the interactive terminal prompt\n\nSigned-off-by: Chris Howlett <chowlett09@gmail.com>\n---\n    Add prompt-yes config setting for help.autocorrect\n    \n    This is my first patch request to git - please do let me know if I\n    should be doing something differently!\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1852%2Fasilano%2Fautocorrect-allow-prompt-default-yes-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1852/asilano/autocorrect-allow-prompt-default-yes-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1852\n\n Documentation/config/help.txt |  4 +++-\n help.c                        | 15 +++++++++++++++\n 2 files changed, 18 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config/help.txt b/Documentation/config/help.txt\nindex 610701f9a37..50ce57892cb 100644\n--- a/Documentation/config/help.txt\n+++ b/Documentation/config/help.txt\n@@ -16,7 +16,9 @@ help.autoCorrect::\n deciseconds (0.1 sec).\n \t - \"immediate\": run the suggested command immediately.\n \t - \"prompt\": show the suggestion and prompt for confirmation to run\n-the command.\n+the command. The default choice at the prompt is \"No\"\n+\t - \"prompt-yes\": show the suggestion and prompt for confirmation to run\n+the command. The default choice at the prompt is \"Yes\"\n \t - \"never\": don't run or show any suggested command.\n \n help.htmlPath::\ndiff --git a/help.c b/help.c\nindex 5483ea8fd29..6a28011cb50 100644\n--- a/help.c\n+++ b/help.c\n@@ -552,6 +552,7 @@ struct help_unknown_cmd_config {\n \tstruct cmdnames aliases;\n };\n \n+#define AUTOCORRECT_PROMPT_YES (-4)\n #define AUTOCORRECT_PROMPT (-3)\n #define AUTOCORRECT_NEVER (-2)\n #define AUTOCORRECT_IMMEDIATELY (-1)\n@@ -572,6 +573,8 @@ static int git_unknown_cmd_config(const char *var, const char *value,\n \t\t\tcfg->autocorrect = AUTOCORRECT_IMMEDIATELY;\n \t\t} else if (!strcmp(value, \"prompt\")) {\n \t\t\tcfg->autocorrect = AUTOCORRECT_PROMPT;\n+\t\t} else if (!strcmp(value, \"prompt-yes\")) {\n+\t\t\tcfg->autocorrect = AUTOCORRECT_PROMPT_YES;\n \t\t} else {\n \t\t\tint v = git_config_int(var, value, ctx->kvi);\n \t\t\tcfg->autocorrect = (v < 0)\n@@ -629,6 +632,9 @@ char *help_unknown_cmd(const char *cmd)\n \tif ((cfg.autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))\n \t\tcfg.autocorrect = AUTOCORRECT_NEVER;\n \n+\tif ((cfg.autocorrect == AUTOCORRECT_PROMPT_YES) && (!isatty(0) || !isatty(2)))\n+\t\tcfg.autocorrect = AUTOCORRECT_IMMEDIATELY;\n+\n \tif (cfg.autocorrect == AUTOCORRECT_NEVER) {\n \t\tfprintf_ln(stderr, _(\"git: '%s' is not a git command. See 'git --help'.\"), cmd);\n \t\texit(1);\n@@ -716,6 +722,15 @@ char *help_unknown_cmd(const char *cmd)\n \t\t\tif (!(starts_with(answer, \"y\") ||\n \t\t\t      starts_with(answer, \"Y\")))\n \t\t\t\texit(1);\n+\t\t} else if (cfg.autocorrect == AUTOCORRECT_PROMPT_YES) {\n+\t\t\tchar *answer;\n+\t\t\tstruct strbuf msg = STRBUF_INIT;\n+\t\t\tstrbuf_addf(&msg, _(\"Run '%s' instead [Y/n]? \"), assumed);\n+\t\t\tanswer = git_prompt(msg.buf, PROMPT_ECHO);\n+\t\t\tstrbuf_release(&msg);\n+\t\t\tif (starts_with(answer, \"n\") ||\n+\t\t\t      starts_with(answer, \"N\"))\n+\t\t\t\texit(1);\n \t\t} else {\n \t\t\tfprintf_ln(stderr,\n \t\t\t\t   _(\"Continuing in %0.1f seconds, \"\n\nbase-commit: fbe8d3079d4a96aeb4e4529cc93cc0043b759a05\n-- \ngitgitgadget\n"},{"id":"510563","messageId":"1c220376-4b4b-425f-9797-abd1728aacc2@app.fastmail.com","threadId":"62812","inReplyTo":"pull.1852.git.1736933815236.gitgitgadget@gmail.com","subject":"Re: [PATCH] help: add prompt-yes setting for autocorrect","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2025-01-15T09:51:25Z","receivedAt":"2025-01-15T09:51:56Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Wed, Jan 15, 2025, at 10:36, Chris Howlett via GitGitGadget wrote:\n> From: Chris Howlett <chowlett09@gmail.com>\n>\n> The help.autocorrect functionality is really useful, saving frustration\n> when a dev fat-fingers a command, and git has a pretty good idea what\n> was originally intended. The config settings are a nice selection, with\n> \"prompt\" asking the user to confirm that they want to run the assumed\n> command.\n>\n> However, with \"prompt\", the choice defaults to \"No\" - that is, hitting\n> return will _not_ run the command. For me at least, if git is confident\n> it knows which command I wanted, it's usually right, and the golden path\n> would be to run the command.\n>\n> Therefore this patch adds \"prompt-yes\" as a counterpart config setting\n> for help.autocorrect, which does the same as \"prompt\", but defaults to\n> \"Yes\" - hitting return will run the assumed command.\n>\n> I have not added any tests because the test suite doesn't have any tests\n> (that I could find) for the \"prompt\" behaviour - I'm assuming this is\n> because it's hard/impossible to simulate the interactive terminal prompt\n>\n> Signed-off-by: Chris Howlett <chowlett09@gmail.com>\n\nThis seems to conflict with the patch “help: interpret boolean string\nvalues for help.autocorrect” which is in `seen`.  The latest version (I\ndon’t know what version is applied right now):\n\nhttps://lore.kernel.org/git/pull.1869.v4.git.git.1736760824201.gitgitgadget@gmail.com/\n"},{"id":"510564","messageId":"CAJVagJ=3uxcCpEivkpW5_HTxdL9Sa9Ymqm1iJQHUJ+=9XneLSg@mail.gmail.com","threadId":"62812","inReplyTo":"1c220376-4b4b-425f-9797-abd1728aacc2@app.fastmail.com","subject":"Re: [PATCH] help: add prompt-yes setting for autocorrect","fromName":"Chris Howlett","fromEmail":"chowlett09@gmail.com","sentAt":"2025-01-15T10:21:38Z","receivedAt":"2025-01-15T10:21:49Z","isPatch":true,"sender":{"key":"chowlett09@gmail.com","avatar":"https://gravatar.com/avatar/b577ffbe67f2f1a56230f18c1040bce4527501f44858e9e7ce1559ee021abda4?d=mp&s=160"},"body":"On Wed, 15 Jan 2025 at 09:51, Kristoffer Haugsbakk\n<kristofferhaugsbakk@fastmail.com> wrote:\n>\n> On Wed, Jan 15, 2025, at 10:36, Chris Howlett via GitGitGadget wrote:\n> > From: Chris Howlett <chowlett09@gmail.com>\n> >\n> > The help.autocorrect functionality is really useful, saving frustration\n> > when a dev fat-fingers a command, and git has a pretty good idea what\n> > was originally intended. The config settings are a nice selection, with\n> > \"prompt\" asking the user to confirm that they want to run the assumed\n> > command.\n> >\n> > However, with \"prompt\", the choice defaults to \"No\" - that is, hitting\n> > return will _not_ run the command. For me at least, if git is confident\n> > it knows which command I wanted, it's usually right, and the golden path\n> > would be to run the command.\n> >\n> > Therefore this patch adds \"prompt-yes\" as a counterpart config setting\n> > for help.autocorrect, which does the same as \"prompt\", but defaults to\n> > \"Yes\" - hitting return will run the assumed command.\n> >\n> > I have not added any tests because the test suite doesn't have any tests\n> > (that I could find) for the \"prompt\" behaviour - I'm assuming this is\n> > because it's hard/impossible to simulate the interactive terminal prompt\n> >\n> > Signed-off-by: Chris Howlett <chowlett09@gmail.com>\n>\n> This seems to conflict with the patch “help: interpret boolean string\n> values for help.autocorrect” which is in `seen`.  The latest version (I\n> don’t know what version is applied right now):\n>\n> https://lore.kernel.org/git/pull.1869.v4.git.git.1736760824201.gitgitgadget@gmail.com/\n\nThat's unsurprising, as I was inspired to add this option after\nreading that committer's blog post on help.autocorrect -\nhttps://blog.gitbutler.com/why-is-git-autocorrect-too-fast-for-formula-one-drivers/\n\nI'm happy to wait for their patch to be merged, then rebase and rework\nagainst it, if that seems the most sensible option? Presumably I'll\nhave to monitor the mailing list to learn when that happens? This is\nmy first patch to git, so I'm not sure of process.\n"},{"id":"510589","messageId":"4a396e63-5e82-4ce4-83c2-13d508cb1f7f@app.fastmail.com","threadId":"62812","inReplyTo":"CAJVagJ=3uxcCpEivkpW5_HTxdL9Sa9Ymqm1iJQHUJ+=9XneLSg@mail.gmail.com","subject":"Re: [PATCH] help: add prompt-yes setting for autocorrect","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2025-01-15T17:40:45Z","receivedAt":"2025-01-15T17:41:06Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Wed, Jan 15, 2025, at 11:21, Chris Howlett wrote:\n> On Wed, 15 Jan 2025 at 09:51, Kristoffer Haugsbakk\n> > [snip]\n>\n> That's unsurprising, as I was inspired to add this option after\n> reading that committer's blog post on help.autocorrect -\n> https://blog.gitbutler.com/why-is-git-autocorrect-too-fast-for-formula-one-drivers/\n>\n> I'm happy to wait for their patch to be merged, then rebase and rework\n> against it, if that seems the most sensible option? Presumably I'll\n> have to monitor the mailing list to learn when that happens? This is\n> my first patch to git, so I'm not sure of process.\n\nYou can keep an eye on the “What's cooking” emails.[1]  The latest\none mentions this other topic as branch `sc/help-autocorrect-one`\n(that’s Scott Chacon’s initals followed by the topic name).\n\nIf you want to wait for that one to get merged:\n\n• Wait until you see such an email with this “status” under it:\n\n       Will merge to 'master'.\n\n  Which means that it will be merged to `master` soon.\n\n(Or maybe run\n\n    git branch --remote --contains=origin/sc/help-autocorrect-one \\\n    | grep master\n\nfrom time to time (I don’t know, I’ve never had to do that).)\n\nOr else you could build on top of it.  That’s more advanced though.\nNot something I’ve done myself.[2]\n\n† 1: Latest: https://lore.kernel.org/git/xmqqzfjt2qye.fsf@gitster.g/\n† 2: See `Documentation/SubmittingPatches under “select few topic\n    branches that are” for how to depend on in-flight topics\n"},{"id":"512513","messageId":"pull.1852.v2.git.1739801960334.gitgitgadget@gmail.com","threadId":"62812","inReplyTo":"pull.1852.git.1736933815236.gitgitgadget@gmail.com","subject":"[PATCH v2] help: add prompt-yes setting for autocorrect","fromName":"Chris Howlett via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2025-02-17T14:19:20Z","receivedAt":"2025-02-17T14:19:23Z","isPatch":true,"sender":{"key":"chowlett09@gmail.com","avatar":"https://gravatar.com/avatar/b577ffbe67f2f1a56230f18c1040bce4527501f44858e9e7ce1559ee021abda4?d=mp&s=160"},"body":"From: Chris Howlett <chowlett09@gmail.com>\n\nThe help.autocorrect functionality is really useful, saving frustration\nwhen a dev fat-fingers a command, and git has a pretty good idea what\nwas originally intended. The config settings are a nice selection, with\n\"prompt\" asking the user to confirm that they want to run the assumed\ncommand.\n\nHowever, with \"prompt\", the choice defaults to \"No\" - that is, hitting\nreturn will _not_ run the command. For me at least, if git is confident\nit knows which command I wanted, it's usually right, and the golden path\nwould be to run the command.\n\nTherefore this patch adds \"prompt-yes\" as a counterpart config setting\nfor help.autocorrect, which does the same as \"prompt\", but defaults to\n\"Yes\" - hitting return will run the assumed command.\n\nI have not added any tests because the test suite doesn't have any tests\n(that I could find) for the \"prompt\" behaviour - I'm assuming this is\nbecause it's hard/impossible to simulate the interactive terminal prompt\n\nSigned-off-by: Chris Howlett <chowlett09@gmail.com>\n---\n    Add prompt-yes config setting for help.autocorrect\n    \n    Changes since v1:\n    \n     * PR rebased against master and fixed up, to account for e21bf2c and\n       e4542d8\n    \n    ------------------------------------------------------------------------\n    \n    This is my first patch request to git - please do let me know if I\n    should be doing something differently!\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1852%2Fasilano%2Fautocorrect-allow-prompt-default-yes-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1852/asilano/autocorrect-allow-prompt-default-yes-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/1852\n\nRange-diff vs v1:\n\n 1:  b87c772089e ! 1:  cade4f1719e help: add prompt-yes setting for autocorrect\n     @@ Commit message\n      \n          Signed-off-by: Chris Howlett <chowlett09@gmail.com>\n      \n     - ## Documentation/config/help.txt ##\n     -@@ Documentation/config/help.txt: help.autoCorrect::\n     + ## Documentation/config/help.adoc ##\n     +@@ Documentation/config/help.adoc: immediately.\n       deciseconds (0.1 sec).\n     - \t - \"immediate\": run the suggested command immediately.\n     + \t - \"never\": don't run or show any suggested command.\n       \t - \"prompt\": show the suggestion and prompt for confirmation to run\n      -the command.\n      +the command. The default choice at the prompt is \"No\"\n      +\t - \"prompt-yes\": show the suggestion and prompt for confirmation to run\n      +the command. The default choice at the prompt is \"Yes\"\n     - \t - \"never\": don't run or show any suggested command.\n       \n       help.htmlPath::\n     + \tSpecify the path where the HTML documentation resides. File system paths\n      \n       ## help.c ##\n      @@ help.c: struct help_unknown_cmd_config {\n       \tstruct cmdnames aliases;\n       };\n       \n     -+#define AUTOCORRECT_PROMPT_YES (-4)\n     ++#define AUTOCORRECT_PROMPT_YES (-5)\n     + #define AUTOCORRECT_SHOW (-4)\n       #define AUTOCORRECT_PROMPT (-3)\n       #define AUTOCORRECT_NEVER (-2)\n     - #define AUTOCORRECT_IMMEDIATELY (-1)\n     -@@ help.c: static int git_unknown_cmd_config(const char *var, const char *value,\n     - \t\t\tcfg->autocorrect = AUTOCORRECT_IMMEDIATELY;\n     - \t\t} else if (!strcmp(value, \"prompt\")) {\n     - \t\t\tcfg->autocorrect = AUTOCORRECT_PROMPT;\n     -+\t\t} else if (!strcmp(value, \"prompt-yes\")) {\n     -+\t\t\tcfg->autocorrect = AUTOCORRECT_PROMPT_YES;\n     - \t\t} else {\n     - \t\t\tint v = git_config_int(var, value, ctx->kvi);\n     - \t\t\tcfg->autocorrect = (v < 0)\n     +@@ help.c: static int parse_autocorrect(const char *value)\n     + \n     + \tif (!strcmp(value, \"prompt\"))\n     + \t\treturn AUTOCORRECT_PROMPT;\n     ++\tif (!strcmp(value, \"prompt-yes\"))\n     ++\t\treturn AUTOCORRECT_PROMPT_YES;\n     + \tif (!strcmp(value, \"never\"))\n     + \t\treturn AUTOCORRECT_NEVER;\n     + \tif (!strcmp(value, \"immediate\"))\n      @@ help.c: char *help_unknown_cmd(const char *cmd)\n       \tif ((cfg.autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))\n       \t\tcfg.autocorrect = AUTOCORRECT_NEVER;\n\n\n Documentation/config/help.adoc |  4 +++-\n help.c                         | 15 +++++++++++++++\n 2 files changed, 18 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config/help.adoc b/Documentation/config/help.adoc\nindex b369589cec9..69b13b119f1 100644\n--- a/Documentation/config/help.adoc\n+++ b/Documentation/config/help.adoc\n@@ -18,7 +18,9 @@ immediately.\n deciseconds (0.1 sec).\n \t - \"never\": don't run or show any suggested command.\n \t - \"prompt\": show the suggestion and prompt for confirmation to run\n-the command.\n+the command. The default choice at the prompt is \"No\"\n+\t - \"prompt-yes\": show the suggestion and prompt for confirmation to run\n+the command. The default choice at the prompt is \"Yes\"\n \n help.htmlPath::\n \tSpecify the path where the HTML documentation resides. File system paths\ndiff --git a/help.c b/help.c\nindex 8d91afe851d..2a25882af02 100644\n--- a/help.c\n+++ b/help.c\n@@ -552,6 +552,7 @@ struct help_unknown_cmd_config {\n \tstruct cmdnames aliases;\n };\n \n+#define AUTOCORRECT_PROMPT_YES (-5)\n #define AUTOCORRECT_SHOW (-4)\n #define AUTOCORRECT_PROMPT (-3)\n #define AUTOCORRECT_NEVER (-2)\n@@ -570,6 +571,8 @@ static int parse_autocorrect(const char *value)\n \n \tif (!strcmp(value, \"prompt\"))\n \t\treturn AUTOCORRECT_PROMPT;\n+\tif (!strcmp(value, \"prompt-yes\"))\n+\t\treturn AUTOCORRECT_PROMPT_YES;\n \tif (!strcmp(value, \"never\"))\n \t\treturn AUTOCORRECT_NEVER;\n \tif (!strcmp(value, \"immediate\"))\n@@ -650,6 +653,9 @@ char *help_unknown_cmd(const char *cmd)\n \tif ((cfg.autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))\n \t\tcfg.autocorrect = AUTOCORRECT_NEVER;\n \n+\tif ((cfg.autocorrect == AUTOCORRECT_PROMPT_YES) && (!isatty(0) || !isatty(2)))\n+\t\tcfg.autocorrect = AUTOCORRECT_IMMEDIATELY;\n+\n \tif (cfg.autocorrect == AUTOCORRECT_NEVER) {\n \t\tfprintf_ln(stderr, _(\"git: '%s' is not a git command. See 'git --help'.\"), cmd);\n \t\texit(1);\n@@ -738,6 +744,15 @@ char *help_unknown_cmd(const char *cmd)\n \t\t\tif (!(starts_with(answer, \"y\") ||\n \t\t\t      starts_with(answer, \"Y\")))\n \t\t\t\texit(1);\n+\t\t} else if (cfg.autocorrect == AUTOCORRECT_PROMPT_YES) {\n+\t\t\tchar *answer;\n+\t\t\tstruct strbuf msg = STRBUF_INIT;\n+\t\t\tstrbuf_addf(&msg, _(\"Run '%s' instead [Y/n]? \"), assumed);\n+\t\t\tanswer = git_prompt(msg.buf, PROMPT_ECHO);\n+\t\t\tstrbuf_release(&msg);\n+\t\t\tif (starts_with(answer, \"n\") ||\n+\t\t\t      starts_with(answer, \"N\"))\n+\t\t\t\texit(1);\n \t\t} else {\n \t\t\tfprintf_ln(stderr,\n \t\t\t\t   _(\"Continuing in %0.1f seconds, \"\n\nbase-commit: 03944513488db4a81fdb4c21c3b515e4cb260b05\n-- \ngitgitgadget\n"},{"id":"513575","messageId":"CAJVagJm36-Z8CtdDFgFXgQfmqGCD7i2rufoErGUc_ou2094How@mail.gmail.com","threadId":"62812","inReplyTo":"pull.1852.v2.git.1739801702034.gitgitgadget@gmail.com","subject":"Re: [PREVIEW v2] help: add prompt-yes setting for autocorrect","fromName":"Chris Howlett","fromEmail":"chowlett09@gmail.com","sentAt":"2025-03-04T21:41:23Z","receivedAt":"2025-03-04T21:41:35Z","isPatch":false,"sender":{"key":"chowlett09@gmail.com","avatar":"https://gravatar.com/avatar/b577ffbe67f2f1a56230f18c1040bce4527501f44858e9e7ce1559ee021abda4?d=mp&s=160"},"body":"I've not seen any interaction with this patch since I posted it a\ncouple of weeks ago. Has it slipped under the radar, or is there no\ninterest in the change?\n\nThanks!\nChris.\n\nOn Mon, 17 Feb 2025 at 14:15, Chris Howlett via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Chris Howlett <chowlett09@gmail.com>\n>\n> The help.autocorrect functionality is really useful, saving frustration\n> when a dev fat-fingers a command, and git has a pretty good idea what\n> was originally intended. The config settings are a nice selection, with\n> \"prompt\" asking the user to confirm that they want to run the assumed\n> command.\n>\n> However, with \"prompt\", the choice defaults to \"No\" - that is, hitting\n> return will _not_ run the command. For me at least, if git is confident\n> it knows which command I wanted, it's usually right, and the golden path\n> would be to run the command.\n>\n> Therefore this patch adds \"prompt-yes\" as a counterpart config setting\n> for help.autocorrect, which does the same as \"prompt\", but defaults to\n> \"Yes\" - hitting return will run the assumed command.\n>\n> I have not added any tests because the test suite doesn't have any tests\n> (that I could find) for the \"prompt\" behaviour - I'm assuming this is\n> because it's hard/impossible to simulate the interactive terminal prompt\n>\n> Signed-off-by: Chris Howlett <chowlett09@gmail.com>\n> ---\n>     Add prompt-yes config setting for help.autocorrect\n>\n>     Changes since v1:\n>\n>      * PR rebased against master and fixed up, to account for e21bf2c and\n>        e4542d8\n>\n>     ------------------------------------------------------------------------\n>\n>     This is my first patch request to git - please do let me know if I\n>     should be doing something differently!\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1852%2Fasilano%2Fautocorrect-allow-prompt-default-yes-v2\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1852/asilano/autocorrect-allow-prompt-default-yes-v2\n> Pull-Request: https://github.com/gitgitgadget/git/pull/1852\n>\n> Range-diff vs v1:\n>\n>  1:  b87c772089e ! 1:  cade4f1719e help: add prompt-yes setting for autocorrect\n>      @@ Commit message\n>\n>           Signed-off-by: Chris Howlett <chowlett09@gmail.com>\n>\n>      - ## Documentation/config/help.txt ##\n>      -@@ Documentation/config/help.txt: help.autoCorrect::\n>      + ## Documentation/config/help.adoc ##\n>      +@@ Documentation/config/help.adoc: immediately.\n>        deciseconds (0.1 sec).\n>      -   - \"immediate\": run the suggested command immediately.\n>      +   - \"never\": don't run or show any suggested command.\n>          - \"prompt\": show the suggestion and prompt for confirmation to run\n>       -the command.\n>       +the command. The default choice at the prompt is \"No\"\n>       +  - \"prompt-yes\": show the suggestion and prompt for confirmation to run\n>       +the command. The default choice at the prompt is \"Yes\"\n>      -   - \"never\": don't run or show any suggested command.\n>\n>        help.htmlPath::\n>      +  Specify the path where the HTML documentation resides. File system paths\n>\n>        ## help.c ##\n>       @@ help.c: struct help_unknown_cmd_config {\n>         struct cmdnames aliases;\n>        };\n>\n>      -+#define AUTOCORRECT_PROMPT_YES (-4)\n>      ++#define AUTOCORRECT_PROMPT_YES (-5)\n>      + #define AUTOCORRECT_SHOW (-4)\n>        #define AUTOCORRECT_PROMPT (-3)\n>        #define AUTOCORRECT_NEVER (-2)\n>      - #define AUTOCORRECT_IMMEDIATELY (-1)\n>      -@@ help.c: static int git_unknown_cmd_config(const char *var, const char *value,\n>      -                  cfg->autocorrect = AUTOCORRECT_IMMEDIATELY;\n>      -          } else if (!strcmp(value, \"prompt\")) {\n>      -                  cfg->autocorrect = AUTOCORRECT_PROMPT;\n>      -+         } else if (!strcmp(value, \"prompt-yes\")) {\n>      -+                 cfg->autocorrect = AUTOCORRECT_PROMPT_YES;\n>      -          } else {\n>      -                  int v = git_config_int(var, value, ctx->kvi);\n>      -                  cfg->autocorrect = (v < 0)\n>      +@@ help.c: static int parse_autocorrect(const char *value)\n>      +\n>      +  if (!strcmp(value, \"prompt\"))\n>      +          return AUTOCORRECT_PROMPT;\n>      ++ if (!strcmp(value, \"prompt-yes\"))\n>      ++         return AUTOCORRECT_PROMPT_YES;\n>      +  if (!strcmp(value, \"never\"))\n>      +          return AUTOCORRECT_NEVER;\n>      +  if (!strcmp(value, \"immediate\"))\n>       @@ help.c: char *help_unknown_cmd(const char *cmd)\n>         if ((cfg.autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))\n>                 cfg.autocorrect = AUTOCORRECT_NEVER;\n>\n>\n>  Documentation/config/help.adoc |  4 +++-\n>  help.c                         | 15 +++++++++++++++\n>  2 files changed, 18 insertions(+), 1 deletion(-)\n>\n> diff --git a/Documentation/config/help.adoc b/Documentation/config/help.adoc\n> index b369589cec9..69b13b119f1 100644\n> --- a/Documentation/config/help.adoc\n> +++ b/Documentation/config/help.adoc\n> @@ -18,7 +18,9 @@ immediately.\n>  deciseconds (0.1 sec).\n>          - \"never\": don't run or show any suggested command.\n>          - \"prompt\": show the suggestion and prompt for confirmation to run\n> -the command.\n> +the command. The default choice at the prompt is \"No\"\n> +        - \"prompt-yes\": show the suggestion and prompt for confirmation to run\n> +the command. The default choice at the prompt is \"Yes\"\n>\n>  help.htmlPath::\n>         Specify the path where the HTML documentation resides. File system paths\n> diff --git a/help.c b/help.c\n> index 8d91afe851d..2a25882af02 100644\n> --- a/help.c\n> +++ b/help.c\n> @@ -552,6 +552,7 @@ struct help_unknown_cmd_config {\n>         struct cmdnames aliases;\n>  };\n>\n> +#define AUTOCORRECT_PROMPT_YES (-5)\n>  #define AUTOCORRECT_SHOW (-4)\n>  #define AUTOCORRECT_PROMPT (-3)\n>  #define AUTOCORRECT_NEVER (-2)\n> @@ -570,6 +571,8 @@ static int parse_autocorrect(const char *value)\n>\n>         if (!strcmp(value, \"prompt\"))\n>                 return AUTOCORRECT_PROMPT;\n> +       if (!strcmp(value, \"prompt-yes\"))\n> +               return AUTOCORRECT_PROMPT_YES;\n>         if (!strcmp(value, \"never\"))\n>                 return AUTOCORRECT_NEVER;\n>         if (!strcmp(value, \"immediate\"))\n> @@ -650,6 +653,9 @@ char *help_unknown_cmd(const char *cmd)\n>         if ((cfg.autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))\n>                 cfg.autocorrect = AUTOCORRECT_NEVER;\n>\n> +       if ((cfg.autocorrect == AUTOCORRECT_PROMPT_YES) && (!isatty(0) || !isatty(2)))\n> +               cfg.autocorrect = AUTOCORRECT_IMMEDIATELY;\n> +\n>         if (cfg.autocorrect == AUTOCORRECT_NEVER) {\n>                 fprintf_ln(stderr, _(\"git: '%s' is not a git command. See 'git --help'.\"), cmd);\n>                 exit(1);\n> @@ -738,6 +744,15 @@ char *help_unknown_cmd(const char *cmd)\n>                         if (!(starts_with(answer, \"y\") ||\n>                               starts_with(answer, \"Y\")))\n>                                 exit(1);\n> +               } else if (cfg.autocorrect == AUTOCORRECT_PROMPT_YES) {\n> +                       char *answer;\n> +                       struct strbuf msg = STRBUF_INIT;\n> +                       strbuf_addf(&msg, _(\"Run '%s' instead [Y/n]? \"), assumed);\n> +                       answer = git_prompt(msg.buf, PROMPT_ECHO);\n> +                       strbuf_release(&msg);\n> +                       if (starts_with(answer, \"n\") ||\n> +                             starts_with(answer, \"N\"))\n> +                               exit(1);\n>                 } else {\n>                         fprintf_ln(stderr,\n>                                    _(\"Continuing in %0.1f seconds, \"\n>\n> base-commit: 03944513488db4a81fdb4c21c3b515e4cb260b05\n> --\n> gitgitgadget\n"},{"id":"513579","messageId":"xmqqzfi0mnnb.fsf@gitster.g","threadId":"62812","inReplyTo":"CAJVagJm36-Z8CtdDFgFXgQfmqGCD7i2rufoErGUc_ou2094How@mail.gmail.com","subject":"Re: [PREVIEW v2] help: add prompt-yes setting for autocorrect","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-03-04T22:33:44Z","receivedAt":"2025-03-04T22:33:47Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Chris Howlett <chowlett09@gmail.com> writes:\n\n> I've not seen any interaction with this patch since I posted it a\n> couple of weeks ago. Has it slipped under the radar, or is there no\n> interest in the change?\n\nI personally do not find the cause so compelling, and am not myself\ninterested in a patch that pretty much has to duplicate the lines\nneeded to support existing AUTOCORRECT_PROMPT.  But others may feel\ndifferently.\n\nAround here, people do not react to everything they see, and some\nmay change their mind when asked the same question twice with some\ninterval in between, so it is a good idea to ping after some weeks\nto reconfirm.\n\nThanks for pinging.\n"}]}