summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Keller <jacob.keller@gmail.com>2017-04-19 02:08:20 -0700
committerJunio C Hamano <gitster@pobox.com>2017-04-19 19:12:18 -0700
commit5563131f9ae4d2f087238c03634796d1993927d1 (patch)
tree490f075cecba928fb4457dd2dd64cadfa5bc7c5b
parent49800c940790cc7465d1b03e08d472ffd8684808 (diff)
downloadgit-5563131f9ae4d2f087238c03634796d1993927d1.tar.gz
parse-options: disallow double-negations of options starting with no-
Many options can be negated by prefixing the option with "no-", for example "--3way" can be prefixed with "--no-3way" to disable it. Since 0f1930c58754 ("parse-options: allow positivation of options starting, with no-", 2012-02-25) we have also had support to negate options which start with "no-" by using the positive wording. This leads to the confusing (and non-documented) case that you can still prefix options beginning with "no-" by a second "no-" to negate them. That is, we allow "no-no-hardlinks" to negate the "no-hardlinks" option. This can be confusing to the user so lets just disallow the double-negative forms. If the long_name begins with "no-" then we simply don't allow the regular negation format, and only allow the option to be negated by the positive form. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--parse-options.c3
-rwxr-xr-xt/t0040-parse-options.sh5
2 files changed, 7 insertions, 1 deletions
diff --git a/parse-options.c b/parse-options.c
index 4fbe924a5d..4e154336f7 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -299,6 +299,9 @@ is_abbreviated:
}
continue;
}
+ /* avoid double-negate on long_name */
+ if (starts_with(long_name, "no-"))
+ continue;
flags |= OPT_UNSET;
if (!skip_prefix(arg + 3, long_name, &rest)) {
/* abbreviated and negated? */
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 74d2cd76fe..abccfa5f26 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -88,7 +88,6 @@ test_expect_success 'OPT_BOOL() is idempotent #1' 'check boolean: 1 --yes --yes'
test_expect_success 'OPT_BOOL() is idempotent #2' 'check boolean: 1 -DB'
test_expect_success 'OPT_BOOL() negation #1' 'check boolean: 0 -D --no-yes'
-test_expect_success 'OPT_BOOL() negation #2' 'check boolean: 0 -D --no-no-doubt'
test_expect_success 'OPT_BOOL() no negation #1' 'check_unknown_i18n --fear'
test_expect_success 'OPT_BOOL() no negation #2' 'check_unknown_i18n --no-no-fear'
@@ -392,4 +391,8 @@ test_expect_success '--no-verbose resets multiple verbose to 0' '
test-parse-options --expect="verbose: 0" -v -v -v --no-verbose
'
+test_expect_success 'double negation not accepted' '
+ test_must_fail test-parse-options --expect="boolean: 0" --no-no-doubt
+'
+
test_done