Skip to content

Commit abd728c

Browse files
MahiKassagitster
authored andcommitted
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>
1 parent 4be77c7 commit abd728c

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

builtin/repo.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ static const char *const repo_usage[] = {
3333
NULL,
3434
};
3535

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+
3646
typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
3747

3848
enum output_format {
@@ -220,7 +230,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
220230
OPT_END()
221231
};
222232

223-
argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
233+
argc = parse_options(argc, argv, prefix, options, repo_info_usage, 0);
224234

225235
if (show_keys && (all_keys || argc))
226236
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,
885895
OPT_END()
886896
};
887897

888-
argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
898+
argc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);
889899
if (argc)
890900
usage(_("too many arguments"));
891901

t/t1900-repo-info.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,10 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
149149
test_cmp expect actual
150150
'
151151

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+
152158
test_done

t/t1901-repo-structure.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,10 @@ test_expect_success 'progress meter option' '
224224
)
225225
'
226226

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+
227233
test_done

0 commit comments

Comments
 (0)