]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph: show "unexpected subcommand" error
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 23 Aug 2021 12:30:21 +0000 (14:30 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Aug 2021 00:06:18 +0000 (17:06 -0700)
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
88617d11f9d (multi-pack-index: fix potential segfault without
sub-command, 2021-07-19).

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 0457903f18fd3ce11e2f4ef471c7ea126fbe25c1..21fc6e934b0e5483aa198cfa2569816db98923dc 100644 (file)
@@ -345,6 +345,7 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)
        else if (argc && !strcmp(argv[0], "write"))
                return graph_write(argc, argv);
 
+       error(_("unrecognized subcommand: %s"), argv[0]);
 usage:
        usage_with_options(builtin_commit_graph_usage,
                           builtin_commit_graph_options);
index 09a2ccd29200159ce199c1e39ac2e7e606f73eff..295c5bd94d23fdc8e9783caa74602216f649a3f6 100755 (executable)
@@ -6,10 +6,24 @@ 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 blah 2>err &&
        test_expect_code 129 git commit-graph write verify
 '
 
+test_expect_success 'usage shown without sub-command' '
+       test_expect_code 129 git commit-graph 2>err &&
+       ! grep error: err
+'
+
+test_expect_success 'usage shown with an error on unknown sub-command' '
+       cat >expect <<-\EOF &&
+       error: unrecognized subcommand: unknown
+       EOF
+       test_expect_code 129 git commit-graph unknown 2>stderr &&
+       grep error stderr >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'setup full repo' '
        mkdir full &&
        cd "$TRASH_DIRECTORY/full" &&