From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH v1 3/4] notes: avoid "too many arguments"
Date: Mon, 5 Aug 2024 17:35:38 -0700 [thread overview]
Message-ID: <20240806003539.3292562-4-gitster@pobox.com> (raw)
In-Reply-To: <20240806003539.3292562-1-gitster@pobox.com>
Imagine seeing your command failing with "too many arguments" when
you run "git cmd foo bar baz". Can you tell it will work if you
said "git cmd foo bar"? Or is that trimming your command line too
much? Too little?
Instead, if the command reports "unknown argument: 'bar'", you'd know
that "bar" and everything after it is unwanted.
Let's make it so for "git notes".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/notes.c | 18 +++++++++---------
t/t3301-notes.sh | 2 +-
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index d9c356e354..235baeb118 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -447,7 +447,7 @@ static int list(int argc, const char **argv, const char *prefix)
git_notes_list_usage, 0);
if (1 < argc) {
- error(_("too many arguments"));
+ error(_("unknown argument: '%s'"), argv[1]);
usage_with_options(git_notes_list_usage, options);
}
@@ -509,7 +509,7 @@ static int add(int argc, const char **argv, const char *prefix)
PARSE_OPT_KEEP_ARGV0);
if (2 < argc) {
- error(_("too many arguments"));
+ error(_("unknown argument: '%s'"), argv[2]);
usage_with_options(git_notes_add_usage, options);
}
@@ -591,7 +591,7 @@ static int copy(int argc, const char **argv, const char *prefix)
if (from_stdin || rewrite_cmd) {
if (argc) {
- error(_("too many arguments"));
+ error(_("unknown argument: '%s'"), argv[0]);
usage_with_options(git_notes_copy_usage, options);
} else {
return notes_copy_from_stdin(force, rewrite_cmd);
@@ -603,7 +603,7 @@ static int copy(int argc, const char **argv, const char *prefix)
usage_with_options(git_notes_copy_usage, options);
}
if (2 < argc) {
- error(_("too many arguments"));
+ error(_("unknown argument: '%s'"), argv[2]);
usage_with_options(git_notes_copy_usage, options);
}
@@ -686,7 +686,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
PARSE_OPT_KEEP_ARGV0);
if (2 < argc) {
- error(_("too many arguments"));
+ error(_("unknown argument: '%s'"), argv[2]);
usage_with_options(usage, options);
}
@@ -762,7 +762,7 @@ static int show(int argc, const char **argv, const char *prefix)
0);
if (1 < argc) {
- error(_("too many arguments"));
+ error(_("unknown argument: '%s'"), argv[1]);
usage_with_options(git_notes_show_usage, options);
}
@@ -915,7 +915,7 @@ static int merge(int argc, const char **argv, const char *prefix)
error(_("must specify a notes ref to merge"));
usage_with_options(git_notes_merge_usage, options);
} else if (!do_merge && argc) {
- error(_("too many arguments"));
+ error(_("unknown argument: '%s'"), argv[0]);
usage_with_options(git_notes_merge_usage, options);
}
@@ -1069,7 +1069,7 @@ static int prune(int argc, const char **argv, const char *prefix)
0);
if (argc) {
- error(_("too many arguments"));
+ error(_("unknown argument: '%s'"), argv[0]);
usage_with_options(git_notes_prune_usage, options);
}
@@ -1091,7 +1091,7 @@ static int get_ref(int argc, const char **argv, const char *prefix)
git_notes_get_ref_usage, 0);
if (argc) {
- error(_("too many arguments"));
+ error(_("unknown argument: '%s'"), argv[0]);
usage_with_options(git_notes_get_ref_usage, options);
}
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 536bd11ff4..9db6a2f5c4 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -1472,7 +1472,7 @@ test_expect_success 'git notes copy diagnoses too many or too few arguments' '
test_must_fail git notes copy 2>error &&
test_grep "too few arguments" error &&
test_must_fail git notes copy one two three 2>error &&
- test_grep "too many arguments" error
+ test_grep "unknown argument: ${SQ}three${SQ}" error
'
test_expect_success 'git notes get-ref expands refs/heads/main to refs/notes/refs/heads/main' '
--
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 ` [PATCH v1 1/4] refs: avoid "too many arguments" Junio C Hamano
2024-08-06 6:13 ` 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 ` Junio C Hamano [this message]
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-4-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).