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

Re: [PATCH B v4 5/5] git config: don't allow --get-color* and variable type

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 22, 2009, 17:35 UTC
Message-ID
<7vmycez86y.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<94a0d4530902220912r94e00d6ha7592bc397baa57c@mail.gmail.com>
Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 23 quoted lines
>>> diff --git a/builtin-config.c b/builtin-config.c
>>> index 8045926..9930568 100644
>>> --- a/builtin-config.c
>>> +++ b/builtin-config.c
>>> @@ -359,6 +359,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
>>>       if (get_colorbool_slot)
>>>           actions |= ACTION_GET_COLORBOOL;
>>>
>>> +     if ((get_color_slot || get_colorbool_slot) && types) {
>>> +             error("--get-color and variable type are incoherent");
>>> +             usage_with_options(builtin_config_usage, builtin_config_options);
>>> +     }
>>> +
>>
>> I do not think I suggested anything like this, so I'd decline to take
>> credit for this patch.
>>
>> Strictly speaking, "--bool --get-colorbool diff.color 1" shouldn't error
>> out, don't you think?  And it certainly shouldn't say "--get-color".
>
> Huh? I misinterpreted:
> I see "git config --bool --get-color diff.color.whitespace" is still
> allowed, which you might want to tighten further.

"--get-color" gets, escape sequence to throw at the terminal to get the color configured. It does not make sense to ask for bool (or int) for that action.

"--get-colorbool" asks if it is appropriate to use such escape sequence (e.g. when the output is tty and config says "auto", you would get "please use color"). In other words, its type is always bool, so using it as --int does not make sense but we cannot really say using it with --bool is nonsense.

The two use formats with and without is_tty are meant to be used in scripts this way:

	# without $is_tty
	if git config --get-colorbool color.diff
        then
        	use_color=true
	else
        	use_color=false
	fi
        # with $is_tty
        if test -t 1
        then
        	is_tty=1
	else
        	is_tty=0
	fi
        use_color=$(git config --get-colorbool color.diff $is_tty)

In the latter form, output from the command is captured by $() and does not see if the stdout of the calling script is a tty, hence the script feeds that information to the command as an extra parameter.

Previous: Felipe ContrerasNext: Felipe Contreras
Message 9 of 13 in “git config: reorganization”
  1. 0/5 git config: reorganizationFelipe Contreras, Feb 21, 2009
  2. 1/5 git config: reorganize to use parseoptFelipe Contreras, Feb 21, 2009
  3. 2/5 git config: don't allow multiple config file locationsFelipe Contreras, Feb 21, 2009
  4. 3/5 git config: don't allow multiple variable typesFelipe Contreras, Feb 21, 2009
  5. 4/5 git config: don't allow extra arguments for -e or -l.Felipe Contreras, Feb 21, 2009
  6. 5/5 git config: don't allow --get-color* and variable typeFelipe Contreras, Feb 21, 2009
  7. Junio C HamanoFeb 22, 2009
  8. Felipe ContrerasFeb 22, 2009
  9. Junio C HamanoFeb 22, 2009
  10. Felipe ContrerasMar 7, 2009
  11. Junio C HamanoFeb 22, 2009
  12. Felipe ContrerasFeb 22, 2009
  13. Felipe ContrerasFeb 21, 2009

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.