]> git.ipfire.org Git - thirdparty/git.git/commitdiff
help: move tty check for autocorrection to autocorrect.c
authorJiamu Sun <39@barroit.sh>
Mon, 16 Mar 2026 15:36:16 +0000 (00:36 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Mar 2026 18:21:07 +0000 (11:21 -0700)
TTY checking is the autocorrect config parser's responsibility. It must
ensure the parsed value is correct and reliable. Thus, move the check to
autocorrect_resolve_config().

Signed-off-by: Jiamu Sun <39@barroit.sh>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
autocorrect.c
help.c

index 97145d3a53ce0715ebc9fba41563efdf90626bb8..887d2396da44b98edd687b0a539f7b8f308842cb 100644 (file)
@@ -33,18 +33,26 @@ void autocorrect_resolve_config(const char *var, const char *value,
                                const struct config_context *ctx, void *data)
 {
        int *out = data;
+       int parsed;
 
-       if (!strcmp(var, "help.autocorrect")) {
-               int v = parse_autocorrect(value);
+       if (strcmp(var, "help.autocorrect"))
+               return;
 
-               if (!v) {
-                       v = git_config_int(var, value, ctx->kvi);
-                       if (v < 0 || v == 1)
-                               v = AUTOCORRECT_IMMEDIATELY;
-               }
+       parsed = parse_autocorrect(value);
 
-               *out = v;
+       /*
+        * Disable autocorrection prompt in a non-interactive session
+        */
+       if (parsed == AUTOCORRECT_PROMPT && (!isatty(0) || !isatty(2)))
+               parsed = AUTOCORRECT_NEVER;
+
+       if (!parsed) {
+               parsed = git_config_int(var, value, ctx->kvi);
+               if (parsed < 0 || parsed == 1)
+                       parsed = AUTOCORRECT_IMMEDIATELY;
        }
+
+       *out = parsed;
 }
 
 void autocorrect_confirm(int autocorrect, const char *assumed)
diff --git a/help.c b/help.c
index 4acb6ca585ff8fa1db60c6280ec7e10c464bcf86..983057970e7c7fe451f97c2e5304c8050f64a6fe 100644 (file)
--- a/help.c
+++ b/help.c
@@ -607,12 +607,6 @@ char *help_unknown_cmd(const char *cmd)
 
        read_early_config(the_repository, git_unknown_cmd_config, &cfg);
 
-       /*
-        * Disable autocorrection prompt in a non-interactive session
-        */
-       if ((cfg.autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))
-               cfg.autocorrect = AUTOCORRECT_NEVER;
-
        if (cfg.autocorrect == AUTOCORRECT_NEVER) {
                fprintf_ln(stderr, _("git: '%s' is not a git command. See 'git --help'."), cmd);
                exit(1);