From: Andreas Schwab Date: Fri, 25 Sep 2009 18:44:44 GMT Subject: Re: 'git branch --no-merge' is ambiguous Message-ID: In-Reply-To: <4ABC9B69.5010205@viscovery.net> Johannes Sixt writes: > Look here: > > $ git branch --merge > * master > $ git branch --no-merge > error: Ambiguous option: no-merge (could be --no-merged or --no-merged) > usage: ... > --no-merged print only not merged branches > --merged print only merged branches > > I tried to debug it, but parse_long_opt() is such awful spaghetti code > that I don't grok it. Please help. parse_long_opt always matches both --opt and --no-opt for any option "opt", and only get_value checks whether --no-opt is actually valid. Since the options for git branch contains both "no-merged" and "merged" there are two matches for --no-merge, but no exact match. With this patch the negation of a NONEG option is rejected earlier, but it changes the error message from "option `no-opt' isn't available" to "unknown option `no-opt'". diff --git a/parse-options.c b/parse-options.c index a64a4d6..f559411 100644 --- a/parse-options.c +++ b/parse-options.c @@ -230,6 +230,9 @@ is_abbreviated: abbrev_flags = flags; continue; } + /* negation allowed? */ + if (options->flags & PARSE_OPT_NONEG) + continue; /* negated and abbreviated very much? */ if (!prefixcmp("no-", arg)) { flags |= OPT_UNSET; Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."