Skip to content

Commit 681c0a2

Browse files
Emily Shaffergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 831401b commit 681c0a2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

builtin/bugreport.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ int cmd_bugreport(int argc, const char **argv, const char *prefix)
126126
argc = parse_options(argc, argv, prefix, bugreport_options,
127127
bugreport_usage, 0);
128128

129+
if (argc) {
130+
error(_("unknown argument `%s'"), argv[0]);
131+
usage(bugreport_usage[0]);
132+
}
133+
129134
/* Prepare the path to put the result */
130135
prefixed_filename = prefix_filename(prefix,
131136
option_output ? option_output : "");

t/t0091-bugreport.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ test_expect_success 'incorrect arguments abort with usage' '
6969
test_path_is_missing git-bugreport-*
7070
'
7171

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+
7279
test_expect_success 'runs outside of a git dir' '
7380
test_when_finished rm non-repo/git-bugreport-* &&
7481
nongit git bugreport

0 commit comments

Comments
 (0)