Skip to content

Commit 367c5f3

Browse files
avargitster
authored andcommitted
commit-graph: show "unexpected subcommand" error
Bring the "commit-graph" command in line with the error output and general pattern in cmd_multi_pack_index(). Let's test for that output, and also cover the same potential bug as was fixed in the multi-pack-index command in 88617d1 (multi-pack-index: fix potential segfault without sub-command, 2021-07-19). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6d209a0 commit 367c5f3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

builtin/commit-graph.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)
345345
else if (argc && !strcmp(argv[0], "write"))
346346
return graph_write(argc, argv);
347347

348+
error(_("unrecognized subcommand: %s"), argv[0]);
348349
usage:
349350
usage_with_options(builtin_commit_graph_usage,
350351
builtin_commit_graph_options);

t/t5318-commit-graph.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@ test_description='commit graph'
66
GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
77

88
test_expect_success 'usage' '
9-
test_expect_code 129 git commit-graph write blah &&
9+
test_expect_code 129 git commit-graph write blah 2>err &&
1010
test_expect_code 129 git commit-graph write verify
1111
'
1212

13+
test_expect_success 'usage shown without sub-command' '
14+
test_expect_code 129 git commit-graph 2>err &&
15+
! grep error: err
16+
'
17+
18+
test_expect_success 'usage shown with an error on unknown sub-command' '
19+
cat >expect <<-\EOF &&
20+
error: unrecognized subcommand: unknown
21+
EOF
22+
test_expect_code 129 git commit-graph unknown 2>stderr &&
23+
grep error stderr >actual &&
24+
test_cmp expect actual
25+
'
26+
1327
test_expect_success 'setup full repo' '
1428
mkdir full &&
1529
cd "$TRASH_DIRECTORY/full" &&

0 commit comments

Comments
 (0)