{"thread":{"id":"54707","subject":"[PATCH v5] help.c: expand options for help.autocorrect","startedAt":"2020-11-24T16:37:59Z","lastAt":"2020-11-25T21:01:55Z","messageCount":3,"participants":["Drew DeVault","Junio C Hamano"],"isPatch":true,"patchVersion":5,"patchTotal":null},"messages":[{"id":"410686","messageId":"20201124163752.20306-1-sir@cmpwn.com","threadId":"54707","inReplyTo":null,"subject":"[PATCH v5] help.c: expand options for help.autocorrect","fromName":"Drew DeVault","fromEmail":"sir@cmpwn.com","sentAt":"2020-11-24T16:37:52Z","receivedAt":"2020-11-24T16:37:59Z","isPatch":true,"sender":{"key":"sir@cmpwn.com","avatar":"https://avatars.githubusercontent.com/u/1310872?v=4"},"body":"While help.autocorrect can be set to 0 to decline auto-execution of\npossibly mistyped commands, it still spends cycles to compute the\nsuggestions, and it wastes screen real estate.\n\nUpdate help.autocorrect to accept the string \"never\" to just exit\nwith error upon mistyped commands to help users who prefer to never\nsee suggested corrections at all.\n\nWhile at it, introduce \"immediate\" as a more readable way to\nimmediately execute the auto-corrected command, which can be done\nwith negative value.\n\nSigned-off-by: Drew DeVault <sir@cmpwn.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\nv5 incorporates Junio's suggested commit message and test.\n\n Documentation/config/help.txt | 16 +++++++++-------\n help.c                        | 25 ++++++++++++++++++++++---\n t/t9003-help-autocorrect.sh   | 13 +++++++++++++\n 3 files changed, 44 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/config/help.txt b/Documentation/config/help.txt\nindex 224bbf5a28..e07abd32d7 100644\n--- a/Documentation/config/help.txt\n+++ b/Documentation/config/help.txt\n@@ -8,13 +8,15 @@ help.format::\n \tthe default. 'web' and 'html' are the same.\n \n help.autoCorrect::\n-\tAutomatically correct and execute mistyped commands after\n-\twaiting for the given number of deciseconds (0.1 sec). If more\n-\tthan one command can be deduced from the entered text, nothing\n-\twill be executed.  If the value of this option is negative,\n-\tthe corrected command will be executed immediately. If the\n-\tvalue is 0 - the command will be just shown but not executed.\n-\tThis is the default.\n+\tIf git detects typos and can identify exactly one valid command similar\n+\tto the error, git will automatically run the intended command after\n+\twaiting a duration of time defined by this configuration value in\n+\tdeciseconds (0.1 sec).  If this value is 0, the suggested corrections\n+\twill be shown, but not executed. If \"immediate\", the suggested command\n+\tis run immediately. If \"never\", suggestions are not shown at all. The\n+\tdefault value is zero.\n++\n+Negative integers are interpreted as \"immediately\" for historical reasons.\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 919cbb9206..3c3bdec213 100644\n--- a/help.c\n+++ b/help.c\n@@ -472,12 +472,26 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)\n static int autocorrect;\n static struct cmdnames aliases;\n \n+#define AUTOCORRECT_NEVER (-2)\n+#define AUTOCORRECT_IMMEDIATELY (-1)\n+\n static int git_unknown_cmd_config(const char *var, const char *value, void *cb)\n {\n \tconst char *p;\n \n-\tif (!strcmp(var, \"help.autocorrect\"))\n-\t\tautocorrect = git_config_int(var,value);\n+\tif (!strcmp(var, \"help.autocorrect\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\tif (!strcmp(value, \"never\")) {\n+\t\t\tautocorrect = AUTOCORRECT_NEVER;\n+\t\t} else if (!strcmp(value, \"immediate\")) {\n+\t\t\tautocorrect = AUTOCORRECT_IMMEDIATELY;\n+\t\t} else {\n+\t\t\tint v = git_config_int(var, value);\n+\t\t\tautocorrect = (v < 0)\n+\t\t\t\t? AUTOCORRECT_IMMEDIATELY : v;\n+\t\t}\n+\t}\n \t/* Also use aliases for command lookup */\n \tif (skip_prefix(var, \"alias.\", &p))\n \t\tadd_cmdname(&aliases, p, strlen(p));\n@@ -525,6 +539,11 @@ const char *help_unknown_cmd(const char *cmd)\n \n \tread_early_config(git_unknown_cmd_config, NULL);\n \n+\tif (autocorrect == AUTOCORRECT_NEVER) {\n+\t\tfprintf_ln(stderr, _(\"git: '%s' is not a git command. See 'git --help'.\"), cmd);\n+\t\texit(1);\n+\t}\n+\n \tload_command_list(\"git-\", &main_cmds, &other_cmds);\n \n \tadd_cmd_list(&main_cmds, &aliases);\n@@ -594,7 +613,7 @@ const char *help_unknown_cmd(const char *cmd)\n \t\t\t   _(\"WARNING: You called a Git command named '%s', \"\n \t\t\t     \"which does not exist.\"),\n \t\t\t   cmd);\n-\t\tif (autocorrect < 0)\n+\t\tif (autocorrect == AUTOCORRECT_IMMEDIATELY)\n \t\t\tfprintf_ln(stderr,\n \t\t\t\t   _(\"Continuing under the assumption that \"\n \t\t\t\t     \"you meant '%s'.\"),\ndiff --git a/t/t9003-help-autocorrect.sh b/t/t9003-help-autocorrect.sh\nindex b1c7919c4a..8f1035c3c2 100755\n--- a/t/t9003-help-autocorrect.sh\n+++ b/t/t9003-help-autocorrect.sh\n@@ -49,4 +49,17 @@ test_expect_success 'autocorrect running commands' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'autocorrect can be declined altogether' '\n+\tgit config help.autocorrect never &&\n+\n+\ttest_must_fail git lfg 2>actual &&\n+\tif test_have_prereq C_LOCALE_OUTPUT\n+\tthen\n+\t\t: cannot test with poisoned i18n\n+\telse\n+\t\tgrep \"is not a git command\" actual &&\n+\t\ttest_line_count = 1 actual\n+\tfi\n+'\n+\n test_done\n-- \n2.29.2\n\n"},{"id":"410716","messageId":"xmqqmtz6ig7h.fsf@gitster.c.googlers.com","threadId":"54707","inReplyTo":"20201124163752.20306-1-sir@cmpwn.com","subject":"Re: [PATCH v5] help.c: expand options for help.autocorrect","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-24T21:43:14Z","receivedAt":"2020-11-24T21:43:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Drew DeVault <sir@cmpwn.com> writes:\n\n> While help.autocorrect can be set to 0 to decline auto-execution of\n> possibly mistyped commands, it still spends cycles to compute the\n> suggestions, and it wastes screen real estate.\n>\n> Update help.autocorrect to accept the string \"never\" to just exit\n> with error upon mistyped commands to help users who prefer to never\n> see suggested corrections at all.\n>\n> While at it, introduce \"immediate\" as a more readable way to\n> immediately execute the auto-corrected command, which can be done\n> with negative value.\n>\n> Signed-off-by: Drew DeVault <sir@cmpwn.com>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> v5 incorporates Junio's suggested commit message and test.\n\nHmph,...\n\n> +\tIf git detects typos and can identify exactly one valid command similar\n> +\tto the error, git will automatically run the intended command after\n> +\twaiting a duration of time defined by this configuration value in\n> +\tdeciseconds (0.1 sec).  If this value is 0, the suggested corrections\n> +\twill be shown, but not executed. If \"immediate\", the suggested command\n> +\tis run immediately. If \"never\", suggestions are not shown at all. The\n> +\tdefault value is zero.\n> ++\n> +Negative integers are interpreted as \"immediately\" for historical reasons.\n\nI do not think we should place too much stress on things that are\nthere for \"historical reasons\"---they do not deserve their own\nparagraph.  That is why the version I queued with tweak said:\n\n\t...  If this value is 0, the suggested corrections will be\n\tshown, but not executed. If it is a negative integer, or\n\t\"immediate\", the suggested command is run immediately. If\n\t\"never\", suggestions are not shown at all. The default value\n\tis zero.\n\n> +test_expect_success 'autocorrect can be declined altogether' '\n> +\tgit config help.autocorrect never &&\n> +\n> +\ttest_must_fail git lfg 2>actual &&\n> +\tif test_have_prereq C_LOCALE_OUTPUT\n> +\tthen\n> +\t\t: cannot test with poisoned i18n\n> +\telse\n> +\t\tgrep \"is not a git command\" actual &&\n> +\t\ttest_line_count = 1 actual\n> +\tfi\n> +'\n\nThis test for 'never' is good.  We'd probably want to also add a\ntest for immediate.\n\nTaking them together, perhaps like the attached patch.\n\nThanks.\n\n\n--- >8 ------ >8 ------ >8 ------ >8 ------ >8 ------ >8 ------\nFrom 59c61bb206242f750a3b63d9b5e16f4e1cf343e7 Mon Sep 17 00:00:00 2001\nFrom: Drew DeVault <sir@cmpwn.com>\nDate: Tue, 24 Nov 2020 11:37:52 -0500\nSubject: [PATCH] help.c: help.autocorrect=never means \"do not even compute\n suggestions\"\n\nWhile help.autocorrect can be set to 0 to decline auto-execution of\npossibly mistyped commands, it still spends cycles to compute the\nsuggestions, and it wastes screen real estate.\n\nUpdate help.autocorrect to accept the string \"never\" to just exit\nwith error upon mistyped commands to help users who prefer to never\nsee suggested corrections at all.\n\nWhile at it, introduce \"immediate\" as a more readable way to\nimmediately execute the auto-corrected command, which can be done\nwith negative value.\n\nSigned-off-by: Drew DeVault <sir@cmpwn.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\nRange-diff:\n1:  4ea4744d46 ! 1:  59c61bb206 help.c: expand options for help.autocorrect\n    @@ Metadata\n     Author: Drew DeVault <sir@cmpwn.com>\n     \n      ## Commit message ##\n    -    help.c: expand options for help.autocorrect\n    +    help.c: help.autocorrect=never means \"do not even compute suggestions\"\n     \n         While help.autocorrect can be set to 0 to decline auto-execution of\n         possibly mistyped commands, it still spends cycles to compute the\n    @@ Documentation/config/help.txt: help.format::\n     +\tto the error, git will automatically run the intended command after\n     +\twaiting a duration of time defined by this configuration value in\n     +\tdeciseconds (0.1 sec).  If this value is 0, the suggested corrections\n    -+\twill be shown, but not executed. If \"immediate\", the suggested command\n    ++\twill be shown, but not executed. If it is a negative integer, or\n    ++\t\"immediate\", the suggested command\n     +\tis run immediately. If \"never\", suggestions are not shown at all. The\n     +\tdefault value is zero.\n    -++\n    -+Negative integers are interpreted as \"immediately\" for historical reasons.\n      \n      help.htmlPath::\n      \tSpecify the path where the HTML documentation resides. File system paths\n    @@ help.c: const char *help_unknown_cmd(const char *cmd)\n      \t\t\t\t     \"you meant '%s'.\"),\n     \n      ## t/t9003-help-autocorrect.sh ##\n    -@@ t/t9003-help-autocorrect.sh: test_expect_success 'autocorrect running commands' '\n    - \ttest_cmp expect actual\n    +@@ t/t9003-help-autocorrect.sh: test_expect_success 'autocorrect showing candidates' '\n    + \tgrep \"^\tdistimdistim\" actual\n      '\n      \n    +-test_expect_success 'autocorrect running commands' '\n    +-\tgit config help.autocorrect -1 &&\n    ++for immediate in -1 immediate\n    ++do\n    ++\ttest_expect_success 'autocorrect running commands' '\n    ++\t\tgit config help.autocorrect $immediate &&\n    + \n    +-\tgit lfg >actual &&\n    +-\techo \"a single log entry\" >expect &&\n    +-\ttest_cmp expect actual &&\n    ++\t\tgit lfg >actual &&\n    ++\t\techo \"a single log entry\" >expect &&\n    ++\t\ttest_cmp expect actual &&\n    + \n    +-\tgit distimdist >actual &&\n    +-\techo \"distimdistim was called\" >expect &&\n    +-\ttest_cmp expect actual\n    ++\t\tgit distimdist >actual &&\n    ++\t\techo \"distimdistim was called\" >expect &&\n    ++\t\ttest_cmp expect actual\n    ++\t'\n    ++done\n    ++\n     +test_expect_success 'autocorrect can be declined altogether' '\n     +\tgit config help.autocorrect never &&\n     +\n    @@ t/t9003-help-autocorrect.sh: test_expect_success 'autocorrect running commands'\n     +\t\tgrep \"is not a git command\" actual &&\n     +\t\ttest_line_count = 1 actual\n     +\tfi\n    -+'\n    -+\n    + '\n    + \n      test_done\n\n Documentation/config/help.txt | 15 ++++++++-------\n help.c                        | 25 ++++++++++++++++++++++---\n t/t9003-help-autocorrect.sh   | 32 ++++++++++++++++++++++++--------\n 3 files changed, 54 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/config/help.txt b/Documentation/config/help.txt\nindex 224bbf5a28..783a90a0f9 100644\n--- a/Documentation/config/help.txt\n+++ b/Documentation/config/help.txt\n@@ -8,13 +8,14 @@ help.format::\n \tthe default. 'web' and 'html' are the same.\n \n help.autoCorrect::\n-\tAutomatically correct and execute mistyped commands after\n-\twaiting for the given number of deciseconds (0.1 sec). If more\n-\tthan one command can be deduced from the entered text, nothing\n-\twill be executed.  If the value of this option is negative,\n-\tthe corrected command will be executed immediately. If the\n-\tvalue is 0 - the command will be just shown but not executed.\n-\tThis is the default.\n+\tIf git detects typos and can identify exactly one valid command similar\n+\tto the error, git will automatically run the intended command after\n+\twaiting a duration of time defined by this configuration value in\n+\tdeciseconds (0.1 sec).  If this value is 0, the suggested corrections\n+\twill be shown, but not executed. If it is a negative integer, or\n+\t\"immediate\", the suggested command\n+\tis run immediately. If \"never\", suggestions are not shown at all. The\n+\tdefault value is zero.\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 919cbb9206..3c3bdec213 100644\n--- a/help.c\n+++ b/help.c\n@@ -472,12 +472,26 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)\n static int autocorrect;\n static struct cmdnames aliases;\n \n+#define AUTOCORRECT_NEVER (-2)\n+#define AUTOCORRECT_IMMEDIATELY (-1)\n+\n static int git_unknown_cmd_config(const char *var, const char *value, void *cb)\n {\n \tconst char *p;\n \n-\tif (!strcmp(var, \"help.autocorrect\"))\n-\t\tautocorrect = git_config_int(var,value);\n+\tif (!strcmp(var, \"help.autocorrect\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\tif (!strcmp(value, \"never\")) {\n+\t\t\tautocorrect = AUTOCORRECT_NEVER;\n+\t\t} else if (!strcmp(value, \"immediate\")) {\n+\t\t\tautocorrect = AUTOCORRECT_IMMEDIATELY;\n+\t\t} else {\n+\t\t\tint v = git_config_int(var, value);\n+\t\t\tautocorrect = (v < 0)\n+\t\t\t\t? AUTOCORRECT_IMMEDIATELY : v;\n+\t\t}\n+\t}\n \t/* Also use aliases for command lookup */\n \tif (skip_prefix(var, \"alias.\", &p))\n \t\tadd_cmdname(&aliases, p, strlen(p));\n@@ -525,6 +539,11 @@ const char *help_unknown_cmd(const char *cmd)\n \n \tread_early_config(git_unknown_cmd_config, NULL);\n \n+\tif (autocorrect == AUTOCORRECT_NEVER) {\n+\t\tfprintf_ln(stderr, _(\"git: '%s' is not a git command. See 'git --help'.\"), cmd);\n+\t\texit(1);\n+\t}\n+\n \tload_command_list(\"git-\", &main_cmds, &other_cmds);\n \n \tadd_cmd_list(&main_cmds, &aliases);\n@@ -594,7 +613,7 @@ const char *help_unknown_cmd(const char *cmd)\n \t\t\t   _(\"WARNING: You called a Git command named '%s', \"\n \t\t\t     \"which does not exist.\"),\n \t\t\t   cmd);\n-\t\tif (autocorrect < 0)\n+\t\tif (autocorrect == AUTOCORRECT_IMMEDIATELY)\n \t\t\tfprintf_ln(stderr,\n \t\t\t\t   _(\"Continuing under the assumption that \"\n \t\t\t\t     \"you meant '%s'.\"),\ndiff --git a/t/t9003-help-autocorrect.sh b/t/t9003-help-autocorrect.sh\nindex b1c7919c4a..a1b180338f 100755\n--- a/t/t9003-help-autocorrect.sh\n+++ b/t/t9003-help-autocorrect.sh\n@@ -37,16 +37,32 @@ test_expect_success 'autocorrect showing candidates' '\n \tgrep \"^\tdistimdistim\" actual\n '\n \n-test_expect_success 'autocorrect running commands' '\n-\tgit config help.autocorrect -1 &&\n+for immediate in -1 immediate\n+do\n+\ttest_expect_success 'autocorrect running commands' '\n+\t\tgit config help.autocorrect $immediate &&\n \n-\tgit lfg >actual &&\n-\techo \"a single log entry\" >expect &&\n-\ttest_cmp expect actual &&\n+\t\tgit lfg >actual &&\n+\t\techo \"a single log entry\" >expect &&\n+\t\ttest_cmp expect actual &&\n \n-\tgit distimdist >actual &&\n-\techo \"distimdistim was called\" >expect &&\n-\ttest_cmp expect actual\n+\t\tgit distimdist >actual &&\n+\t\techo \"distimdistim was called\" >expect &&\n+\t\ttest_cmp expect actual\n+\t'\n+done\n+\n+test_expect_success 'autocorrect can be declined altogether' '\n+\tgit config help.autocorrect never &&\n+\n+\ttest_must_fail git lfg 2>actual &&\n+\tif test_have_prereq C_LOCALE_OUTPUT\n+\tthen\n+\t\t: cannot test with poisoned i18n\n+\telse\n+\t\tgrep \"is not a git command\" actual &&\n+\t\ttest_line_count = 1 actual\n+\tfi\n '\n \n test_done\n-- \n2.29.2-520-gf7cd35e8a7\n\n"},{"id":"410801","messageId":"xmqqft4xdubq.fsf_-_@gitster.c.googlers.com","threadId":"54707","inReplyTo":"xmqqmtz6ig7h.fsf@gitster.c.googlers.com","subject":"[PATCH v6] help.c: help.autocorrect=never means \"do not compute suggestions\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-11-25T21:01:45Z","receivedAt":"2020-11-25T21:01:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"From: Drew DeVault <sir@cmpwn.com>\n\nWhile help.autocorrect can be set to 0 to decline auto-execution of\npossibly mistyped commands, it still spends cycles to compute the\nsuggestions, and it wastes screen real estate.\n\nUpdate help.autocorrect to accept the string \"never\" to just exit\nwith error upon mistyped commands to help users who prefer to never\nsee suggested corrections at all.\n\nWhile at it, introduce \"immediate\" as a more readable way to\nimmediately execute the auto-corrected command, which can be done\nwith negative value.\n\nSigned-off-by: Drew DeVault <sir@cmpwn.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * Took bugfix for the new test from SZEDER's review.\n\nRange-diff against v5:\n1:  59c61bb206 ! 1:  c4b6b18b2e help.c: help.autocorrect=never means \"do not even compute suggestions\"\n    @@ t/t9003-help-autocorrect.sh: test_expect_success 'autocorrect showing candidates\n     +\ttest_must_fail git lfg 2>actual &&\n     +\tif test_have_prereq C_LOCALE_OUTPUT\n     +\tthen\n    -+\t\t: cannot test with poisoned i18n\n    -+\telse\n     +\t\tgrep \"is not a git command\" actual &&\n     +\t\ttest_line_count = 1 actual\n     +\tfi\n\n Documentation/config/help.txt | 15 ++++++++-------\n help.c                        | 25 ++++++++++++++++++++++---\n t/t9003-help-autocorrect.sh   | 30 ++++++++++++++++++++++--------\n 3 files changed, 52 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/config/help.txt b/Documentation/config/help.txt\nindex 224bbf5a28..783a90a0f9 100644\n--- a/Documentation/config/help.txt\n+++ b/Documentation/config/help.txt\n@@ -8,13 +8,14 @@ help.format::\n \tthe default. 'web' and 'html' are the same.\n \n help.autoCorrect::\n-\tAutomatically correct and execute mistyped commands after\n-\twaiting for the given number of deciseconds (0.1 sec). If more\n-\tthan one command can be deduced from the entered text, nothing\n-\twill be executed.  If the value of this option is negative,\n-\tthe corrected command will be executed immediately. If the\n-\tvalue is 0 - the command will be just shown but not executed.\n-\tThis is the default.\n+\tIf git detects typos and can identify exactly one valid command similar\n+\tto the error, git will automatically run the intended command after\n+\twaiting a duration of time defined by this configuration value in\n+\tdeciseconds (0.1 sec).  If this value is 0, the suggested corrections\n+\twill be shown, but not executed. If it is a negative integer, or\n+\t\"immediate\", the suggested command\n+\tis run immediately. If \"never\", suggestions are not shown at all. The\n+\tdefault value is zero.\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 919cbb9206..3c3bdec213 100644\n--- a/help.c\n+++ b/help.c\n@@ -472,12 +472,26 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)\n static int autocorrect;\n static struct cmdnames aliases;\n \n+#define AUTOCORRECT_NEVER (-2)\n+#define AUTOCORRECT_IMMEDIATELY (-1)\n+\n static int git_unknown_cmd_config(const char *var, const char *value, void *cb)\n {\n \tconst char *p;\n \n-\tif (!strcmp(var, \"help.autocorrect\"))\n-\t\tautocorrect = git_config_int(var,value);\n+\tif (!strcmp(var, \"help.autocorrect\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\tif (!strcmp(value, \"never\")) {\n+\t\t\tautocorrect = AUTOCORRECT_NEVER;\n+\t\t} else if (!strcmp(value, \"immediate\")) {\n+\t\t\tautocorrect = AUTOCORRECT_IMMEDIATELY;\n+\t\t} else {\n+\t\t\tint v = git_config_int(var, value);\n+\t\t\tautocorrect = (v < 0)\n+\t\t\t\t? AUTOCORRECT_IMMEDIATELY : v;\n+\t\t}\n+\t}\n \t/* Also use aliases for command lookup */\n \tif (skip_prefix(var, \"alias.\", &p))\n \t\tadd_cmdname(&aliases, p, strlen(p));\n@@ -525,6 +539,11 @@ const char *help_unknown_cmd(const char *cmd)\n \n \tread_early_config(git_unknown_cmd_config, NULL);\n \n+\tif (autocorrect == AUTOCORRECT_NEVER) {\n+\t\tfprintf_ln(stderr, _(\"git: '%s' is not a git command. See 'git --help'.\"), cmd);\n+\t\texit(1);\n+\t}\n+\n \tload_command_list(\"git-\", &main_cmds, &other_cmds);\n \n \tadd_cmd_list(&main_cmds, &aliases);\n@@ -594,7 +613,7 @@ const char *help_unknown_cmd(const char *cmd)\n \t\t\t   _(\"WARNING: You called a Git command named '%s', \"\n \t\t\t     \"which does not exist.\"),\n \t\t\t   cmd);\n-\t\tif (autocorrect < 0)\n+\t\tif (autocorrect == AUTOCORRECT_IMMEDIATELY)\n \t\t\tfprintf_ln(stderr,\n \t\t\t\t   _(\"Continuing under the assumption that \"\n \t\t\t\t     \"you meant '%s'.\"),\ndiff --git a/t/t9003-help-autocorrect.sh b/t/t9003-help-autocorrect.sh\nindex b1c7919c4a..03cd5c5423 100755\n--- a/t/t9003-help-autocorrect.sh\n+++ b/t/t9003-help-autocorrect.sh\n@@ -37,16 +37,30 @@ test_expect_success 'autocorrect showing candidates' '\n \tgrep \"^\tdistimdistim\" actual\n '\n \n-test_expect_success 'autocorrect running commands' '\n-\tgit config help.autocorrect -1 &&\n+for immediate in -1 immediate\n+do\n+\ttest_expect_success 'autocorrect running commands' '\n+\t\tgit config help.autocorrect $immediate &&\n \n-\tgit lfg >actual &&\n-\techo \"a single log entry\" >expect &&\n-\ttest_cmp expect actual &&\n+\t\tgit lfg >actual &&\n+\t\techo \"a single log entry\" >expect &&\n+\t\ttest_cmp expect actual &&\n \n-\tgit distimdist >actual &&\n-\techo \"distimdistim was called\" >expect &&\n-\ttest_cmp expect actual\n+\t\tgit distimdist >actual &&\n+\t\techo \"distimdistim was called\" >expect &&\n+\t\ttest_cmp expect actual\n+\t'\n+done\n+\n+test_expect_success 'autocorrect can be declined altogether' '\n+\tgit config help.autocorrect never &&\n+\n+\ttest_must_fail git lfg 2>actual &&\n+\tif test_have_prereq C_LOCALE_OUTPUT\n+\tthen\n+\t\tgrep \"is not a git command\" actual &&\n+\t\ttest_line_count = 1 actual\n+\tfi\n '\n \n test_done\n-- \n2.29.2-533-ge2694b469b\n\n"}]}