Re: [PATCH v6 00/10] parseopt: add subcommand autocorrection
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 11, 2026, 03:03 UTC
- Message-ID
- <xmqqcxz2tzpr.fsf@gitster.g>
- In-Reply-To
- <SY0P300MB0801677A2A1E0FD38D06A841CE2A2@SY0P300MB0801.AUSP300.PROD.OUTLOOK.COM>
Jiamu Sun <39@barroit.sh> writes:
Show 27 quoted lines
> 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