git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v1 4/4] miscellaneous: avoid "too many arguments"

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 6, 2024, 00:35 UTC
Message-ID
<20240806003539.3292562-5-gitster@pobox.com>
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 a few remaining commands.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/prune-packed.c | 6 +++---
 builtin/receive-pack.c | 3 ++-
 builtin/tag.c          | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c
index ca3578e158..46989e12f9 100644
--- a/builtin/prune-packed.c
+++ b/builtin/prune-packed.c
@@ -23,9 +23,9 @@ int cmd_prune_packed(int argc, const char **argv, const char *prefix)
 			     prune_packed_usage, 0);
 
 	if (argc > 0)
-		usage_msg_opt(_("too many arguments"),
-			      prune_packed_usage,
-			      prune_packed_options);
+		usage_msg_optf(_("unknown argument: '%s'"),
+			       prune_packed_usage, prune_packed_options,
+			       argv[0]);
 
 	prune_packed_objects(opts);
 	return 0;
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 339524ae2a..e49f4ea4dd 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -2503,7 +2503,8 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, receive_pack_usage, 0);
 
 	if (argc > 1)
-		usage_msg_opt(_("too many arguments"), receive_pack_usage, options);
+		usage_msg_optf(_("unknown argument: '%s'"),
+			       receive_pack_usage, options, argv[0]);
 	if (argc == 0)
 		usage_msg_opt(_("you must specify a directory"), receive_pack_usage, options);
 
diff --git a/builtin/tag.c b/builtin/tag.c
index a1fb218512..274bd0e6ce 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -641,7 +641,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 
 	object_ref = argc == 2 ? argv[1] : "HEAD";
 	if (argc > 2)
-		die(_("too many arguments"));
+		die(_("unknown argument: '%s'"), argv[2]);
 
 	if (repo_get_oid(the_repository, object_ref, &object))
 		die(_("Failed to resolve '%s' as a valid ref."), object_ref);
-- 
2.46.0-235-g968ce1ce0e
Previous: Junio C HamanoNext: Eric Sunshine
Message 14 of 16 in “make "too many arguments" a bit more useful”
  1. 0/4 make "too many arguments" a bit more usefulJunio C Hamano, Aug 6, 2024
  2. 1/4 refs: avoid "too many arguments"Junio C Hamano, Aug 6, 2024
  3. Patrick SteinhardtAug 6, 2024
  4. Junio C HamanoAug 6, 2024
  5. [RFC] usage_msg_opt() and _optf() must dieJunio C Hamano, Aug 6, 2024
  6. Eric SunshineAug 6, 2024
  7. Junio C HamanoAug 6, 2024
  8. Patrick SteinhardtAug 7, 2024
  9. Justin ToblerAug 6, 2024
  10. Martin ÅgrenAug 6, 2024
  11. refs: avoid "too many arguments"Junio C Hamano, Aug 6, 2024
  12. 2/4 cat-file: avoid "too many arguments"Junio C Hamano, Aug 6, 2024
  13. 3/4 notes: avoid "too many arguments"Junio C Hamano, Aug 6, 2024
  14. 4/4 miscellaneous: avoid "too many arguments"Junio C Hamano, Aug 6, 2024
  15. Eric SunshineAug 6, 2024
  16. Junio C HamanoAug 6, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.