Skip to content

Commit 2446e8f

Browse files
committed
notes: avoid "too many arguments"
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 "unexpected 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 <[email protected]>
1 parent becacd2 commit 2446e8f

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

builtin/notes.c

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

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

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

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

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

592592
if (from_stdin || rewrite_cmd) {
593593
if (argc) {
594-
error(_("too many arguments"));
594+
error(_("unexpected argument: '%s'"), argv[0]);
595595
usage_with_options(git_notes_copy_usage, options);
596596
} else {
597597
return notes_copy_from_stdin(force, rewrite_cmd);
@@ -603,7 +603,7 @@ static int copy(int argc, const char **argv, const char *prefix)
603603
usage_with_options(git_notes_copy_usage, options);
604604
}
605605
if (2 < argc) {
606-
error(_("too many arguments"));
606+
error(_("unexpected argument: '%s'"), argv[2]);
607607
usage_with_options(git_notes_copy_usage, options);
608608
}
609609

@@ -686,7 +686,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
686686
PARSE_OPT_KEEP_ARGV0);
687687

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

@@ -762,7 +762,7 @@ static int show(int argc, const char **argv, const char *prefix)
762762
0);
763763

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

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

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

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

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

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)