parse-options: detect ambiguous self-negation
commit0d8a3097c74ed3b78442c4d533f3427316596a46
authorRené Scharfe <l.s.r@web.de>
Sun, 3 Mar 2024 12:19:41 +0000 (3 13:19 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 3 Mar 2024 17:49:21 +0000 (3 09:49 -0800)
tree3a06f5cef0415bdd9ee8767ee16e8adb79045481
parentcb46c3faf843fa46ce2df22baeb02ad2f60da6fb
parse-options: detect ambiguous self-negation

Git currently does not detect the ambiguity of an option that starts
with "no" like --notes and its negated form if given just --n or --no.
All Git commands with such options have other negatable options, and
we detect the ambiguity with them, so that's currently only a potential
problem for scripts that use git rev-parse --parseopt.

Let's fix it nevertheless, as there's no need for that confusion.  To
detect the ambiguity we have to loosen the check in register_abbrev(),
as an option is considered an alias of itself.  Add non-matching
negation flags as a criterion to recognize an option being ambiguous
with its negated form.

And we need to keep going after finding a non-negated option as an
abbreviated candidate and perform the negation checks in the same
loop.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c
t/t1502-rev-parse-parseopt.sh