Web lists-archives.com

Re: [PATCH] various: disallow --no-no-OPT for --no-opt options




On Wed, Apr 19, 2017 at 12:29:18AM +0200, René Scharfe wrote:

> Am 18.04.2017 um 19:09 schrieb Ævar Arnfjörð Bjarmason:
> > Change various --no-OPT options which don't supply PARSE_OPT_NONEG to
> > make --no-no-OPT an error.
> > 
> > All of these worked before this change, e.g. doing cloning by doing
> > "git clone --no-no-checkout" is equivalent to just "git clone", but
> > this was never intended, and is inconsistent with other --no-OPT
> > options which do pass PARSE_OPT_NONEG.
> 
> First: Why does that bother you, i.e. what's the harm?
> 
> Setting PARSE_OPT_NONEG takes away the ability to toggle the affected
> option.  E.g. git clone would reject --checkout.  Currently users can
> specify --no- options as defaults in aliases and override them on the
> command line if needed, with the patch that won't be possible anymore.
> 
> PARSE_OPT_NONEG should only be used for options where a negation doesn't
> make sense, e.g. for the --stage option of checkout-index.

I think we do strive to avoid "--no-no-foo", and instead have "--no-foo"
and "--foo" to cover both sides.  So for example:

> > -		OPT_BOOL(0, "no-add", &state->no_add,
> > +		OPT_BOOL_NONEG(0, "no-add", &state->no_add,
> >   			N_("ignore additions made by the patch")),

This could be more like:

  OPT_NEGBOOL(0, "add", &state->no_add, ...)

where NEGBOOL would be smart enough to show "--no-add" in the help as
the primary. It might even be possible to detect the existing line and
have parse-options automatically respect "--foo" when "--no-foo" is
present.  But that may run afoul of callers that add both "--foo" and
"--no-foo" manually.

-Peff