git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: RFC proposal: set git defaults options from config

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
May 16, 2011, 12:54 UTC
Message-ID
<4DD11E76.1010707@drmicha.warpmail.net>
In-Reply-To
<20110516110256.GB23889@sigill.intra.peff.net>
Jeff King venit, vidit, dixit 16.05.2011 13:02:
Show 28 quoted lines
> On Thu, May 12, 2011 at 04:35:11PM +0200, Michael J Gruber wrote:
> 
>> Mechanism
>> =========
>>
>> I propose the following mechanism for setting default command line
>> options from the config:
>>
>> options.<cmd> = <value>
>>
>> is a "multivar" in git-config speak, i.e. it can appear multiple times.
>> When running "git <cmd> <opts>", our wrapper executes
>>
>> git <cmd> <values> <opt>
>>
>> where <values> is determined by the following rule in pseudocode:
>>
>> if $GIT_OPTIONS_<cmd> is unset:
>>   <values> := empty
>> else:
>>   for <value> in $(git config --get-all options.cmd):
>>     if <value> matches the regexp in $GIT_OPTIONS_<CMD>:
>>       append <value> to <values>
> 
> As a user, how would I active this for all commands when not running a
> script? I see why you defensively say "if unset, don't enable this
> feature at all".  As a user, should I have to set GIT_OPTIONS_CMD for
> everything that I want to configure? I hope not.

Yeah, sorry, I was a bit dense. I meant to activate it by default and shut it off from git-sh-setup by default so that scripts are not affected (but can choose to enable it selevtively).

> I think we need one extra variable to say generally "I am in strict
> plumbing mode" or "I am in user mode". So you would want something like:
Show 11 quoted lines
> 
>   if $GIT_STRICT is unset:
>     <values> := $(git config --get-all options.cmd)
>   else if $GIT_OPTIONS_<cmd> is unset:
>     <values> := empty
>   else:
>     [match values by regex as you do]
> 
> But then you have a question of when GIT_STRICT gets set. An obvious
> place is to set it in the git wrapper, so that "git foo" will have its
> subcommands properly strict.
Yep.
> But that doesn't help scripts which are not called from the git wrapper;
> they need to set GIT_STRICT themselves, so we need a phase-in period for
> them to do so.
git-sh-setup
The phase-in is still needed for scripts which do use sh-setup, of course.
Show 9 quoted lines
>> NOTES
>> =====
>>
>> * This can be done by commit_pager_choice() or by a call right after
>> that in those places.
> 
> Ah, so reading this, I have a sense that you were intending to make the
> equivalent of GIT_STRICT be "am I running a pager" (or "am I outputting
> to a terminal)?
As a default for the phase-in-phase I was hoping that would be safe enough.
Show 30 quoted lines
> Which is somewhat safer, as it is purely something for programs to opt
> into. And as a heuristic, it's mostly good. I can come up with examples
> where a script might not want to allow some options to be passed, even
> though output is to the user, but they are probably stretching (e.g.,
> something like "--allow-textconv" in a script that is meant to restrict
> the users rights).
> 
>> * regexp notation/version to be decided
> 
> I think I would just as soon have a list of allowed options. We're
> hopefully not doing the regex over the value of the option, like
> "--pretty=foo is OK, but --pretty=bar is not". It seems like this
> unnecessarily complicate the common case (you don't care what the value
> is, but you have to tack on (|=.*) to every option matcher), and the
> added flexibility is probably not going to be useful.
> 
> So I expect options regex are just going to look like:
> 
>   --(foo|bar|baz|bleep)
> 
> at which point we might as well just make it a list. And for the sake of
> sanity, we may want to provide some default lists for scripts to OK,
> like some minimal set of rev limiting options or something, so that
> scripts don't end up specifying the same sets over and over.
> 
>> * We should probably do this for long options only (and insert
>> "--<value>" rather than "<value>" to spare the "--" in config).
> 
> Yeah. Anything that doesn't have a long option and is useful enough to
> be used in this way should probably get one.
Agreed!
Show 6 quoted lines
>> Taking cover...
> 
> I dunno. It's not so bad. But I think we probably want to start with an
> environment variable to say "I am a script, be strict", let scripts
> start picking that up, and then phase in the ability to turn on options
> selectively.
GIT_BE_STRICT_I_AM_BRITISH
Michael
Previous: Jeff King
Message 14 of 14 in “Adds 'stash.index' configuration option”
  1. Adds 'stash.index' configuration optionDavid Pisoni, May 11, 2011
  2. Junio C HamanoMay 11, 2011
  3. Junio C HamanoMay 12, 2011
  4. David PisoniMay 12, 2011
  5. Junio C HamanoMay 12, 2011
  6. Michael J GruberMay 12, 2011
  7. Jeff KingMay 12, 2011
  8. Michael J GruberMay 12, 2011
  9. Jeff KingMay 12, 2011
  10. RFC proposal: set git defaults options from configMichael J Gruber, May 12, 2011
  11. David PisoniMay 12, 2011
  12. Jeff KingMay 16, 2011
  13. Jeff KingMay 16, 2011
  14. Michael J GruberMay 16, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.