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@xxxxxxxxx> --- 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