From patchwork Tue Aug 6 00:35:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13754279 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07A4410FF for ; Tue, 6 Aug 2024 00:35:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722904546; cv=none; b=u25BXQIFhFvkaNdrvltg45RK4BL4nAvSwss6FtIyaGLkwSgN7O9JfROAcosxcUfawduOC/ChUE4cSax329nfwroU4WPpeHeDgf8MQtSZVxYIYvO+pe2hfmikgzwh/2gABw9PA6CcMHZN4IvjRXJJrh2USxF2nL+MqdLMg6zDriE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722904546; c=relaxed/simple; bh=aWHwMZL82j8QemStSVaMIJirsEoEAcKbv/haASSBXBI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ibo1FTPaP+6Oa2aDDsSJ0VxOvzl+XbYzDq4LEeg5HoHwLI7C9o+1oLGGX8/wcuUesFyMMt13GOY4GOY46xzYN6QN3Lctn9fEo3ZeOkcA23zDB0MOiOvteIILoChVASTiyejbPr+LOMhYHIK8jS9gEv8zDq6HPDWzlUhSXYrpAnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=YSOrUXt/; arc=none smtp.client-ip=64.147.108.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="YSOrUXt/" Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id DF19828347; Mon, 5 Aug 2024 20:35:43 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=aWHwMZL82j8QemStSVaMIJirs EoEAcKbv/haASSBXBI=; b=YSOrUXt/ZIHlRR5Rh2NkjwLNHVOSHak8xjW+A2szc QaTKmwfPA8kXYPAa99H32lnP3HV6EWl63k8ngmPmuCS7SAcLEWVt46GTi/45knY5 FjpZUxuQdKoVBaPhTeD4L0mgIKL7sCmMCL+ijJE5Dq7UKciM1oo7fZibOJClO/fO 30= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id D83AA28346; Mon, 5 Aug 2024 20:35:43 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.108.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 453B928345; Mon, 5 Aug 2024 20:35:43 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v1 1/4] refs: avoid "too many arguments" Date: Mon, 5 Aug 2024 17:35:36 -0700 Message-ID: <20240806003539.3292562-2-gitster@pobox.com> X-Mailer: git-send-email 2.46.0-235-g968ce1ce0e In-Reply-To: <20240806003539.3292562-1-gitster@pobox.com> References: <20240806003539.3292562-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: D05B4CD0-538B-11EF-B5B4-9B0F950A682E-77302942!pb-smtp2.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 --- 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=")); 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 ' From patchwork Tue Aug 6 00:35:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13754280 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57A55A936 for ; Tue, 6 Aug 2024 00:35:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722904551; cv=none; b=PD/l4Zldz8N8TFYC9sR/kK0FqAx7XgIrbJHjhAyVLDESMwChNNLx8le+V+w1c2hFsNZZMAj9AookxPQRc0eqARAi8Ae9rmF/m1/L/RauJAHEMVXKuPURp4YZH1yRpUz2Mh7hUlpqjE5OVCaXwxcMTIQD6+9+5U8vLTGSsM0MbZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722904551; c=relaxed/simple; bh=Z0/z3nEOnZDPCfmCrylMguarsm8kmHMuJaFbKIkV4W8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sWMJx7ltge6OY4PblmdRWqbVJHDAhi0UR7sBPaJ4qgMbBRWjPSf4nNTLWCAswfnEyww3J9dKRvfRisbBpLSmQYvfdVtJQpp8ZF4dlT29QhRcKP8k49STLgKFTYwSEMaNccoiVhcuVkD2voXupwhqoLCUYRAUY1mUUsKr7LW3mAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=FPKepvCd; arc=none smtp.client-ip=173.228.157.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="FPKepvCd" Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id BF102315AB; Mon, 5 Aug 2024 20:35:49 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=Z0/z3nEOnZDPCfmCrylMguars m8kmHMuJaFbKIkV4W8=; b=FPKepvCdOUqbJJztmtzK8nFq7RoaNta2zA/IA11k5 nxCyCuYhki0K7O+oTW4SwcCoHDKk2Xvi8XxTe3SM3BGfJxMwwgor7+8Zo7dyqlj4 +EJ8cjVIhQ4kK69PvuaPi2OYMXOxKH/Y/PQWGdVRASApRu1huZtFqC9mzTnm8Y+T ok= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id B7AFE315AA; Mon, 5 Aug 2024 20:35:49 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.108.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 6CD61315A8; Mon, 5 Aug 2024 20:35:45 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v1 2/4] cat-file: avoid "too many arguments" Date: Mon, 5 Aug 2024 17:35:37 -0700 Message-ID: <20240806003539.3292562-3-gitster@pobox.com> X-Mailer: git-send-email 2.46.0-235-g968ce1ce0e In-Reply-To: <20240806003539.3292562-1-gitster@pobox.com> References: <20240806003539.3292562-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: D1A5653A-538B-11EF-A5A1-BF444491E1BC-77302942!pb-smtp20.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 --- 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 From patchwork Tue Aug 6 00:35:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13754281 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A32063D5 for ; Tue, 6 Aug 2024 00:35:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.228.157.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722904556; cv=none; b=JEsJ7EJZ354ytOSoL4j5RmPDO8n5qjRXJMXDtg7IsL8CEQxuKjCO1oeBFXkNfooHZBQiBMbffFtQ7ZvtTB7+a1iL4G1AwDJpxIhbjosbiKoopSxVEYZ+oxjmrdvpwNfWjP+aNnkyz8mYLl21aARqqqLHvz89CtAqOANzkjsgBOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722904556; c=relaxed/simple; bh=eloSFMoHn/U/W/RNcCyh0KI+rb0bJDm61+NrvbD5BvE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l7NuCwGxZDH2vQLR+65LQ0NYLw2VI57WS8VdLg1J5r5cNnS5UHSBgPTIQ4UmbTxGvl7d4CDW9LOpaASEwjEX7pIuNGvbEKwrtDzH102im0CWxh+MRURS36hZcXAxtN1/gomBLAtwPZpfAUHEhusOWPqOkZ3KCQr36oVvWDJIAPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=RUD7y+zY; arc=none smtp.client-ip=173.228.157.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="RUD7y+zY" Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 23FFB1BFC1; Mon, 5 Aug 2024 20:35:54 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=eloSFMoHn/U/W/RNcCyh0KI+r b0bJDm61+NrvbD5BvE=; b=RUD7y+zYLqKBde3oCM6Ewlq+xk7Gwr2f4qx47DqV0 mhayfNHrvOFWqVFZyj8cuziMnRl+t2Kmk/hdJB1nSawfAN9QCawmnN/bCSR4PpO4 f4cTxuq+he/uQyQUfn3uBO8aYfxqX5xCxzY+7G1LBB9ofQuun0f/7nDBUKVXM32a 08= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 1D0021BFC0; Mon, 5 Aug 2024 20:35:54 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.108.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 1C0BF1BFBD; Mon, 5 Aug 2024 20:35:50 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v1 3/4] notes: avoid "too many arguments" Date: Mon, 5 Aug 2024 17:35:38 -0700 Message-ID: <20240806003539.3292562-4-gitster@pobox.com> X-Mailer: git-send-email 2.46.0-235-g968ce1ce0e In-Reply-To: <20240806003539.3292562-1-gitster@pobox.com> References: <20240806003539.3292562-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: D46DCCB2-538B-11EF-8E17-E92ED1CD468F-77302942!pb-smtp21.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 --- 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' ' From patchwork Tue Aug 6 00:35:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13754282 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41FDE63D5 for ; Tue, 6 Aug 2024 00:36:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.108.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722904563; cv=none; b=bjTbtigcGPveHB/cUOHmp6Y15X3z8eMXSgHF2DeBCxf9wpLGtoPdaDc3y7kWyUXzdNitigPukEBvPYg9xOey6CkbxSyQQI+eSdBZU2kqZ9py6qklh/p+4B/wsp4p8ANwuvn1p4tfxJ70JEoRJ/EbO0etZXi9T6woC5SwKtUhjwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722904563; c=relaxed/simple; bh=M9KcmDY+UAXiWqoa1XGndAnqA65uw/fofXprqgMuT5M=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YSdy2cpyQfpraYPWAUA7Feo65cAzj2DlV+8SfuBXB6mHtk7bNsbPx9DmTPqwObRt5XIxXCdUtwqmTQVxiljrpR8uhhZkY1OguF/TA3yPlZQC6idSHVeAGSqEwFMwacWNMavQOlYIhu/y1rKY/sRgSntBukwUpajxZsGuktQS5r8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b=LAFcVpn4; arc=none smtp.client-ip=64.147.108.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="LAFcVpn4" Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 972EF39FFD; Mon, 5 Aug 2024 20:35:54 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=M9KcmDY+UAXiWqoa1XGndAnqA 65uw/fofXprqgMuT5M=; b=LAFcVpn4raChPcihemlIx9Itpmlm4ZNiJ4Gi6viWd SnWAoqzgo8JBvQHxrKPK32H8SWw0/JtvuScb8M1tWfhKfT7tR5x7/Hhgho5tQ4De n3wyybTl/eVk4oseu948heKNo8nhLeGq4gZDC8opzEUOO+5VqMLUOMIL8RSC+pa0 /Q= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 8EAE239FFC; Mon, 5 Aug 2024 20:35:54 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.108.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id F10CA39FFB; Mon, 5 Aug 2024 20:35:53 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v1 4/4] miscellaneous: avoid "too many arguments" Date: Mon, 5 Aug 2024 17:35:39 -0700 Message-ID: <20240806003539.3292562-5-gitster@pobox.com> X-Mailer: git-send-email 2.46.0-235-g968ce1ce0e In-Reply-To: <20240806003539.3292562-1-gitster@pobox.com> References: <20240806003539.3292562-1-gitster@pobox.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Pobox-Relay-ID: D6BC83F0-538B-11EF-B40C-2BAEEB2EC81B-77302942!pb-smtp1.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 --- 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);