]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bugreport: reject positional arguments
authorEmily Shaffer <nasamuffin@google.com>
Thu, 26 Oct 2023 18:22:31 +0000 (11:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 28 Oct 2023 23:56:17 +0000 (08:56 +0900)
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>
builtin/bugreport.c
t/t0091-bugreport.sh

index d2ae5c305db82cda78851196411f6437f4abbda9..3106e56a130c58994fced2afd8dbd337134861ad 100644 (file)
@@ -126,6 +126,11 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, bugreport_options,
                             bugreport_usage, 0);
 
+       if (argc) {
+               error(_("unknown argument `%s'"), argv[0]);
+               usage(bugreport_usage[0]);
+       }
+
        /* Prepare the path to put the result */
        prefixed_filename = prefix_filename(prefix,
                                            option_output ? option_output : "");
index e1588f71b7c69c5f17eeda4d744dda1b69642533..ae5b7dc31ffd6719226b2921d1c5f08b6f9758f6 100755 (executable)
@@ -69,6 +69,13 @@ test_expect_success 'incorrect arguments abort with usage' '
        test_path_is_missing git-bugreport-*
 '
 
+test_expect_success 'incorrect positional arguments abort with usage and hint' '
+       test_must_fail git bugreport false 2>output &&
+       grep usage output &&
+       grep false output &&
+       test_path_is_missing git-bugreport-*
+'
+
 test_expect_success 'runs outside of a git dir' '
        test_when_finished rm non-repo/git-bugreport-* &&
        nongit git bugreport