path: root/color.c
diff options
authorJunio C Hamano <>2007-12-06 01:26:11 (GMT)
committerJunio C Hamano <>2007-12-06 01:57:11 (GMT)
commit0f6f5a4022de5904926cd528c681468e3f635256 (patch)
treeee37c3b7e05ff21f223508ce71ff3cc3f862f32e /color.c
parentcec99d8cef12d18c71b277a4cd6963d37b13e901 (diff)
git config --get-colorbool
This adds an option to help scripts find out color settings from the configuration file. git config --get-colorbool color.diff inspects color.diff variable, and exits with status 0 (i.e. success) if color is to be used. It exits with status 1 otherwise. If a script wants "true"/"false" answer to the standard output of the command, it can pass an additional boolean parameter to its command line, telling if its standard output is a terminal, like this: git config --get-colorbool color.diff true When called like this, the command outputs "true" to its standard output if color is to be used (i.e. "color.diff" says "always", "auto", or "true"), and "false" otherwise. Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'color.c')
1 files changed, 4 insertions, 2 deletions
diff --git a/color.c b/color.c
index 97cfbda..7bd424a 100644
--- a/color.c
+++ b/color.c
@@ -116,7 +116,7 @@ bad:
die("bad config value '%s' for variable '%s'", value, var);
-int git_config_colorbool(const char *var, const char *value)
+int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
if (value) {
if (!strcasecmp(value, "never"))
@@ -133,7 +133,9 @@ int git_config_colorbool(const char *var, const char *value)
/* any normal truth value defaults to 'auto' */
- if (isatty(1) || (pager_in_use && pager_use_color)) {
+ if (stdout_is_tty < 0)
+ stdout_is_tty = isatty(1);
+ if (stdout_is_tty || (pager_in_use && pager_use_color)) {
char *term = getenv("TERM");
if (term && strcmp(term, "dumb"))
return 1;