Skip to content

Commit dc774bc

Browse files
committed
Merge branch 'jc/too-many-arguments' into jch
Error message clarification. * jc/too-many-arguments: miscellaneous: avoid "too many arguments" notes: avoid "too many arguments" cat-file: avoid "too many arguments" refs: avoid "too many arguments"
2 parents f2c23f8 + 6c8ee88 commit dc774bc

File tree

9 files changed

+27
-29
lines changed

9 files changed

+27
-29
lines changed

builtin/cat-file.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,13 @@ int cmd_cat_file(int argc,
10771077
else if (!argc && opt_epts)
10781078
usage_msg_optf(_("<object> required with '-%c'"),
10791079
usage, options, opt);
1080+
else if (!argc)
1081+
BUG("argc==0 with opt=%c", opt);
10801082
else if (argc == 1)
10811083
obj_name = argv[0];
10821084
else
1083-
usage_msg_opt(_("too many arguments"), usage, options);
1085+
usage_msg_optf(_("unexpected argument: '%s'"),
1086+
usage, options, argv[1]);
10841087
} else if (!argc) {
10851088
usage_with_options(usage, options);
10861089
} else if (argc != 2) {

builtin/notes.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static int list(int argc, const char **argv, const char *prefix)
446446
git_notes_list_usage, 0);
447447

448448
if (1 < argc) {
449-
error(_("too many arguments"));
449+
error(_("unexpected argument: '%s'"), argv[1]);
450450
usage_with_options(git_notes_list_usage, options);
451451
}
452452

@@ -508,7 +508,7 @@ static int add(int argc, const char **argv, const char *prefix)
508508
PARSE_OPT_KEEP_ARGV0);
509509

510510
if (2 < argc) {
511-
error(_("too many arguments"));
511+
error(_("unexpected argument: '%s'"), argv[2]);
512512
usage_with_options(git_notes_add_usage, options);
513513
}
514514

@@ -589,7 +589,7 @@ static int copy(int argc, const char **argv, const char *prefix)
589589

590590
if (from_stdin || rewrite_cmd) {
591591
if (argc) {
592-
error(_("too many arguments"));
592+
error(_("unexpected argument: '%s'"), argv[0]);
593593
usage_with_options(git_notes_copy_usage, options);
594594
} else {
595595
return notes_copy_from_stdin(force, rewrite_cmd);
@@ -601,7 +601,7 @@ static int copy(int argc, const char **argv, const char *prefix)
601601
usage_with_options(git_notes_copy_usage, options);
602602
}
603603
if (2 < argc) {
604-
error(_("too many arguments"));
604+
error(_("unexpected argument: '%s'"), argv[2]);
605605
usage_with_options(git_notes_copy_usage, options);
606606
}
607607

@@ -684,7 +684,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
684684
PARSE_OPT_KEEP_ARGV0);
685685

686686
if (2 < argc) {
687-
error(_("too many arguments"));
687+
error(_("unexpected argument: '%s'"), argv[2]);
688688
usage_with_options(usage, options);
689689
}
690690

@@ -760,7 +760,7 @@ static int show(int argc, const char **argv, const char *prefix)
760760
0);
761761

762762
if (1 < argc) {
763-
error(_("too many arguments"));
763+
error(_("unexpected argument: '%s'"), argv[1]);
764764
usage_with_options(git_notes_show_usage, options);
765765
}
766766

@@ -913,7 +913,7 @@ static int merge(int argc, const char **argv, const char *prefix)
913913
error(_("must specify a notes ref to merge"));
914914
usage_with_options(git_notes_merge_usage, options);
915915
} else if (!do_merge && argc) {
916-
error(_("too many arguments"));
916+
error(_("unexpected argument: '%s'"), argv[0]);
917917
usage_with_options(git_notes_merge_usage, options);
918918
}
919919

@@ -1069,7 +1069,7 @@ static int prune(int argc, const char **argv, const char *prefix)
10691069
0);
10701070

10711071
if (argc) {
1072-
error(_("too many arguments"));
1072+
error(_("unexpected argument: '%s'"), argv[0]);
10731073
usage_with_options(git_notes_prune_usage, options);
10741074
}
10751075

@@ -1092,7 +1092,7 @@ static int get_ref(int argc, const char **argv, const char *prefix)
10921092
git_notes_get_ref_usage, 0);
10931093

