]> git.ipfire.org Git - thirdparty/git.git/blobdiff - help.c
commit-graph: avoid leaking topo_levels slab in write_commit_graph()
[thirdparty/git.git] / help.c
diff --git a/help.c b/help.c
index 919cbb9206aedf98ac97e59e2132451210e1d4e4..3c3bdec21356d9e346ef2185d7ddaffa8229d6d0 100644 (file)
--- a/help.c
+++ b/help.c
@@ -472,12 +472,26 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)
 static int autocorrect;
 static struct cmdnames aliases;
 
+#define AUTOCORRECT_NEVER (-2)
+#define AUTOCORRECT_IMMEDIATELY (-1)
+
 static int git_unknown_cmd_config(const char *var, const char *value, void *cb)
 {
        const char *p;
 
-       if (!strcmp(var, "help.autocorrect"))
-               autocorrect = git_config_int(var,value);
+       if (!strcmp(var, "help.autocorrect")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               if (!strcmp(value, "never")) {
+                       autocorrect = AUTOCORRECT_NEVER;
+               } else if (!strcmp(value, "immediate")) {
+                       autocorrect = AUTOCORRECT_IMMEDIATELY;
+               } else {
+                       int v = git_config_int(var, value);
+                       autocorrect = (v < 0)
+                               ? AUTOCORRECT_IMMEDIATELY : v;
+               }
+       }
        /* Also use aliases for command lookup */
        if (skip_prefix(var, "alias.", &p))
                add_cmdname(&aliases, p, strlen(p));
@@ -525,6 +539,11 @@ const char *help_unknown_cmd(const char *cmd)
 
        read_early_config(git_unknown_cmd_config, NULL);
 
+       if (autocorrect == AUTOCORRECT_NEVER) {
+               fprintf_ln(stderr, _("git: '%s' is not a git command. See 'git --help'."), cmd);
+               exit(1);
+       }
+
        load_command_list("git-", &main_cmds, &other_cmds);
 
        add_cmd_list(&main_cmds, &aliases);
@@ -594,7 +613,7 @@ const char *help_unknown_cmd(const char *cmd)
                           _("WARNING: You called a Git command named '%s', "
                             "which does not exist."),
                           cmd);
-               if (autocorrect < 0)
+               if (autocorrect == AUTOCORRECT_IMMEDIATELY)
                        fprintf_ln(stderr,
                                   _("Continuing under the assumption that "
                                     "you meant '%s'."),