From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH v1 1/4] refs: avoid "too many arguments"
Date: Mon, 5 Aug 2024 17:35:36 -0700 [thread overview]
Message-ID: <20240806003539.3292562-2-gitster@pobox.com> (raw)
In-Reply-To: <20240806003539.3292562-1-gitster@pobox.com>
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.
Let's report that 'master' is unknown in such an input, which would
be easier for the user to understand.
In this particular case, "the command takes no arguments" would also
be a good alternative message, but because we plan to reuse the same
pattern for commands that take 1 or more messages, and saying "the
command takes exactly 1 argument" when "git foo --option bar baz"
has to fail (because it does not want to see "baz") can mislead the
reader into thinking that "--option" may count as that single
argument, so let's be a bit more explicit and mention the first
thing we do not want to see on the command line instead.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/refs.c | 4 +++-
t/t1460-refs-migrate.sh | 7 ++++---
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/builtin/refs.c b/builtin/refs.c
index 46dcd150d4..a2aac38ceb 100644
--- a/builtin/refs.c
+++ b/builtin/refs.c
@@ -30,7 +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"));
+ usage_msg_optf(_("unknown argument: '%s'"),
+ migrate_usage, options,
+ argv[0]);
if (!format_str)
usage(_("missing --ref-format=<format>"));
diff --git a/t/t1460-refs-migrate.sh b/t/t1460-refs-migrate.sh
index f7c0783d30..b32e740001 100755
--- a/t/t1460-refs-migrate.sh
+++ b/t/t1460-refs-migrate.sh
@@ -31,9 +31,10 @@ 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
+ {
+ printf "fatal: unknown argument: ${SQ}foo${SQ}\n\n" &&
+ ( git -C repo refs migrate -h || : )
+ } >expect &&
test_cmp expect err
'
--
2.46.0-235-g968ce1ce0e
next prev parent reply other threads:[~2024-08-06 0:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-06 0:35 [PATCH v1 0/4] make "too many arguments" a bit more useful Junio C Hamano
2024-08-06 0:35 ` Junio C Hamano [this message]
2024-08-06 6:13 ` [PATCH v1 1/4] refs: avoid "too many arguments" Patrick Steinhardt
2024-08-06 16:48 ` Junio C Hamano
2024-08-06 17:11 ` [RFC] usage_msg_opt() and _optf() must die Junio C Hamano
2024-08-06 17:38 ` Eric Sunshine
2024-08-06 20:21 ` Junio C Hamano
2024-08-07 5:01 ` Patrick Steinhardt
2024-08-06 19:09 ` Justin Tobler
2024-08-06 19:24 ` Martin Ågren
2024-08-06 17:47 ` [PATCH v2] refs: avoid "too many arguments" Junio C Hamano
2024-08-06 0:35 ` [PATCH v1 2/4] cat-file: " Junio C Hamano
2024-08-06 0:35 ` [PATCH v1 3/4] notes: " Junio C Hamano
2024-08-06 0:35 ` [PATCH v1 4/4] miscellaneous: " Junio C Hamano
2024-08-06 2:31 ` Eric Sunshine
2024-08-06 16:50 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240806003539.3292562-2-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).