[PATCH 0/5] parseopt: add subcommand autocorrection
- From
- Jiamu Sun <39@barroit.sh>
- Date
- Mar 8, 2026, 12:17 UTC
- Message-ID
- <SY0P300MB08019805A8304105FA805EB1CE78A@SY0P300MB0801.AUSP300.PROD.OUTLOOK.COM>
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.
Currently, builtins with mandatory subcommands enable autocorrection by default. However, those using PARSE_OPT_SUBCOMMAND_OPTIONAL skip it to avoid treating valid unknown arguments as mistyped subcommands.
This series adds PARSE_OPT_SUBCOMMAND_AUTOCORR, allowing commands with optional subcommands to explicitly opt in to autocorrection. It then enables this flag for git-remote and git-notes.
Additionally, it extracts the existing autocorrection logic from help.c so subcommand handling can reuse the same config parsing and prompt/delay logic.
Jiamu Sun (5): parseopt: extract subcommand handling from parse_options_step() help: refactor command autocorrection handling parseopt: autocorrect mistyped subcommands parseopt: enable subcommand autocorrect for remote and notes help: add tests for subcommand autocorrection
Makefile | 1 + autocorrect.c | 92 +++++++++++++++++++ autocorrect.h | 23 +++++ builtin/notes.c | 10 +- builtin/remote.c | 12 +-- help.c | 106 ++++----------------- parse-options.c | 147 +++++++++++++++++++++++------- parse-options.h | 1 + t/t9004-autocorrect-subcommand.sh | 49 ++++++++++ 9 files changed, 306 insertions(+), 135 deletions(-) create mode 100644 autocorrect.c create mode 100644 autocorrect.h create mode 100755 t/t9004-autocorrect-subcommand.sh
base-commit: 795c338de725e13bd361214c6b768019fc45a2c1
-- 2.53.0