refs: avoid "too many arguments"

Running "git refs migrate master main" would fail and say "too many
arguments".  By reading that message, you cannot tell if you just
should have given a single ref and made it "git refs migrate
master", or the command refuses to take any arguments.

Instead, report that "git ref migrate" takes no arguments, which is
far easier for the user to understand.

    $ git refs migrate master main
    fatal: 'git refs migrate' takes no arguments

The other side of the coin this change is covering is to remove
doubts in new users' minds when we say "git refs migrate", if it is
"git" command running with two "refs migrate" arguments, "git refs"
command running with one "migrate" argument, or "git refs migrate"
command running with no arguments.

In the same spirit, reword the existing "missing --ref-format=<format>"
message and say

    $ git refs migrate
    fatal: 'git refs migrate' needs '--ref-format=<format>'

Note that we are turning two usage() calls to die() calls.  The
former should signal that the message given is a command line that
shows the usage help of the command.  If we are giving a fatal error
message, we should not hesitate to use die().

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano 2024-08-05 17:35:36 -07:00
parent 39bf06adf9
commit fb787025ae
2 changed files with 4 additions and 10 deletions

View File

@ -30,9 +30,9 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, options, migrate_usage, 0);
if (argc)
usage(_("too many arguments"));
die(_("'git refs migrate' takes no arguments"));
if (!format_str)
usage(_("missing --ref-format=<format>"));
die(_("'git refs migrate' needs '--ref-format=<format>'"));
format = ref_storage_format_by_name(format_str);
if (format == REF_STORAGE_FORMAT_UNKNOWN) {

View File

@ -31,20 +31,14 @@ test_expect_success "superfluous arguments" '
test_when_finished "rm -rf repo" &&
git init repo &&
test_must_fail git -C repo refs migrate foo 2>err &&
cat >expect <<-EOF &&
usage: too many arguments
EOF
test_cmp expect err
test_grep "takes no arguments" err
'
test_expect_success "missing ref storage format" '
test_when_finished "rm -rf repo" &&
git init repo &&
test_must_fail git -C repo refs migrate 2>err &&
cat >expect <<-EOF &&
usage: missing --ref-format=<format>
EOF
test_cmp expect err
test_grep "needs ${SQ}--ref-format=<format>${SQ}" err
'
test_expect_success "unknown ref storage format" '