Note that:
- the support for colors is now documented (January 2015, Git 2.2.2, commit 0edad17 ) :
docs: describe ANSI 256-color mode
Our color specifications have supported the 256-color ANSI extension for years, but we never documented it.
git config
man page now includes:
Colors (foreground and background) may also be given as numbers between 0 and 255;
these use ANSI 256-color mode (but note that not all terminals may support this)
config: fix parsing of "git config --get-color some.key -1
"
Most of git-config's command line options use OPT_BIT
to choose an action, and then parse the non-option arguments in a context-dependent way. However, --get-color
and --get-colorbool
are unlike the rest of the options, in that they are OPT_STRING
, taking the option name as a parameter.
This generally works, because we then use the presence of those strings to set an action bit anyway. But it does mean that the option-parser will continue looking for options even after the key (because it is not a non-option; it is an argument to an option). And running:
git config --get-color some.key -1
(to use "-1
" as the default color spec) will barf, claiming that "-1
" is not an option.
Instead, we should treat --get-color
and --get-colorbool
as action bits, just like --add
, --get
, and all the other actions, and then check that the non-option arguments we got are sane.
This fixes the weirdness above, and makes those two options like all the others.
This "fixes" a test in t/t4026-color.sh
, which checked that feeding "-2
" as a color should fail (it does fail, but prior to this patch, because parseopt
barfed, not because we actually ever tried to parse the color).
This also catches other errors, like:
git config --get-color some.key black blue
which previously silently ignored "blue
" (and now will complain that you gave too many arguments).
There are some possible regressions, though.
We now disallow these, which currently do what you would expect:
# specifying other options after the action
git config --get-color some.key --file whatever
# using long-arg syntax
git config --get-color=some.key
If 256 colors are not enough, you can import even more colors.
See commit 17a4be2 (Git 2.3.0, Q1 2015)
parse_color
: support 24-bit RGB values
Some terminals (like XTerm) allow full 24-bit RGB color specifications using an extension to the regular ANSI color scheme.
Let's allow users to specify hex RGB colors, enabling the all-important feature of hot pink ref decorations:
git log --format="%h%C(#ff69b4)%d%C(reset) %s"