Skip to content

Commit 6d209a0

Browse files
avargitster
authored andcommitted
commit-graph: show usage on "commit-graph [write|verify] garbage"
Change the parse_options() invocation in the commit-graph code to error on unknown leftover argv elements, in addition to the existing and implicit erroring via parse_options() on unknown options. We'd already error in cmd_commit_graph() on e.g.: git commit-graph unknown verify git commit-graph --unknown verify But here we're calling parse_options() twice more for the "write" and "verify" subcommands. We did not do the same checking for leftover argv elements there. As a result we'd silently accept garbage in these subcommands, let's not do that. 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 070e7c5 commit 6d209a0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

builtin/commit-graph.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ static int graph_verify(int argc, const char **argv)
105105
argc = parse_options(argc, argv, NULL,
106106
options,
107107
builtin_commit_graph_verify_usage, 0);
108+
if (argc)
109+
usage_with_options(builtin_commit_graph_verify_usage, options);
108110

109111
if (!opts.obj_dir)
110112
opts.obj_dir = get_object_directory();
@@ -262,6 +264,8 @@ static int graph_write(int argc, const char **argv)
262264
argc = parse_options(argc, argv, NULL,
263265
options,
264266
builtin_commit_graph_write_usage, 0);
267+
if (argc)
268+
usage_with_options(builtin_commit_graph_write_usage, options);
265269

266270
if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1)
267271
die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs"));

t/t5318-commit-graph.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ test_description='commit graph'
55

66
GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
77

8+
test_expect_success 'usage' '
9+
test_expect_code 129 git commit-graph write blah &&
10+
test_expect_code 129 git commit-graph write verify
11+
'
12+
813
test_expect_success 'setup full repo' '
914
mkdir full &&
1015
cd "$TRASH_DIRECTORY/full" &&

0 commit comments

Comments
 (0)