bugreport: reject positional arguments
git-bugreport already rejected unrecognized flag arguments, like `--diaggnose`, but this doesn't help if the user's mistake was to forget the `--` in front of the argument. This can result in a user's intended argument not being parsed with no indication to the user that something went wrong. Since git-bugreport presently doesn't take any positionals at all, let's reject all positionals and give the user a usage hint. Signed-off-by: Emily Shaffer <nasamuffin@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Emily Shaffer committed
Oct 26, 2023 at 11:22 UTC
681c0a247bb6ec38ec9ac9ed745e2ef2c91f447d
2 files changed
+12
builtin/bugreport.c
+5
@@ -126,6 +126,11 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
126
argc = parse_options(argc, argv, prefix, bugreport_options,
127
bugreport_usage, 0);
128
129
+ if (argc) {
130
+ error(_("unknown argument `%s'"), argv[0]);
131
+ usage(bugreport_usage[0]);
132
+ }
133
+
134
/* Prepare the path to put the result */
135
prefixed_filename = prefix_filename(prefix,
136
option_output ? option_output : "");
t/t0091-bugreport.sh
+7
@@ -69,6 +69,13 @@ test_expect_success 'incorrect arguments abort with usage' '
69
test_path_is_missing git-bugreport-*
70
'
71
72
+test_expect_success 'incorrect positional arguments abort with usage and hint' '
73
+ test_must_fail git bugreport false 2>output &&
74
+ grep usage output &&
75
+ grep false output &&
76
+ test_path_is_missing git-bugreport-*
77
+'
78
+
79
test_expect_success 'runs outside of a git dir' '
80
test_when_finished rm non-repo/git-bugreport-* &&
81
nongit git bugreport