repo: show subcommand-specific help text

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>

Mahi Kassa committed Mar 25, 2026 at 12:51 UTC abd728cdf6ea0164cfd7ede2223f669037ff531d
3 files changed +24 -2
builtin/repo.c
+12 -2
@@ -33,6 +33,16 @@ static const char *const repo_usage[] = {
33 NULL,
34 };
35
36 +static const char *const repo_info_usage[] = {
37 + REPO_INFO_USAGE,
38 + NULL,
39 +};
40 +
41 +static const char *const repo_structure_usage[] = {
42 + REPO_STRUCTURE_USAGE,
43 + NULL,
44 +};
45 +
46 typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
47
48 enum output_format {
@@ -220,7 +230,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
230 OPT_END()
231 };
232
223 - argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
233 + argc = parse_options(argc, argv, prefix, options, repo_info_usage, 0);
234
235 if (show_keys && (all_keys || argc))
236 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,
895 OPT_END()
896 };
897
888 - argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
898 + argc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);
899 if (argc)
900 usage(_("too many arguments"));
901
t/t1900-repo-info.sh
+6
@@ -149,4 +149,10 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
149 test_cmp expect actual
150 '
151
152 +test_expect_success 'git repo info -h shows only repo info usage' '
153 + test_must_fail git repo info -h >actual &&
154 + test_grep "git repo info" actual &&
155 + test_grep ! "git repo structure" actual
156 +'
157 +
158 test_done
t/t1901-repo-structure.sh
+6
@@ -224,4 +224,10 @@ test_expect_success 'progress meter option' '
224 )
225 '
226
227 +test_expect_success 'git repo structure -h shows only repo structure usage' '
228 + test_must_fail git repo structure -h >actual &&
229 + test_grep "git repo structure" actual &&
230 + test_grep ! "git repo info" actual
231 +'
232 +
233 test_done