{"thread":{"id":"65447","subject":"[PATCH] parse-options.c: display subcommands properly in check_typos","startedAt":"2026-04-06T18:38:29Z","lastAt":"2026-04-06T19:27:19Z","messageCount":2,"participants":["aubrey via GitGitGadget","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"541010","messageId":"pull.2084.git.1775500706920.gitgitgadget@gmail.com","threadId":"65447","inReplyTo":null,"subject":"[PATCH] parse-options.c: display subcommands properly in check_typos","fromName":"aubrey via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-04-06T18:38:26Z","receivedAt":"2026-04-06T18:38:29Z","isPatch":true,"body":"From: aubymori <aubyomori@gmail.com>\n\nBefore this, mistyping a subcommand with one dash (e.g. `git stash -list`)\nwould display a message telling the user to try it with two dashes.\nSince subcommands are parsed with no dashes, this is incorrect and simply\nresults in the help message for that command being shown.\n\nThis commit changes check_typos to check the command type and display a\nproper message for subcommands.\n\nSigned-off-by: aubymori <aubyomori@gmail.com>\n---\n    parse-options.c: display subcommands properly in check_typos\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2084%2Faubymori%2Fmaster-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2084/aubymori/master-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2084\n\n parse-options.c | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/parse-options.c b/parse-options.c\nindex a676da86f5..2c4530bb8c 100644\n--- a/parse-options.c\n+++ b/parse-options.c\n@@ -633,7 +633,10 @@ static void check_typos(const char *arg, const struct option *options)\n \t\tif (!options->long_name)\n \t\t\tcontinue;\n \t\tif (starts_with(options->long_name, arg)) {\n-\t\t\terror(_(\"did you mean `--%s` (with two dashes)?\"), arg);\n+\t\t\tif (options->type == OPTION_SUBCOMMAND)\n+\t\t\t\terror(_(\"did you mean `%s` (with no dash)?\"), arg);\n+\t\t\telse\n+\t\t\t\terror(_(\"did you mean `--%s` (with two dashes)?\"), arg);\n \t\t\texit(129);\n \t\t}\n \t}\n\nbase-commit: 2855562ca6a9c6b0e7bc780b050c1e83c9fcfbd0\n-- \ngitgitgadget\n"},{"id":"541013","messageId":"xmqqy0izanze.fsf@gitster.g","threadId":"65447","inReplyTo":"pull.2084.git.1775500706920.gitgitgadget@gmail.com","subject":"Re: [PATCH] parse-options.c: display subcommands properly in check_typos","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-04-06T19:27:17Z","receivedAt":"2026-04-06T19:27:19Z","isPatch":true,"body":"\"aubrey via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: aubymori <aubyomori@gmail.com>\n>\n> Before this, mistyping a subcommand with one dash (e.g. `git stash -list`)\n> would display a message telling the user to try it with two dashes.\n> Since subcommands are parsed with no dashes, this is incorrect and simply\n> results in the help message for that command being shown.\n>\n> This commit changes check_typos to check the command type and display a\n> proper message for subcommands.\n\nThe usual way to compose a log message of this project is to\n\n - Give an observation on how the current system works in the\n   present tense (so no need to say \"Currently X is Y\", or\n   \"Previously X was Y\" to describe the state before your change;\n   just \"X is Y\" is enough), and discuss what you perceive as a\n   problem in it.\n\n - Propose a solution (optional---often, problem description\n   trivially leads to an obvious solution in reader's minds).\n\n - Give commands to somebody editing the codebase to \"make it so\",\n   instead of saying \"This commit does X\".\n\nin this order.\n\nSo, \"Before this, \" is unneeded, \"This commit changes\" should be\nmore like\n\n    Make check_typoes() check the command type and show a proper\n    message for subcommands.\n\nAlso it would want a new test to cover this case somewhere.  I am\nnot sure where, though perhaps a new test in t0040 with update to\nt/helper/test-parse-options.c or something like that.\n\nThis is a tangent, but I was hoping that \"git stash lost\" or \"git\nremote got-url origin\" would get their misspelt subcommand names\ncorrected with this fix, but that is not what this patch alone can\ndo, because all calls to check_typos() in parse_options_step() are\ngated with (*arg == '-') and cannot kick in for these two examples.\nparse_options_step() instead routes such input to parse_nodash_opt()\nand there is no such typo correction there.\n\nIt is not so surprising that nobody has complained about this, as I\nunderstand that the condition to trigger this is rather narrow.  You\nhave to give a single '-' (not two, only one) before a subcommand\nthat usually is spelled without any dash in front in order to\ntrigger it?\n\nThanks.\n\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2084%2Faubymori%2Fmaster-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2084/aubymori/master-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/2084\n>\n>  parse-options.c | 5 ++++-\n>  1 file changed, 4 insertions(+), 1 deletion(-)\n>\n> diff --git a/parse-options.c b/parse-options.c\n> index a676da86f5..2c4530bb8c 100644\n> --- a/parse-options.c\n> +++ b/parse-options.c\n> @@ -633,7 +633,10 @@ static void check_typos(const char *arg, const struct option *options)\n>  \t\tif (!options->long_name)\n>  \t\t\tcontinue;\n>  \t\tif (starts_with(options->long_name, arg)) {\n> -\t\t\terror(_(\"did you mean `--%s` (with two dashes)?\"), arg);\n> +\t\t\tif (options->type == OPTION_SUBCOMMAND)\n> +\t\t\t\terror(_(\"did you mean `%s` (with no dash)?\"), arg);\n> +\t\t\telse\n> +\t\t\t\terror(_(\"did you mean `--%s` (with two dashes)?\"), arg);\n>  \t\t\texit(129);\n>  \t\t}\n>  \t}\n>\n> base-commit: 2855562ca6a9c6b0e7bc780b050c1e83c9fcfbd0\n"}]}