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

[PATCH v1 2/4] cat-file: avoid "too many arguments"

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 6, 2024, 00:35 UTC
Message-ID
<20240806003539.3292562-3-gitster@pobox.com>
In-Reply-To
<20240806003539.3292562-1-gitster@pobox.com>

Running "git cat-file -e a b c d e f g" would fail and say "too many arguments". By reading that message, you cannot tell if the command could have worked if you limited the list of objects to 5 items instead of 7, or the command is prepared to take only a single item.

Let's report that "b" is an unexpected argument instead.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/cat-file.c  | 3 ++-
 t/t1006-cat-file.sh | 8 +++++---
 2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 18fe58d6b8..ba85825c55 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -1074,7 +1074,8 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
 		else if (argc == 1)
 			obj_name = argv[0];
 		else
-			usage_msg_opt(_("too many arguments"), usage, options);
+			usage_msg_optf(_("unknown argument: '%s'"),
+				       usage, options, argv[1]);
 	} else if (!argc) {
 		usage_with_options(usage, options);
 	} else if (argc != 2) {
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index ff9bf213aa..8ad440bbcc 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -66,16 +66,18 @@ do
 	done
 done
 
-test_too_many_arguments () {
+test_unknown_arg () {
+	unk=$1
+	shift
 	test_expect_code 129 "$@" 2>err &&
-	grep -E "^fatal: too many arguments$" err
+	grep -E "^fatal: unknown argument: '$unk'" err
 }
 
 for opt in $short_modes $cw_modes
 do
 	args="one two three"
 	test_expect_success "usage: too many arguments: $opt $args" '
-		test_too_many_arguments git cat-file $opt $args
+		test_unknown_arg two git cat-file $opt $args
 	'
 
 	for opt2 in --buffer --follow-symlinks
-- 
2.46.0-235-g968ce1ce0e
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 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.