Subject: Re: [PATCH v6 00/10] parseopt: add subcommand autocorrection

From: Junio C Hamano <[email-masked]>
Date: Mon, 11 May 2026 12:03:12 +0900

Jiamu Sun <[email-masked]> writes:

> Git currently provides auto-correction for builtins and aliases, but
> lacks this functionality for subcommands parsed via the parse-options
> API. Subcommands are also commands, and typos will occur, too. Like:
>
> 	git remote add-rul
>
> So, this series introduces subcommand auto-correction.
>
> By default, this implementation enables autocorrection for builtins
> with mandatory subcommands. However, for those using
> PARSE_OPT_SUBCOMMAND_OPTIONAL, autocorrection is skipped to avoid
> misinterpreting legitimate unknown arguments as mistyped subcommands.
>
> To allow builtins with optional subcommands to explicitly opt in,
> this series adds the PARSE_OPT_SUBCOMMAND_AUTOCORRECT flag, and enables
> it for git-remote and git-notes.
>
> Additionally, the existing autocorrection logic is extracted from
> help.c so subcommand handling can reuse the same config parsing and
> prompt/delay logic.
>
> Some string literals are also combined so the full text is easier to
> grep for.
>
> Changes in v6:
>   - Adjust existing tests to fit subcommand autocorrection behavior
>   - Change the similar subcommand hint exit code to 129

I've been carrying the following fix on top of these series since
Apr 23 when the topic was merged to 'seen'.  Can you fix these up at
the source, so that we can move forward with this topic?

Thanks.

diff --git a/parse-options.c b/parse-options.c
index a1258134df..1a5feab5dd 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -647,7 +647,8 @@ static const char *autocorrect_subcommand(const char *cmd,
 					  struct string_list *cmds)
 {
 	struct autocorrect autocorrect = { 0 };
-	unsigned int n = 0, best = 0;
+	unsigned int n = 0;
+	int best = 0;
 	struct string_list_item *cand;
 
 	autocorrect_resolve(&autocorrect);
@@ -657,7 +658,7 @@ static const char *autocorrect_subcommand(const char *cmd,
 
 	for_each_string_list_item(cand, cmds) {
 		if (starts_with(cand->string, cmd)) {
-			cand->util = 0;
+			cand->util = NULL;
 		} else {
 			int edit = levenshtein(cmd, cand->string,
 					       0, 2, 1, 3) + 1;
-- 
2.54.0-170-g88022b8681