{"thread":{"id":"66775","subject":"[PATCH] credential: parse subcommands with OPT_SUBCOMMAND","startedAt":"2026-11-04T20:22:28Z","lastAt":"2026-11-14T18:47:52Z","messageCount":6,"participants":["Wasswa Edson","Tanga Joris"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"557500","messageId":"20261104202228.24642-1-edsonwasswa54@gmail.com","threadId":"66775","inReplyTo":null,"subject":"[PATCH] credential: parse subcommands with OPT_SUBCOMMAND","fromName":"Wasswa Edson","fromEmail":"edsonwasswa54@gmail.com","sentAt":"2026-11-04T20:22:28Z","receivedAt":"2026-11-04T20:22:28Z","isPatch":true,"sender":{"key":"edsonwasswa54@gmail.com","avatar":null},"body":"\"git credential\" dispatches its four subcommands (fill, approve,\nreject, capability) with a strcmp() chain after an argc check,\ninstead of using the parse-options API used by other builtins.\n\nConvert the dispatch to OPT_SUBCOMMAND(). Besides making the code\nshorter and more idiomatic, each subcommand gets its own usage\nstring, so \"git credential <subcommand> -h\" shows a targeted help\ntext, and the subcommand names are reported via\n--git-completion-helper.\n\nSince the builtin now uses parse-options, drop NO_PARSEOPT from its\ngit.c entry so \"git --list-cmds=parseopt\" includes it.\n\nTwo pre-existing inconsistencies are fixed while at it:\n\n- The usage string did not mention \"capability\" even though it is a\n  documented subcommand; it now lists all four.\n- Documentation/git-credential.adoc marked its SYNOPSIS as a plain\n  literal block, which t0450 cannot extract; mark it [verse] and drop\n  \"credential\" from t0450/adoc-help-mismatches.\n\nBehavior changes are limited to error paths: a missing or unknown\nsubcommand is reported as such (\"need a subcommand\" / \"unknown\nsubcommand\") before the usage text, instead of only showing the\nusage text, and \"git credential <subcommand> -h\" exits 0 after\nshowing the subcommand's usage. Exit codes for failures are\nunchanged (129).\n\nSigned-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n---\n Documentation/git-credential.adoc |   3 +-\n builtin/credential.c              | 148 ++++++++++++++++++++++++------\n git.c                             |   2 +-\n t/t0300-credentials.sh            |  18 ++++\n t/t0450/adoc-help-mismatches      |   1 -\n 5 files changed, 138 insertions(+), 34 deletions(-)\n\ndiff --git a/Documentation/git-credential.adoc b/Documentation/git-credential.adoc\nindex e41493292f..e12d429f43 100644\n--- a/Documentation/git-credential.adoc\n+++ b/Documentation/git-credential.adoc\n@@ -7,9 +7,8 @@ git-credential - Retrieve and store user credentials\n \n SYNOPSIS\n --------\n-------------------\n+[verse]\n 'git credential' (fill|approve|reject|capability)\n-------------------\n \n DESCRIPTION\n -----------\ndiff --git a/builtin/credential.c b/builtin/credential.c\nindex a295c80b36..7b398658bf 100644\n--- a/builtin/credential.c\n+++ b/builtin/credential.c\n@@ -5,48 +5,136 @@\n #include \"builtin.h\"\n #include \"environment.h\"\n #include \"config.h\"\n+#include \"gettext.h\"\n+#include \"parse-options.h\"\n \n-static const char usage_msg[] =\n-\t\"git credential (fill|approve|reject)\";\n+static const char * const credential_usage[] = {\n+\tN_(\"git credential (fill|approve|reject|capability)\"),\n+\tNULL,\n+};\n \n-int cmd_credential(int argc,\n-\t\t   const char **argv,\n-\t\t   const char *prefix UNUSED,\n-\t\t   struct repository *repo UNUSED)\n+static const char * const credential_fill_usage[] = {\n+\tN_(\"git credential fill\"),\n+\tNULL,\n+};\n+\n+static const char * const credential_approve_usage[] = {\n+\tN_(\"git credential approve\"),\n+\tNULL,\n+};\n+\n+static const char * const credential_reject_usage[] = {\n+\tN_(\"git credential reject\"),\n+\tNULL,\n+};\n+\n+static const char * const credential_capability_usage[] = {\n+\tN_(\"git credential capability\"),\n+\tNULL,\n+};\n+\n+static int cmd_credential_fill(int argc, const char **argv, const char *prefix,\n+\t\t\t       struct repository *repo UNUSED)\n {\n-\tconst char *op;\n+\tstruct option options[] = { OPT_END() };\n \tstruct credential c = CREDENTIAL_INIT;\n \n-\trepo_config(the_repository, git_default_config, NULL);\n+\targc = parse_options(argc, argv, prefix, options,\n+\t\t\t     credential_fill_usage, 0);\n+\tif (argc)\n+\t\tusage_with_options(credential_fill_usage, options);\n+\n+\tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n+\t\tdie(\"unable to read credential from stdin\");\n+\n+\tcredential_fill(the_repository, &c, 0);\n+\tcredential_next_state(&c);\n+\tcredential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);\n+\n+\tcredential_clear(&c);\n+\treturn 0;\n+}\n \n-\tshow_usage_if_asked(argc, argv, usage_msg);\n-\tif (argc != 2)\n-\t\tusage(usage_msg);\n-\top = argv[1];\n+static int cmd_credential_approve(int argc, const char **argv,\n+\t\t\t\tconst char *prefix,\n+\t\t\t\tstruct repository *repo UNUSED)\n+{\n+\tstruct option options[] = { OPT_END() };\n+\tstruct credential c = CREDENTIAL_INIT;\n \n-\tif (!strcmp(op, \"capability\")) {\n-\t\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_INITIAL);\n-\t\tcredential_announce_capabilities(&c, stdout);\n-\t\treturn 0;\n-\t}\n+\targc = parse_options(argc, argv, prefix, options,\n+\t\t\t     credential_approve_usage, 0);\n+\tif (argc)\n+\t\tusage_with_options(credential_approve_usage, options);\n \n \tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n \t\tdie(\"unable to read credential from stdin\");\n \n-\tif (!strcmp(op, \"fill\")) {\n-\t\tcredential_fill(the_repository, &c, 0);\n-\t\tcredential_next_state(&c);\n-\t\tcredential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);\n-\t} else if (!strcmp(op, \"approve\")) {\n-\t\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n-\t\tcredential_approve(the_repository, &c);\n-\t} else if (!strcmp(op, \"reject\")) {\n-\t\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n-\t\tcredential_reject(the_repository, &c);\n-\t} else {\n-\t\tusage(usage_msg);\n-\t}\n+\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n+\tcredential_approve(the_repository, &c);\n \n \tcredential_clear(&c);\n \treturn 0;\n }\n+\n+static int cmd_credential_reject(int argc, const char **argv,\n+\t\t\t\t const char *prefix,\n+\t\t\t\t struct repository *repo UNUSED)\n+{\n+\tstruct option options[] = { OPT_END() };\n+\tstruct credential c = CREDENTIAL_INIT;\n+\n+\targc = parse_options(argc, argv, prefix, options,\n+\t\t\t     credential_reject_usage, 0);\n+\tif (argc)\n+\t\tusage_with_options(credential_reject_usage, options);\n+\n+\tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n+\t\tdie(\"unable to read credential from stdin\");\n+\n+\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n+\tcredential_reject(the_repository, &c);\n+\n+\tcredential_clear(&c);\n+\treturn 0;\n+}\n+\n+static int cmd_credential_capability(int argc, const char **argv,\n+\t\t\t\t     const char *prefix,\n+\t\t\t\t     struct repository *repo UNUSED)\n+{\n+\tstruct option options[] = { OPT_END() };\n+\tstruct credential c = CREDENTIAL_INIT;\n+\n+\targc = parse_options(argc, argv, prefix, options,\n+\t\t\t     credential_capability_usage, 0);\n+\tif (argc)\n+\t\tusage_with_options(credential_capability_usage, options);\n+\n+\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_INITIAL);\n+\tcredential_announce_capabilities(&c, stdout);\n+\n+\tcredential_clear(&c);\n+\treturn 0;\n+}\n+\n+int cmd_credential(int argc,\n+\t\t   const char **argv,\n+\t\t   const char *prefix,\n+\t\t   struct repository *repo)\n+{\n+\tparse_opt_subcommand_fn *fn = NULL;\n+\tstruct option options[] = {\n+\t\tOPT_SUBCOMMAND(\"fill\", &fn, cmd_credential_fill),\n+\t\tOPT_SUBCOMMAND(\"approve\", &fn, cmd_credential_approve),\n+\t\tOPT_SUBCOMMAND(\"reject\", &fn, cmd_credential_reject),\n+\t\tOPT_SUBCOMMAND(\"capability\", &fn, cmd_credential_capability),\n+\t\tOPT_END()\n+\t};\n+\n+\trepo_config(the_repository, git_default_config, NULL);\n+\n+\targc = parse_options(argc, argv, prefix, options, credential_usage, 0);\n+\n+\treturn fn(argc, argv, prefix, repo);\n+}\ndiff --git a/git.c b/git.c\nindex d7b5f88e52..da370902ab 100644\n--- a/git.c\n+++ b/git.c\n@@ -562,7 +562,7 @@ static struct cmd_struct commands[] = {\n \t{ \"commit-tree\", cmd_commit_tree, RUN_SETUP },\n \t{ \"config\", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG },\n \t{ \"count-objects\", cmd_count_objects, RUN_SETUP },\n-\t{ \"credential\", cmd_credential, RUN_SETUP_GENTLY | NO_PARSEOPT },\n+\t{ \"credential\", cmd_credential, RUN_SETUP_GENTLY },\n \t{ \"credential-cache\", cmd_credential_cache },\n \t{ \"credential-cache--daemon\", cmd_credential_cache_daemon },\n \t{ \"credential-store\", cmd_credential_store },\ndiff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh\nindex ea11cdb4dc..ce230caff1 100755\n--- a/t/t0300-credentials.sh\n+++ b/t/t0300-credentials.sh\n@@ -1056,4 +1056,22 @@ test_expect_success 'interactive prompt is sanitized' '\n \tEOF\n '\n \n+test_expect_success 'credential subcommands -h show subcommand usage' '\n+\tfor sub in fill approve reject capability\n+\tdo\n+\t\tgit credential $sub -h >out &&\n+\t\ttest_grep \"^usage: git credential $sub\" out || return 1\n+\tdone\n+'\n+\n+test_expect_success 'credential requires a subcommand' '\n+\ttest_expect_code 129 git credential 2>err &&\n+\ttest_grep \"need a subcommand\" err\n+'\n+\n+test_expect_success 'credential rejects unknown subcommand' '\n+\ttest_expect_code 129 git credential foo 2>err &&\n+\ttest_grep \"unknown subcommand\" err\n+'\n+\n test_done\ndiff --git a/t/t0450/adoc-help-mismatches b/t/t0450/adoc-help-mismatches\nindex baf3b1d809..939e47bf3a 100644\n--- a/t/t0450/adoc-help-mismatches\n+++ b/t/t0450/adoc-help-mismatches\n@@ -9,7 +9,6 @@ checkout\n checkout-index\n clone\n column\n-credential\n credential-cache\n credential-store\n fetch-pack\n-- \n2.53.0\n\n\n"},{"id":"557865","messageId":"CAKrRMNqsh=d+_C8u+q1EBeQVwDZaywGQGZ89oYLyyvmB=8u1jw@mail.gmail.com","threadId":"66775","inReplyTo":"20261104202228.24642-1-edsonwasswa54@gmail.com","subject":"Re: [PATCH] credential: parse subcommands with OPT_SUBCOMMAND","fromName":"Tanga Joris","fromEmail":"tangajoris@gmail.com","sentAt":"2026-11-08T22:28:21Z","receivedAt":"2026-11-08T22:28:21Z","isPatch":true,"sender":{"key":"tangajoris@gmail.com","avatar":null},"body":"Hi Edson,\n\nThanks for working on this, nice work adding subcommands completion for\n\"git credential\".\n\nOn Thu, 5 Nov 2026 at 03:59, Wasswa Edson <edsonwasswa54@gmail.com> wrote:\n> Besides making the code\n> shorter and more idiomatic,\n\nbuiltin/credential.c goes from 52 lines to 140, so maybe \"shorter\"\ncould go.\n\nOverall, the patch looks good, but most of the new lines are the same\nparse_options() call and check, repeated four times. Maybe a small helper\nwould work here?\n\n> +     if (argc)\n> +             usage_with_options(credential_fill_usage, options);\n\nOne small thing: no test covers this check. When I removed it, t0300\nstill passed. Maybe something like this?\n\ntest_expect_success 'credential subcommands reject extra arguments' '\n        for sub in fill approve reject capability\n        do\n                test_expect_code 129 git credential $sub extra\n</dev/null || return 1\n        done\n'\n\nThanks,\nTanga\n\n"},{"id":"558477","messageId":"20261114184752.1417-1-edsonwasswa54@gmail.com","threadId":"66775","inReplyTo":"20261104202228.24642-1-edsonwasswa54@gmail.com","subject":"[PATCH v2 0/3] credential: parse subcommands with OPT_SUBCOMMAND","fromName":"Wasswa Edson","fromEmail":"edsonwasswa54@gmail.com","sentAt":"2026-11-14T18:47:49Z","receivedAt":"2026-11-14T18:47:49Z","isPatch":true,"sender":{"key":"edsonwasswa54@gmail.com","avatar":null},"body":"\"git credential\" dispatches its subcommands by hand with strcmp().\nThis series converts it to OPT_SUBCOMMAND(), so that each subcommand\ngets its own \"-h\" usage and the subcommand names become available\nto completion.\n\nChanges since v1:\n\n - Split into three patches. The pre-existing mismatch between the\n   \"-h\" output and the SYNOPSIS (1/3) and a refactor moving each\n   subcommand into its own function (2/3) are now separate from the\n   switch to OPT_SUBCOMMAND() (3/3).\n\n - Factor the repeated parse_options() call and argument check into\n   a helper, which rejects leftover arguments with \"too many\n   arguments\" (Tanga).\n\n - Add a test for the rejection of extra arguments (Tanga).\n\n - Drop the claim that the code gets shorter (Tanga).\n\nv1: https://lore.kernel.org/git/20261104202228.24642-1-edsonwasswa54@gmail.com/\n\nWasswa Edson (3):\n  credential: make -h output and SYNOPSIS agree\n  credential: move each subcommand into its own function\n  credential: parse subcommands with OPT_SUBCOMMAND\n\n Documentation/git-credential.adoc |   3 +-\n builtin/credential.c              | 143 +++++++++++++++++++++++-------\n git.c                             |   2 +-\n t/t0300-credentials.sh            |  27 ++++++\n t/t0450/adoc-help-mismatches      |   1 -\n 5 files changed, 142 insertions(+), 34 deletions(-)\n\nRange-diff against v1:\n-:  ---------- > 1:  d1bffb83df credential: make -h output and SYNOPSIS agree\n-:  ---------- > 2:  c7708ac31b credential: move each subcommand into its own function\n1:  85e3f2ce94 ! 3:  7c9842bb9e credential: parse subcommands with OPT_SUBCOMMAND\n    @@ Metadata\n      ## Commit message ##\n         credential: parse subcommands with OPT_SUBCOMMAND\n     \n    -    \"git credential\" dispatches its four subcommands (fill, approve,\n    -    reject, capability) with a strcmp() chain after an argc check,\n    -    instead of using the parse-options API used by other builtins.\n    +    Now that each subcommand of \"git credential\" lives in its own\n    +    function, switch the dispatch to OPT_SUBCOMMAND(). This gives each\n    +    subcommand its own usage string, so that \"git credential <subcommand>\n    +    -h\" shows help for that subcommand, and makes the subcommand names\n    +    available to the completion via --git-completion-helper.\n     \n    -    Convert the dispatch to OPT_SUBCOMMAND(). Besides making the code\n    -    shorter and more idiomatic, each subcommand gets its own usage\n    -    string, so \"git credential <subcommand> -h\" shows a targeted help\n    -    text, and the subcommand names are reported via\n    -    --git-completion-helper.\n    +    Each subcommand takes neither options nor arguments; reject any\n    +    with a common helper. Drop NO_PARSEOPT from the git.c entry, as the\n    +    command now uses parse-options.\n     \n    -    Since the builtin now uses parse-options, drop NO_PARSEOPT from its\n    -    git.c entry so \"git --list-cmds=parseopt\" includes it.\n    +    This changes the behavior only on error paths:\n     \n    -    Two pre-existing inconsistencies are fixed while at it:\n    +     - A missing or unknown subcommand is reported as such (\"need a\n    +       subcommand\" / \"unknown subcommand\") before the usage text.\n     \n    -    - The usage string did not mention \"capability\" even though it is a\n    -      documented subcommand; it now lists all four.\n    -    - Documentation/git-credential.adoc marked its SYNOPSIS as a plain\n    -      literal block, which t0450 cannot extract; mark it [verse] and drop\n    -      \"credential\" from t0450/adoc-help-mismatches.\n    +     - Extra arguments are reported as \"too many arguments\" before the\n    +       usage text of the subcommand.\n     \n    -    Behavior changes are limited to error paths: a missing or unknown\n    -    subcommand is reported as such (\"need a subcommand\" / \"unknown\n    -    subcommand\") before the usage text, instead of only showing the\n    -    usage text, and \"git credential <subcommand> -h\" exits 0 after\n    -    showing the subcommand's usage. Exit codes for failures are\n    -    unchanged (129).\n    +     - \"git credential <subcommand> -h\" shows the usage of that\n    +       subcommand and exits with 0, instead of failing with the usage of\n    +       the whole command.\n     \n    -    Signed-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n    +    Failures still exit with 129.\n     \n    - ## Documentation/git-credential.adoc ##\n    -@@ Documentation/git-credential.adoc: git-credential - Retrieve and store user credentials\n    - \n    - SYNOPSIS\n    - --------\n    --------------------\n    -+[verse]\n    - 'git credential' (fill|approve|reject|capability)\n    --------------------\n    - \n    - DESCRIPTION\n    - -----------\n    +    Helped-by: Tanga Joris <tangajoris@gmail.com>\n    +    Signed-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n     \n      ## builtin/credential.c ##\n     @@\n    @@ builtin/credential.c\n      #include \"config.h\"\n     +#include \"gettext.h\"\n     +#include \"parse-options.h\"\n    - \n    --static const char usage_msg[] =\n    --\t\"git credential (fill|approve|reject)\";\n    ++\n     +static const char * const credential_usage[] = {\n     +\tN_(\"git credential (fill|approve|reject|capability)\"),\n     +\tNULL,\n     +};\n    - \n    --int cmd_credential(int argc,\n    --\t\t   const char **argv,\n    --\t\t   const char *prefix UNUSED,\n    --\t\t   struct repository *repo UNUSED)\n    ++\n     +static const char * const credential_fill_usage[] = {\n     +\tN_(\"git credential fill\"),\n     +\tNULL,\n    @@ builtin/credential.c\n     +\tNULL,\n     +};\n     +\n    ++static void parse_no_args(int argc, const char **argv, const char *prefix,\n    ++\t\t\t  const char * const *usagestr)\n    ++{\n    ++\tstruct option options[] = {\n    ++\t\tOPT_END()\n    ++\t};\n    + \n    +-static const char usage_msg[] =\n    +-\t\"git credential (fill|approve|reject|capability)\";\n    ++\tif (parse_options(argc, argv, prefix, options, usagestr, 0))\n    ++\t\tusage_msg_opt(_(\"too many arguments\"), usagestr, options);\n    ++}\n    + \n    +-static int cmd_credential_fill(int argc UNUSED, const char **argv UNUSED,\n    +-\t\t\t       const char *prefix UNUSED,\n     +static int cmd_credential_fill(int argc, const char **argv, const char *prefix,\n    -+\t\t\t       struct repository *repo UNUSED)\n    + \t\t\t       struct repository *repo UNUSED)\n      {\n    --\tconst char *op;\n    -+\tstruct option options[] = { OPT_END() };\n      \tstruct credential c = CREDENTIAL_INIT;\n      \n    --\trepo_config(the_repository, git_default_config, NULL);\n    -+\targc = parse_options(argc, argv, prefix, options,\n    -+\t\t\t     credential_fill_usage, 0);\n    -+\tif (argc)\n    -+\t\tusage_with_options(credential_fill_usage, options);\n    -+\n    -+\tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n    -+\t\tdie(\"unable to read credential from stdin\");\n    ++\tparse_no_args(argc, argv, prefix, credential_fill_usage);\n     +\n    -+\tcredential_fill(the_repository, &c, 0);\n    -+\tcredential_next_state(&c);\n    -+\tcredential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);\n    -+\n    -+\tcredential_clear(&c);\n    -+\treturn 0;\n    -+}\n    + \tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n    + \t\tdie(\"unable to read credential from stdin\");\n      \n    --\tshow_usage_if_asked(argc, argv, usage_msg);\n    --\tif (argc != 2)\n    --\t\tusage(usage_msg);\n    --\top = argv[1];\n    -+static int cmd_credential_approve(int argc, const char **argv,\n    -+\t\t\t\tconst char *prefix,\n    -+\t\t\t\tstruct repository *repo UNUSED)\n    -+{\n    -+\tstruct option options[] = { OPT_END() };\n    -+\tstruct credential c = CREDENTIAL_INIT;\n    +@@ builtin/credential.c: static int cmd_credential_fill(int argc UNUSED, const char **argv UNUSED,\n    + \treturn 0;\n    + }\n      \n    --\tif (!strcmp(op, \"capability\")) {\n    --\t\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_INITIAL);\n    --\t\tcredential_announce_capabilities(&c, stdout);\n    --\t\treturn 0;\n    --\t}\n    -+\targc = parse_options(argc, argv, prefix, options,\n    -+\t\t\t     credential_approve_usage, 0);\n    -+\tif (argc)\n    -+\t\tusage_with_options(credential_approve_usage, options);\n    +-static int cmd_credential_approve(int argc UNUSED, const char **argv UNUSED,\n    +-\t\t\t\t  const char *prefix UNUSED,\n    ++static int cmd_credential_approve(int argc, const char **argv,\n    ++\t\t\t\t  const char *prefix,\n    + \t\t\t\t  struct repository *repo UNUSED)\n    + {\n    + \tstruct credential c = CREDENTIAL_INIT;\n      \n    ++\tparse_no_args(argc, argv, prefix, credential_approve_usage);\n    ++\n      \tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n      \t\tdie(\"unable to read credential from stdin\");\n      \n    --\tif (!strcmp(op, \"fill\")) {\n    --\t\tcredential_fill(the_repository, &c, 0);\n    --\t\tcredential_next_state(&c);\n    --\t\tcredential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);\n    --\t} else if (!strcmp(op, \"approve\")) {\n    --\t\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n    --\t\tcredential_approve(the_repository, &c);\n    --\t} else if (!strcmp(op, \"reject\")) {\n    --\t\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n    --\t\tcredential_reject(the_repository, &c);\n    --\t} else {\n    --\t\tusage(usage_msg);\n    --\t}\n    -+\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n    -+\tcredential_approve(the_repository, &c);\n    - \n    - \tcredential_clear(&c);\n    +@@ builtin/credential.c: static int cmd_credential_approve(int argc UNUSED, const char **argv UNUSED,\n      \treturn 0;\n      }\n    -+\n    + \n    +-static int cmd_credential_reject(int argc UNUSED, const char **argv UNUSED,\n    +-\t\t\t\t const char *prefix UNUSED,\n     +static int cmd_credential_reject(int argc, const char **argv,\n     +\t\t\t\t const char *prefix,\n    -+\t\t\t\t struct repository *repo UNUSED)\n    -+{\n    -+\tstruct option options[] = { OPT_END() };\n    -+\tstruct credential c = CREDENTIAL_INIT;\n    -+\n    -+\targc = parse_options(argc, argv, prefix, options,\n    -+\t\t\t     credential_reject_usage, 0);\n    -+\tif (argc)\n    -+\t\tusage_with_options(credential_reject_usage, options);\n    -+\n    -+\tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n    -+\t\tdie(\"unable to read credential from stdin\");\n    -+\n    -+\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n    -+\tcredential_reject(the_repository, &c);\n    -+\n    -+\tcredential_clear(&c);\n    -+\treturn 0;\n    -+}\n    + \t\t\t\t struct repository *repo UNUSED)\n    + {\n    + \tstruct credential c = CREDENTIAL_INIT;\n    + \n    ++\tparse_no_args(argc, argv, prefix, credential_reject_usage);\n     +\n    + \tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n    + \t\tdie(\"unable to read credential from stdin\");\n    + \n    +@@ builtin/credential.c: static int cmd_credential_reject(int argc UNUSED, const char **argv UNUSED,\n    + \treturn 0;\n    + }\n    + \n    +-static int cmd_credential_capability(int argc UNUSED,\n    +-\t\t\t\t     const char **argv UNUSED,\n    +-\t\t\t\t     const char *prefix UNUSED,\n     +static int cmd_credential_capability(int argc, const char **argv,\n     +\t\t\t\t     const char *prefix,\n    -+\t\t\t\t     struct repository *repo UNUSED)\n    -+{\n    -+\tstruct option options[] = { OPT_END() };\n    -+\tstruct credential c = CREDENTIAL_INIT;\n    -+\n    -+\targc = parse_options(argc, argv, prefix, options,\n    -+\t\t\t     credential_capability_usage, 0);\n    -+\tif (argc)\n    -+\t\tusage_with_options(credential_capability_usage, options);\n    -+\n    -+\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_INITIAL);\n    -+\tcredential_announce_capabilities(&c, stdout);\n    -+\n    -+\tcredential_clear(&c);\n    -+\treturn 0;\n    -+}\n    + \t\t\t\t     struct repository *repo UNUSED)\n    + {\n    + \tstruct credential c = CREDENTIAL_INIT;\n    + \n    ++\tparse_no_args(argc, argv, prefix, credential_capability_usage);\n     +\n    -+int cmd_credential(int argc,\n    -+\t\t   const char **argv,\n    -+\t\t   const char *prefix,\n    -+\t\t   struct repository *repo)\n    -+{\n    + \tcredential_set_all_capabilities(&c, CREDENTIAL_OP_INITIAL);\n    + \tcredential_announce_capabilities(&c, stdout);\n    + \n    +@@ builtin/credential.c: int cmd_credential(int argc,\n    + \t\t   const char *prefix,\n    + \t\t   struct repository *repo)\n    + {\n    +-\tconst char *op;\n     +\tparse_opt_subcommand_fn *fn = NULL;\n     +\tstruct option options[] = {\n     +\t\tOPT_SUBCOMMAND(\"fill\", &fn, cmd_credential_fill),\n    @@ builtin/credential.c\n     +\t\tOPT_SUBCOMMAND(\"capability\", &fn, cmd_credential_capability),\n     +\t\tOPT_END()\n     +\t};\n    -+\n    -+\trepo_config(the_repository, git_default_config, NULL);\n    -+\n    + \n    + \trepo_config(the_repository, git_default_config, NULL);\n    + \n    +-\tshow_usage_if_asked(argc, argv, usage_msg);\n    +-\tif (argc != 2)\n    +-\t\tusage(usage_msg);\n    +-\top = argv[1];\n    +-\n    +-\tif (!strcmp(op, \"fill\"))\n    +-\t\treturn cmd_credential_fill(argc - 1, argv + 1, prefix, repo);\n    +-\tif (!strcmp(op, \"approve\"))\n    +-\t\treturn cmd_credential_approve(argc - 1, argv + 1, prefix, repo);\n    +-\tif (!strcmp(op, \"reject\"))\n    +-\t\treturn cmd_credential_reject(argc - 1, argv + 1, prefix, repo);\n    +-\tif (!strcmp(op, \"capability\"))\n    +-\t\treturn cmd_credential_capability(argc - 1, argv + 1, prefix,\n    +-\t\t\t\t\t\t repo);\n    +-\n    +-\tusage(usage_msg);\n     +\targc = parse_options(argc, argv, prefix, options, credential_usage, 0);\n     +\n     +\treturn fn(argc, argv, prefix, repo);\n    -+}\n    + }\n     \n      ## git.c ##\n     @@ git.c: static struct cmd_struct commands[] = {\n    @@ t/t0300-credentials.sh: test_expect_success 'interactive prompt is sanitized' '\n     +\ttest_expect_code 129 git credential foo 2>err &&\n     +\ttest_grep \"unknown subcommand\" err\n     +'\n    ++\n    ++test_expect_success 'credential subcommands reject extra arguments' '\n    ++\tfor sub in fill approve reject capability\n    ++\tdo\n    ++\t\ttest_expect_code 129 git credential $sub extra \\\n    ++\t\t\t</dev/null 2>err &&\n    ++\t\ttest_grep \"too many arguments\" err || return 1\n    ++\tdone\n    ++'\n     +\n      test_done\n    -\n    - ## t/t0450/adoc-help-mismatches ##\n    -@@ t/t0450/adoc-help-mismatches: checkout\n    - checkout-index\n    - clone\n    - column\n    --credential\n    - credential-cache\n    - credential-store\n    - fetch-pack\n\nbase-commit: 37b3475fb530c14109211faca33716a173db61ed\n-- \n2.53.0\n\n\n"},{"id":"558478","messageId":"20261114184752.1417-2-edsonwasswa54@gmail.com","threadId":"66775","inReplyTo":"20261114184752.1417-1-edsonwasswa54@gmail.com","subject":"[PATCH v2 1/3] credential: make -h output and SYNOPSIS agree","fromName":"Wasswa Edson","fromEmail":"edsonwasswa54@gmail.com","sentAt":"2026-11-14T18:47:50Z","receivedAt":"2026-11-14T18:47:50Z","isPatch":true,"sender":{"key":"edsonwasswa54@gmail.com","avatar":null},"body":"The usage string of \"git credential\" does not mention the\n\"capability\" subcommand, even though it is documented and\nimplemented. The SYNOPSIS in its documentation does list it, but\nis written as a plain literal block instead of using [verse], so\nt0450 cannot extract it, and \"credential\" has been listed as a\nknown mismatch between the \"-h\" output and the documentation.\n\nAdd \"capability\" to the usage string, mark the SYNOPSIS as\n[verse], and drop \"credential\" from the list of known mismatches.\n\nSigned-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n---\n Documentation/git-credential.adoc | 3 +--\n builtin/credential.c              | 2 +-\n t/t0450/adoc-help-mismatches      | 1 -\n 3 files changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-credential.adoc b/Documentation/git-credential.adoc\nindex e41493292f..e12d429f43 100644\n--- a/Documentation/git-credential.adoc\n+++ b/Documentation/git-credential.adoc\n@@ -7,9 +7,8 @@ git-credential - Retrieve and store user credentials\n \n SYNOPSIS\n --------\n-------------------\n+[verse]\n 'git credential' (fill|approve|reject|capability)\n-------------------\n \n DESCRIPTION\n -----------\ndiff --git a/builtin/credential.c b/builtin/credential.c\nindex a295c80b36..72e7b2af4e 100644\n--- a/builtin/credential.c\n+++ b/builtin/credential.c\n@@ -7,7 +7,7 @@\n #include \"config.h\"\n \n static const char usage_msg[] =\n-\t\"git credential (fill|approve|reject)\";\n+\t\"git credential (fill|approve|reject|capability)\";\n \n int cmd_credential(int argc,\n \t\t   const char **argv,\ndiff --git a/t/t0450/adoc-help-mismatches b/t/t0450/adoc-help-mismatches\nindex baf3b1d809..939e47bf3a 100644\n--- a/t/t0450/adoc-help-mismatches\n+++ b/t/t0450/adoc-help-mismatches\n@@ -9,7 +9,6 @@ checkout\n checkout-index\n clone\n column\n-credential\n credential-cache\n credential-store\n fetch-pack\n-- \n2.53.0\n\n\n"},{"id":"558479","messageId":"20261114184752.1417-3-edsonwasswa54@gmail.com","threadId":"66775","inReplyTo":"20261114184752.1417-1-edsonwasswa54@gmail.com","subject":"[PATCH v2 2/3] credential: move each subcommand into its own function","fromName":"Wasswa Edson","fromEmail":"edsonwasswa54@gmail.com","sentAt":"2026-11-14T18:47:51Z","receivedAt":"2026-11-14T18:47:51Z","isPatch":true,"sender":{"key":"edsonwasswa54@gmail.com","avatar":null},"body":"cmd_credential() handles all of its subcommands inline, sharing a\nsingle \"struct credential\" and dispatching with a chain of\nstrcmp() calls.\n\nMove each subcommand into its own function with the signature\nexpected by parse-options' subcommand callbacks, in preparation for\nswitching the dispatch to OPT_SUBCOMMAND() in the next commit.\n\nThe only change in behavior is that an unknown subcommand is now\nrejected before reading a credential from the standard input.\n\nSigned-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n---\n builtin/credential.c | 102 +++++++++++++++++++++++++++++++------------\n 1 file changed, 75 insertions(+), 27 deletions(-)\n\ndiff --git a/builtin/credential.c b/builtin/credential.c\nindex 72e7b2af4e..d6ba21a2cb 100644\n--- a/builtin/credential.c\n+++ b/builtin/credential.c\n@@ -9,13 +9,75 @@\n static const char usage_msg[] =\n \t\"git credential (fill|approve|reject|capability)\";\n \n+static int cmd_credential_fill(int argc UNUSED, const char **argv UNUSED,\n+\t\t\t       const char *prefix UNUSED,\n+\t\t\t       struct repository *repo UNUSED)\n+{\n+\tstruct credential c = CREDENTIAL_INIT;\n+\n+\tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n+\t\tdie(\"unable to read credential from stdin\");\n+\n+\tcredential_fill(the_repository, &c, 0);\n+\tcredential_next_state(&c);\n+\tcredential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);\n+\n+\tcredential_clear(&c);\n+\treturn 0;\n+}\n+\n+static int cmd_credential_approve(int argc UNUSED, const char **argv UNUSED,\n+\t\t\t\t  const char *prefix UNUSED,\n+\t\t\t\t  struct repository *repo UNUSED)\n+{\n+\tstruct credential c = CREDENTIAL_INIT;\n+\n+\tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n+\t\tdie(\"unable to read credential from stdin\");\n+\n+\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n+\tcredential_approve(the_repository, &c);\n+\n+\tcredential_clear(&c);\n+\treturn 0;\n+}\n+\n+static int cmd_credential_reject(int argc UNUSED, const char **argv UNUSED,\n+\t\t\t\t const char *prefix UNUSED,\n+\t\t\t\t struct repository *repo UNUSED)\n+{\n+\tstruct credential c = CREDENTIAL_INIT;\n+\n+\tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n+\t\tdie(\"unable to read credential from stdin\");\n+\n+\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n+\tcredential_reject(the_repository, &c);\n+\n+\tcredential_clear(&c);\n+\treturn 0;\n+}\n+\n+static int cmd_credential_capability(int argc UNUSED,\n+\t\t\t\t     const char **argv UNUSED,\n+\t\t\t\t     const char *prefix UNUSED,\n+\t\t\t\t     struct repository *repo UNUSED)\n+{\n+\tstruct credential c = CREDENTIAL_INIT;\n+\n+\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_INITIAL);\n+\tcredential_announce_capabilities(&c, stdout);\n+\n+\tcredential_clear(&c);\n+\treturn 0;\n+}\n+\n int cmd_credential(int argc,\n \t\t   const char **argv,\n-\t\t   const char *prefix UNUSED,\n-\t\t   struct repository *repo UNUSED)\n+\t\t   const char *prefix,\n+\t\t   struct repository *repo)\n {\n \tconst char *op;\n-\tstruct credential c = CREDENTIAL_INIT;\n \n \trepo_config(the_repository, git_default_config, NULL);\n \n@@ -24,29 +86,15 @@ int cmd_credential(int argc,\n \t\tusage(usage_msg);\n \top = argv[1];\n \n-\tif (!strcmp(op, \"capability\")) {\n-\t\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_INITIAL);\n-\t\tcredential_announce_capabilities(&c, stdout);\n-\t\treturn 0;\n-\t}\n-\n-\tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n-\t\tdie(\"unable to read credential from stdin\");\n-\n-\tif (!strcmp(op, \"fill\")) {\n-\t\tcredential_fill(the_repository, &c, 0);\n-\t\tcredential_next_state(&c);\n-\t\tcredential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);\n-\t} else if (!strcmp(op, \"approve\")) {\n-\t\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n-\t\tcredential_approve(the_repository, &c);\n-\t} else if (!strcmp(op, \"reject\")) {\n-\t\tcredential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);\n-\t\tcredential_reject(the_repository, &c);\n-\t} else {\n-\t\tusage(usage_msg);\n-\t}\n+\tif (!strcmp(op, \"fill\"))\n+\t\treturn cmd_credential_fill(argc - 1, argv + 1, prefix, repo);\n+\tif (!strcmp(op, \"approve\"))\n+\t\treturn cmd_credential_approve(argc - 1, argv + 1, prefix, repo);\n+\tif (!strcmp(op, \"reject\"))\n+\t\treturn cmd_credential_reject(argc - 1, argv + 1, prefix, repo);\n+\tif (!strcmp(op, \"capability\"))\n+\t\treturn cmd_credential_capability(argc - 1, argv + 1, prefix,\n+\t\t\t\t\t\t repo);\n \n-\tcredential_clear(&c);\n-\treturn 0;\n+\tusage(usage_msg);\n }\n-- \n2.53.0\n\n\n"},{"id":"558480","messageId":"20261114184752.1417-4-edsonwasswa54@gmail.com","threadId":"66775","inReplyTo":"20261114184752.1417-1-edsonwasswa54@gmail.com","subject":"[PATCH v2 3/3] credential: parse subcommands with OPT_SUBCOMMAND","fromName":"Wasswa Edson","fromEmail":"edsonwasswa54@gmail.com","sentAt":"2026-11-14T18:47:52Z","receivedAt":"2026-11-14T18:47:52Z","isPatch":true,"sender":{"key":"edsonwasswa54@gmail.com","avatar":null},"body":"Now that each subcommand of \"git credential\" lives in its own\nfunction, switch the dispatch to OPT_SUBCOMMAND(). This gives each\nsubcommand its own usage string, so that \"git credential <subcommand>\n-h\" shows help for that subcommand, and makes the subcommand names\navailable to the completion via --git-completion-helper.\n\nEach subcommand takes neither options nor arguments; reject any\nwith a common helper. Drop NO_PARSEOPT from the git.c entry, as the\ncommand now uses parse-options.\n\nThis changes the behavior only on error paths:\n\n - A missing or unknown subcommand is reported as such (\"need a\n   subcommand\" / \"unknown subcommand\") before the usage text.\n\n - Extra arguments are reported as \"too many arguments\" before the\n   usage text of the subcommand.\n\n - \"git credential <subcommand> -h\" shows the usage of that\n   subcommand and exits with 0, instead of failing with the usage of\n   the whole command.\n\nFailures still exit with 129.\n\nHelped-by: Tanga Joris <tangajoris@gmail.com>\nSigned-off-by: Wasswa Edson <edsonwasswa54@gmail.com>\n---\n builtin/credential.c   | 91 +++++++++++++++++++++++++++++-------------\n git.c                  |  2 +-\n t/t0300-credentials.sh | 27 +++++++++++++\n 3 files changed, 91 insertions(+), 29 deletions(-)\n\ndiff --git a/builtin/credential.c b/builtin/credential.c\nindex d6ba21a2cb..b9945d019b 100644\n--- a/builtin/credential.c\n+++ b/builtin/credential.c\n@@ -5,16 +5,52 @@\n #include \"builtin.h\"\n #include \"environment.h\"\n #include \"config.h\"\n+#include \"gettext.h\"\n+#include \"parse-options.h\"\n+\n+static const char * const credential_usage[] = {\n+\tN_(\"git credential (fill|approve|reject|capability)\"),\n+\tNULL,\n+};\n+\n+static const char * const credential_fill_usage[] = {\n+\tN_(\"git credential fill\"),\n+\tNULL,\n+};\n+\n+static const char * const credential_approve_usage[] = {\n+\tN_(\"git credential approve\"),\n+\tNULL,\n+};\n+\n+static const char * const credential_reject_usage[] = {\n+\tN_(\"git credential reject\"),\n+\tNULL,\n+};\n+\n+static const char * const credential_capability_usage[] = {\n+\tN_(\"git credential capability\"),\n+\tNULL,\n+};\n+\n+static void parse_no_args(int argc, const char **argv, const char *prefix,\n+\t\t\t  const char * const *usagestr)\n+{\n+\tstruct option options[] = {\n+\t\tOPT_END()\n+\t};\n \n-static const char usage_msg[] =\n-\t\"git credential (fill|approve|reject|capability)\";\n+\tif (parse_options(argc, argv, prefix, options, usagestr, 0))\n+\t\tusage_msg_opt(_(\"too many arguments\"), usagestr, options);\n+}\n \n-static int cmd_credential_fill(int argc UNUSED, const char **argv UNUSED,\n-\t\t\t       const char *prefix UNUSED,\n+static int cmd_credential_fill(int argc, const char **argv, const char *prefix,\n \t\t\t       struct repository *repo UNUSED)\n {\n \tstruct credential c = CREDENTIAL_INIT;\n \n+\tparse_no_args(argc, argv, prefix, credential_fill_usage);\n+\n \tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n \t\tdie(\"unable to read credential from stdin\");\n \n@@ -26,12 +62,14 @@ static int cmd_credential_fill(int argc UNUSED, const char **argv UNUSED,\n \treturn 0;\n }\n \n-static int cmd_credential_approve(int argc UNUSED, const char **argv UNUSED,\n-\t\t\t\t  const char *prefix UNUSED,\n+static int cmd_credential_approve(int argc, const char **argv,\n+\t\t\t\t  const char *prefix,\n \t\t\t\t  struct repository *repo UNUSED)\n {\n \tstruct credential c = CREDENTIAL_INIT;\n \n+\tparse_no_args(argc, argv, prefix, credential_approve_usage);\n+\n \tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n \t\tdie(\"unable to read credential from stdin\");\n \n@@ -42,12 +80,14 @@ static int cmd_credential_approve(int argc UNUSED, const char **argv UNUSED,\n \treturn 0;\n }\n \n-static int cmd_credential_reject(int argc UNUSED, const char **argv UNUSED,\n-\t\t\t\t const char *prefix UNUSED,\n+static int cmd_credential_reject(int argc, const char **argv,\n+\t\t\t\t const char *prefix,\n \t\t\t\t struct repository *repo UNUSED)\n {\n \tstruct credential c = CREDENTIAL_INIT;\n \n+\tparse_no_args(argc, argv, prefix, credential_reject_usage);\n+\n \tif (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)\n \t\tdie(\"unable to read credential from stdin\");\n \n@@ -58,13 +98,14 @@ static int cmd_credential_reject(int argc UNUSED, const char **argv UNUSED,\n \treturn 0;\n }\n \n-static int cmd_credential_capability(int argc UNUSED,\n-\t\t\t\t     const char **argv UNUSED,\n-\t\t\t\t     const char *prefix UNUSED,\n+static int cmd_credential_capability(int argc, const char **argv,\n+\t\t\t\t     const char *prefix,\n \t\t\t\t     struct repository *repo UNUSED)\n {\n \tstruct credential c = CREDENTIAL_INIT;\n \n+\tparse_no_args(argc, argv, prefix, credential_capability_usage);\n+\n \tcredential_set_all_capabilities(&c, CREDENTIAL_OP_INITIAL);\n \tcredential_announce_capabilities(&c, stdout);\n \n@@ -77,24 +118,18 @@ int cmd_credential(int argc,\n \t\t   const char *prefix,\n \t\t   struct repository *repo)\n {\n-\tconst char *op;\n+\tparse_opt_subcommand_fn *fn = NULL;\n+\tstruct option options[] = {\n+\t\tOPT_SUBCOMMAND(\"fill\", &fn, cmd_credential_fill),\n+\t\tOPT_SUBCOMMAND(\"approve\", &fn, cmd_credential_approve),\n+\t\tOPT_SUBCOMMAND(\"reject\", &fn, cmd_credential_reject),\n+\t\tOPT_SUBCOMMAND(\"capability\", &fn, cmd_credential_capability),\n+\t\tOPT_END()\n+\t};\n \n \trepo_config(the_repository, git_default_config, NULL);\n \n-\tshow_usage_if_asked(argc, argv, usage_msg);\n-\tif (argc != 2)\n-\t\tusage(usage_msg);\n-\top = argv[1];\n-\n-\tif (!strcmp(op, \"fill\"))\n-\t\treturn cmd_credential_fill(argc - 1, argv + 1, prefix, repo);\n-\tif (!strcmp(op, \"approve\"))\n-\t\treturn cmd_credential_approve(argc - 1, argv + 1, prefix, repo);\n-\tif (!strcmp(op, \"reject\"))\n-\t\treturn cmd_credential_reject(argc - 1, argv + 1, prefix, repo);\n-\tif (!strcmp(op, \"capability\"))\n-\t\treturn cmd_credential_capability(argc - 1, argv + 1, prefix,\n-\t\t\t\t\t\t repo);\n-\n-\tusage(usage_msg);\n+\targc = parse_options(argc, argv, prefix, options, credential_usage, 0);\n+\n+\treturn fn(argc, argv, prefix, repo);\n }\ndiff --git a/git.c b/git.c\nindex d7b5f88e52..da370902ab 100644\n--- a/git.c\n+++ b/git.c\n@@ -562,7 +562,7 @@ static struct cmd_struct commands[] = {\n \t{ \"commit-tree\", cmd_commit_tree, RUN_SETUP },\n \t{ \"config\", cmd_config, RUN_SETUP_GENTLY | DELAY_PAGER_CONFIG },\n \t{ \"count-objects\", cmd_count_objects, RUN_SETUP },\n-\t{ \"credential\", cmd_credential, RUN_SETUP_GENTLY | NO_PARSEOPT },\n+\t{ \"credential\", cmd_credential, RUN_SETUP_GENTLY },\n \t{ \"credential-cache\", cmd_credential_cache },\n \t{ \"credential-cache--daemon\", cmd_credential_cache_daemon },\n \t{ \"credential-store\", cmd_credential_store },\ndiff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh\nindex ea11cdb4dc..858996ac4a 100755\n--- a/t/t0300-credentials.sh\n+++ b/t/t0300-credentials.sh\n@@ -1056,4 +1056,31 @@ test_expect_success 'interactive prompt is sanitized' '\n \tEOF\n '\n \n+test_expect_success 'credential subcommands -h show subcommand usage' '\n+\tfor sub in fill approve reject capability\n+\tdo\n+\t\tgit credential $sub -h >out &&\n+\t\ttest_grep \"^usage: git credential $sub\" out || return 1\n+\tdone\n+'\n+\n+test_expect_success 'credential requires a subcommand' '\n+\ttest_expect_code 129 git credential 2>err &&\n+\ttest_grep \"need a subcommand\" err\n+'\n+\n+test_expect_success 'credential rejects unknown subcommand' '\n+\ttest_expect_code 129 git credential foo 2>err &&\n+\ttest_grep \"unknown subcommand\" err\n+'\n+\n+test_expect_success 'credential subcommands reject extra arguments' '\n+\tfor sub in fill approve reject capability\n+\tdo\n+\t\ttest_expect_code 129 git credential $sub extra \\\n+\t\t\t</dev/null 2>err &&\n+\t\ttest_grep \"too many arguments\" err || return 1\n+\tdone\n+'\n+\n test_done\n-- \n2.53.0\n\n\n"}]}