]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph: show usage on "commit-graph [write|verify] garbage"
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 23 Aug 2021 12:30:20 +0000 (14:30 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Aug 2021 00:06:18 +0000 (17:06 -0700)
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 <avarab@gmail.com>
Reviewed-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit-graph.c
t/t5318-commit-graph.sh

index bf34aa43f228cac92f30c593d4161c666772254d..0457903f18fd3ce11e2f4ef471c7ea126fbe25c1 100644 (file)
@@ -105,6 +105,8 @@ static int graph_verify(int argc, const char **argv)
        argc = parse_options(argc, argv, NULL,
                             options,
                             builtin_commit_graph_verify_usage, 0);
+       if (argc)
+               usage_with_options(builtin_commit_graph_verify_usage, options);
 
        if (!opts.obj_dir)
                opts.obj_dir = get_object_directory();
@@ -262,6 +264,8 @@ static int graph_write(int argc, const char **argv)
        argc = parse_options(argc, argv, NULL,
                             options,
                             builtin_commit_graph_write_usage, 0);
+       if (argc)
+               usage_with_options(builtin_commit_graph_write_usage, options);
 
        if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1)
                die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs"));
index af88f805aa275b6cd7a0ef4c50819a8538d7b0d1..09a2ccd29200159ce199c1e39ac2e7e606f73eff 100755 (executable)
@@ -5,6 +5,11 @@ test_description='commit graph'
 
 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
 
+test_expect_success 'usage' '
+       test_expect_code 129 git commit-graph write blah &&
+       test_expect_code 129 git commit-graph write verify
+'
+
 test_expect_success 'setup full repo' '
        mkdir full &&
        cd "$TRASH_DIRECTORY/full" &&