Skip to content

Commit 3284b93

Browse files
rscharfegitster
authored andcommitted
parse-options: disallow negating OPTION_SET_INT 0
An option of type OPTION_SET_INT can be defined to set its variable to zero. It's negated variant will do the same, though, which is confusing. Several such options were fixed by disabling negation, changing the value to set or using a different option type: 991c552 (ls-tree: fix --no-full-name, 2023-07-18) e12cb98 (branch: reject "--no-all" and "--no-remotes" early, 2023-07-18) 68cbb20 (show-branch: reject --[no-](topo|date)-order, 2023-07-19) 3821eb6 (reset: reject --no-(mixed|soft|hard|merge|keep) option, 2023-07-19) 36f76d2 (pack-objects: fix --no-quiet, 2023-07-21) 3a5f308 (pack-objects: fix --no-keep-true-parents, 2023-07-21) c95ae3f (describe: fix --no-exact-match, 2023-07-21) d089a06 (bundle: use OPT_PASSTHRU_ARGV, 2023-07-29) Check for such options that allow negation in parse_options_check() and report them to find future cases quicker. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac83bc5 commit 3284b93

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

parse-options.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ static void parse_options_check(const struct option *opts)
480480
opts->long_name))
481481
optbug(opts, "uses feature "
482482
"not supported for dashless options");
483+
if (opts->type == OPTION_SET_INT && !opts->defval &&
484+
opts->long_name && !(opts->flags & PARSE_OPT_NONEG))
485+
optbug(opts, "OPTION_SET_INT 0 should not be negatable");
483486
switch (opts->type) {
484487
case OPTION_COUNTUP:
485488
case OPTION_BIT:

0 commit comments

Comments
 (0)