]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repo: show subcommand-specific help text
authorMahi Kassa <mahlet.takassa@gmail.com>
Wed, 25 Mar 2026 11:51:48 +0000 (12:51 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Mar 2026 17:35:27 +0000 (10:35 -0700)
Use subcommand-specific usage arrays for "git repo info" and
"git repo structure" so that each command shows only its own
synopsis in help output.

Add tests to cover the subcommand help behavior.

Signed-off-by: Mahi Kassa <mahlet.takassa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/repo.c
t/t1900-repo-info.sh
t/t1901-repo-structure.sh

index b5146499d08d332746db42868d3ff15950166b91..71a5c1c29c05fe4b285abe9cf313e20f555247ef 100644 (file)
@@ -33,6 +33,16 @@ static const char *const repo_usage[] = {
        NULL,
 };
 
+static const char *const repo_info_usage[] = {
+       REPO_INFO_USAGE,
+       NULL,
+};
+
+static const char *const repo_structure_usage[] = {
+       REPO_STRUCTURE_USAGE,
+       NULL,
+};
+
 typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
 
 enum output_format {
@@ -220,7 +230,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
                OPT_END()
        };
 
-       argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+       argc = parse_options(argc, argv, prefix, options, repo_info_usage, 0);
 
        if (show_keys && (all_keys || argc))
                die(_("--keys cannot be used with a <key> or --all"));
@@ -885,7 +895,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
                OPT_END()
        };
 
-       argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+       argc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);
        if (argc)
                usage(_("too many arguments"));
 
index a9eb07abe8aaea45e799c714fdc751b92002c186..39bb77dda0c327951a59778cfbaae7dfd488ebf9 100755 (executable)
@@ -149,4 +149,10 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
        test_cmp expect actual
 '
 
+test_expect_success 'git repo info -h shows only repo info usage' '
+       test_must_fail git repo info -h >actual &&
+       test_grep "git repo info" actual &&
+       test_grep ! "git repo structure" actual
+'
+
 test_done
index 98921ce1cbb66fd4e1238a8ebf26067ac3d39c8a..10050abd70fd67b6c7657557b5a49dd63474f99e 100755 (executable)
@@ -224,4 +224,10 @@ test_expect_success 'progress meter option' '
        )
 '
 
+test_expect_success 'git repo structure -h shows only repo structure usage' '
+       test_must_fail git repo structure -h >actual &&
+       test_grep "git repo structure" actual &&
+       test_grep ! "git repo info" actual
+'
+
 test_done