git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] parse-options.c: display subcommands properly in check_typos

From
AGaubrey via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 6, 2026, 18:38 UTC
Message-ID
<pull.2084.git.1775500706920.gitgitgadget@gmail.com>
From: aubymori <aubyomori@gmail.com>

Before this, mistyping a subcommand with one dash (e.g. `git stash -list`) would display a message telling the user to try it with two dashes. Since subcommands are parsed with no dashes, this is incorrect and simply results in the help message for that command being shown.

This commit changes check_typos to check the command type and display a proper message for subcommands.

Signed-off-by: aubymori <aubyomori@gmail.com>
---
    parse-options.c: display subcommands properly in check_typos
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2084%2Faubymori%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2084/aubymori/master-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2084
 parse-options.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/parse-options.c b/parse-options.c
index a676da86f5..2c4530bb8c 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -633,7 +633,10 @@ static void check_typos(const char *arg, const struct option *options)
 		if (!options->long_name)
 			continue;
 		if (starts_with(options->long_name, arg)) {
-			error(_("did you mean `--%s` (with two dashes)?"), arg);
+			if (options->type == OPTION_SUBCOMMAND)
+				error(_("did you mean `%s` (with no dash)?"), arg);
+			else
+				error(_("did you mean `--%s` (with two dashes)?"), arg);
 			exit(129);
 		}
 	}

base-commit: 2855562ca6a9c6b0e7bc780b050c1e83c9fcfbd0
-- 
gitgitgadget
Next: Junio C Hamano
Message 1 of 2 in “parse-options.c: display subcommands properly in check_typos”
  1. parse-options.c: display subcommands properly in check_typosaubrey via GitGitGadget, Apr 6, 2026
  2. Junio C HamanoApr 6, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.