10941094
if (argc) {
1095-
error(_("too many arguments"));
1095+
error(_("unexpected argument: '%s'"), argv[0]);
10961096
usage_with_options(git_notes_get_ref_usage, options);
10971097
}
10981098

builtin/prune-packed.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ int cmd_prune_packed(int argc,
2626
prune_packed_usage, 0);
2727

2828
if (argc > 0)
29-
usage_msg_opt(_("too many arguments"),
30-
prune_packed_usage,
31-
prune_packed_options);
29+
die(_("'git prune-packed' takes no arguments"));
3230

3331
prune_packed_objects(opts);
3432
return 0;

builtin/receive-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2521,7 +2521,8 @@ int cmd_receive_pack(int argc,
25212521
argc = parse_options(argc, argv, prefix, options, receive_pack_usage, 0);
25222522

25232523
if (argc > 1)
2524-
usage_msg_opt(_("too many arguments"), receive_pack_usage, options);
2524+
usage_msg_optf(_("unexpected argument: '%s'"),
2525+
receive_pack_usage, options, argv[1]);
25252526
if (argc == 0)
25262527
usage_msg_opt(_("you must specify a directory"), receive_pack_usage, options);
25272528

builtin/refs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix)
3535

3636
argc = parse_options(argc, argv, prefix, options, migrate_usage, 0);
3737
if (argc)
38-
usage(_("too many arguments"));
38+
die(_("'git refs migrate' takes no arguments"));
3939
if (!format_str)
40-
usage(_("missing --ref-format=<format>"));
40+
die(_("'git refs migrate' needs '--ref-format=<format>'"));
4141

4242
format = ref_storage_format_by_name(format_str);
4343
if (format == REF_STORAGE_FORMAT_UNKNOWN) {

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ int cmd_tag(int argc,
645645

646646
object_ref = argc == 2 ? argv[1] : "HEAD";
647647
if (argc > 2)
648-
die(_("too many arguments"));
648+
die(_("unexpected argument: '%s'"), argv[2]);
649649

650650
if (repo_get_oid(the_repository, object_ref, &object))
651651
die(_("Failed to resolve '%s' as a valid ref."), object_ref);

t/t1006-cat-file.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,18 @@ do
6767
done
6868
done
6969

70-
test_too_many_arguments () {
70+
test_unexpected_arg () {
71+
unexpected=$1
72+
shift
7173
test_expect_code 129 "$@" 2>err &&
72-
grep -E "^fatal: too many arguments$" err
74+
grep -E "^fatal: unexpected argument: '$unexpected'" err
7375
}
7476

7577
for opt in $short_modes $cw_modes
7678
do
7779
args="one two three"
7880
test_expect_success "usage: too many arguments: $opt $args" '
79-
test_too_many_arguments git cat-file $opt $args
81+
test_unexpected_arg two git cat-file $opt $args
8082
'
8183

8284
for opt2 in --buffer --follow-symlinks

t/t1460-refs-migrate.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,14 @@ test_expect_success "superfluous arguments" '
3131
test_when_finished "rm -rf repo" &&
3232
git init repo &&
3333
test_must_fail git -C repo refs migrate foo 2>err &&
34-
cat >expect <<-EOF &&
35-
usage: too many arguments
36-
EOF
37-
test_cmp expect err
34+
test_grep "takes no arguments" err
3835
'
3936

4037
test_expect_success "missing ref storage format" '
4138
test_when_finished "rm -rf repo" &&
4239
git init repo &&
4340
test_must_fail git -C repo refs migrate 2>err &&
44-
cat >expect <<-EOF &&
45-
usage: missing --ref-format=<format>
46-
EOF
47-
test_cmp expect err
41+
test_grep "needs ${SQ}--ref-format=<format>${SQ}" err
4842
'
4943

5044
test_expect_success "unknown ref storage format" '

t/t3301-notes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ test_expect_success 'git notes copy diagnoses too many or too few arguments' '
14721472
test_must_fail git notes copy 2>error &&
14731473
test_grep "too few arguments" error &&
14741474
test_must_fail git notes copy one two three 2>error &&
1475-
test_grep "too many arguments" error
1475+
test_grep "unexpected argument: ${SQ}three${SQ}" error
14761476
'
14771477

14781478
test_expect_success 'git notes get-ref expands refs/heads/main to refs/notes/refs/heads/main' '

0 commit comments

Comments
 (0)