summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-10-18 14:20:43 +0900
committerJunio C Hamano <gitster@pobox.com>2017-10-18 14:20:43 +0900
commite3e3c6a43e7f36d507129909e49d54f1e8ad65e2 (patch)
treeb4ab435d592b835fcc4f0a637d0b758d1600c7cd
parent4e4a0c6e794f1f37ba7fa65e5e774b9d6c168afc (diff)
parentb521fd122865dca88b99d05344ec189d39efcefb (diff)
downloadgit-e3e3c6a43e7f36d507129909e49d54f1e8ad65e2.tar.gz
Merge branch 'jk/ref-filter-colors-fix' into maint
This is the "theoretically more correct" approach of simply stepping back to the state before plumbing commands started paying attention to "color.ui" configuration variable. * jk/ref-filter-colors-fix: tag: respect color.ui config Revert "color: check color.ui in git_default_config()" Revert "t6006: drop "always" color config tests" Revert "color: make "always" the same as "auto" in config" color: make "always" the same as "auto" in config provide --color option for all ref-filter users t3205: use --color instead of color.branch=always t3203: drop "always" color test t6006: drop "always" color config tests t7502: use diff.noprefix for --verbose test t7508: use test_terminal for color output t3701: use test-terminal to collect color output t4015: prefer --color to -c color.diff=always test-terminal: set TERM=vt100
-rw-r--r--Documentation/git-for-each-ref.txt5
-rw-r--r--Documentation/git-tag.txt5
-rw-r--r--builtin/branch.c2
-rw-r--r--builtin/clean.c3
-rw-r--r--builtin/for-each-ref.c1
-rw-r--r--builtin/grep.c2
-rw-r--r--builtin/show-branch.c2
-rw-r--r--builtin/tag.c3
-rw-r--r--color.c8
-rw-r--r--config.c4
-rw-r--r--diff.c3
-rwxr-xr-xt/t3203-branch-output.sh8
-rwxr-xr-xt/t3205-branch-color.sh5
-rwxr-xr-xt/t3701-add-interactive.sh18
-rwxr-xr-xt/t4015-diff-whitespace.sh28
-rwxr-xr-xt/t4202-log.sh2
-rwxr-xr-xt/t6006-rev-list-format.sh3
-rwxr-xr-xt/t6300-for-each-ref.sh12
-rwxr-xr-xt/t7004-tag.sh8
-rwxr-xr-xt/t7006-pager.sh6
-rwxr-xr-xt/t7502-commit.sh4
-rwxr-xr-xt/t7508-status.sh41
-rwxr-xr-xt/test-terminal.perl1
23 files changed, 103 insertions, 71 deletions
diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index 66b4e0a405..cbd0a6212a 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -57,6 +57,11 @@ OPTIONS
`xx`; for example `%00` interpolates to `\0` (NUL),
`%09` to `\t` (TAB) and `%0a` to `\n` (LF).
+--color[=<when>]:
+ Respect any colors specified in the `--format` option. The
+ `<when>` field must be one of `always`, `never`, or `auto` (if
+ `<when>` is absent, behave as if `always` was given).
+
--shell::
--perl::
--python::
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 95e9f391d8..956fc019f9 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -115,6 +115,11 @@ options for details.
variable if it exists, or lexicographic order otherwise. See
linkgit:git-config[1].
+--color[=<when>]:
+ Respect any colors specified in the `--format` option. The
+ `<when>` field must be one of `always`, `never`, or `auto` (if
+ `<when>` is absent, behave as if `always` was given).
+
-i::
--ignore-case::
Sorting and filtering tags are case insensitive.
diff --git a/builtin/branch.c b/builtin/branch.c
index 2ea92a70b7..8f779b02b5 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -92,7 +92,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
return config_error_nonbool(var);
return color_parse(value, branch_colors[slot]);
}
- return git_default_config(var, value, cb);
+ return git_color_default_config(var, value, cb);
}
static const char *branch_get_color(enum color_branch ix)
diff --git a/builtin/clean.c b/builtin/clean.c
index c1bafda5b6..057fc97fe4 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -125,7 +125,8 @@ static int git_clean_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ /* inspect the color.ui config variable and others */
+ return git_color_default_config(var, value, cb);
}
static const char *clean_get_color(enum color_clean ix)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 5d7c921a77..e931be9ce4 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -36,6 +36,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
OPT_GROUP(""),
OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")),
OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")),
+ OPT__COLOR(&format.use_color, N_("respect format colors")),
OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
N_("field name to sort on"), &parse_opt_ref_sorting),
OPT_CALLBACK(0, "points-at", &filter.points_at,
diff --git a/builtin/grep.c b/builtin/grep.c
index 42ff87065a..7e79eb1a75 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -284,7 +284,7 @@ static int wait_all(void)
static int grep_cmd_config(const char *var, const char *value, void *cb)
{
int st = grep_config(var, value, cb);
- if (git_default_config(var, value, cb) < 0)
+ if (git_color_default_config(var, value, cb) < 0)
st = -1;
if (!strcmp(var, "grep.threads")) {
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 28f245c8cc..7073a3eb97 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -554,7 +554,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
return 0;
}
- return git_default_config(var, value, cb);
+ return git_color_default_config(var, value, cb);
}
static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
diff --git a/builtin/tag.c b/builtin/tag.c
index 7a70d5a9bb..00382a56f5 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -158,7 +158,7 @@ static int git_tag_config(const char *var, const char *value, void *cb)
if (starts_with(var, "column."))
return git_column_config(var, value, "tag", &colopts);
- return git_default_config(var, value, cb);
+ return git_color_default_config(var, value, cb);
}
static void write_tag_body(int fd, const struct object_id *oid)
@@ -411,6 +411,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
},
OPT_STRING( 0 , "format", &format.format, N_("format"),
N_("format to use for the output")),
+ OPT__COLOR(&format.use_color, N_("respect format colors")),
OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
OPT_END()
};
diff --git a/color.c b/color.c
index 7aa8b076f0..31b6207a00 100644
--- a/color.c
+++ b/color.c
@@ -361,6 +361,14 @@ int git_color_config(const char *var, const char *value, void *cb)
return 0;
}
+int git_color_default_config(const char *var, const char *value, void *cb)
+{
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
+ return git_default_config(var, value, cb);
+}
+
void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb)
{
if (*color)
diff --git a/config.c b/config.c
index c138c0ba05..c6bc2ff715 100644
--- a/config.c
+++ b/config.c
@@ -16,7 +16,6 @@
#include "string-list.h"
#include "utf8.h"
#include "dir.h"
-#include "color.h"
struct config_source {
struct config_source *prev;
@@ -1351,9 +1350,6 @@ int git_default_config(const char *var, const char *value, void *dummy)
if (starts_with(var, "advice."))
return git_default_advice_config(var, value);
- if (git_color_config(var, value, dummy) < 0)
- return -1;
-
if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
pager_use_color = git_config_bool(var,value);
return 0;
diff --git a/diff.c b/diff.c
index 9c38258030..85e714f6c6 100644
--- a/diff.c
+++ b/diff.c
@@ -299,6 +299,9 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
return 0;
}
+ if (git_color_config(var, value, cb) < 0)
+ return -1;
+
return git_diff_basic_config(var, value, cb);
}
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index d2aec0f38b..ee6787614c 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -253,13 +253,7 @@ test_expect_success '%(color) omitted without tty' '
'
test_expect_success TTY '%(color) present with tty' '
- test_terminal env TERM=vt100 git branch $color_args >actual.raw &&
- test_decode_color <actual.raw >actual &&
- test_cmp expect.color actual
-'
-
-test_expect_success 'color.branch=always overrides auto-color' '
- git -c color.branch=always branch $color_args >actual.raw &&
+ test_terminal git branch $color_args >actual.raw &&
test_decode_color <actual.raw >actual &&
test_cmp expect.color actual
'
diff --git a/t/t3205-branch-color.sh b/t/t3205-branch-color.sh
index 9343550f50..4f1e16bb44 100755
--- a/t/t3205-branch-color.sh
+++ b/t/t3205-branch-color.sh
@@ -12,7 +12,6 @@ test_expect_success 'set up some sample branches' '
# choose non-default colors to make sure config
# is taking effect
test_expect_success 'set up some color config' '
- git config color.branch always &&
git config color.branch.local blue &&
git config color.branch.remote yellow &&
git config color.branch.current cyan
@@ -24,7 +23,7 @@ test_expect_success 'regular output shows colors' '
<BLUE>other<RESET>
<YELLOW>remotes/origin/master<RESET>
EOF
- git branch -a >actual.raw &&
+ git branch --color -a >actual.raw &&
test_decode_color <actual.raw >actual &&
test_cmp expect actual
'
@@ -36,7 +35,7 @@ test_expect_success 'verbose output shows colors' '
<BLUE>other <RESET> $oid foo
<YELLOW>remotes/origin/master<RESET> $oid foo
EOF
- git branch -v -a >actual.raw &&
+ git branch --color -v -a >actual.raw &&
test_decode_color <actual.raw >actual &&
test_cmp expect actual
'
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 2f3e7cea64..a49c12c79b 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -2,6 +2,7 @@
test_description='add -i basic tests'
. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
if ! test_have_prereq PERL
then
@@ -380,14 +381,11 @@ test_expect_success 'patch mode ignores unmerged entries' '
test_cmp expected diff
'
-test_expect_success 'diffs can be colorized' '
+test_expect_success TTY 'diffs can be colorized' '
git reset --hard &&
- # force color even though the test script has no terminal
- test_config color.ui always &&
-
echo content >test &&
- printf y | git add -p >output 2>&1 &&
+ printf y | test_terminal git add -p >output 2>&1 &&
# We do not want to depend on the exact coloring scheme
# git uses for diffs, so just check that we saw some kind of color.
@@ -485,4 +483,14 @@ test_expect_success 'hunk-editing handles custom comment char' '
git diff --exit-code
'
+test_expect_success 'add -p works even with color.ui=always' '
+ git reset --hard &&
+ echo change >>file &&
+ test_config color.ui always &&
+ echo y | git add -p &&
+ echo file >expect &&
+ git diff --cached --name-only >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 289806d0c7..94597ff284 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -821,7 +821,7 @@ test_expect_success 'diff that introduces a line with only tabs' '
echo "test" >x &&
git commit -m "initial" x &&
echo "{NTN}" | tr "NT" "\n\t" >>x &&
- git -c color.diff=always diff | test_decode_color >current &&
+ git diff --color | test_decode_color >current &&
cat >expected <<-\EOF &&
<BOLD>diff --git a/x b/x<RESET>
@@ -851,7 +851,7 @@ test_expect_success 'diff that introduces and removes ws breakages' '
echo "2. and a new line "
} >x &&
- git -c color.diff=always diff |
+ git diff --color |
test_decode_color >current &&
cat >expected <<-\EOF &&
@@ -923,15 +923,15 @@ test_expect_success 'ws-error-highlight test setup' '
test_expect_success 'test --ws-error-highlight option' '
- git -c color.diff=always diff --ws-error-highlight=default,old |
+ git diff --color --ws-error-highlight=default,old |
test_decode_color >current &&
test_cmp expect.default-old current &&
- git -c color.diff=always diff --ws-error-highlight=all |
+ git diff --color --ws-error-highlight=all |
test_decode_color >current &&
test_cmp expect.all current &&
- git -c color.diff=always diff --ws-error-highlight=none |
+ git diff --color --ws-error-highlight=none |
test_decode_color >current &&
test_cmp expect.none current
@@ -939,15 +939,15 @@ test_expect_success 'test --ws-error-highlight option' '
test_expect_success 'test diff.wsErrorHighlight config' '
- git -c color.diff=always -c diff.wsErrorHighlight=default,old diff |
+ git -c diff.wsErrorHighlight=default,old diff --color |
test_decode_color >current &&
test_cmp expect.default-old current &&
- git -c color.diff=always -c diff.wsErrorHighlight=all diff |
+ git -c diff.wsErrorHighlight=all diff --color |
test_decode_color >current &&
test_cmp expect.all current &&
- git -c color.diff=always -c diff.wsErrorHighlight=none diff |
+ git -c diff.wsErrorHighlight=none diff --color |
test_decode_color >current &&
test_cmp expect.none current
@@ -955,18 +955,18 @@ test_expect_success 'test diff.wsErrorHighlight config' '
test_expect_success 'option overrides diff.wsErrorHighlight' '
- git -c color.diff=always -c diff.wsErrorHighlight=none \
- diff --ws-error-highlight=default,old |
+ git -c diff.wsErrorHighlight=none \
+ diff --color --ws-error-highlight=default,old |
test_decode_color >current &&
test_cmp expect.default-old current &&
- git -c color.diff=always -c diff.wsErrorHighlight=default \
- diff --ws-error-highlight=all |
+ git -c diff.wsErrorHighlight=default \
+ diff --color --ws-error-highlight=all |
test_decode_color >current &&
test_cmp expect.all current &&
- git -c color.diff=always -c diff.wsErrorHighlight=all \
- diff --ws-error-highlight=none |
+ git -c diff.wsErrorHighlight=all \
+ diff --color --ws-error-highlight=none |
test_decode_color >current &&
test_cmp expect.none current
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 36d120c969..8f155da7a5 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -750,7 +750,7 @@ test_expect_success 'log.decorate config parsing' '
'
test_expect_success TTY 'log output on a TTY' '
- git log --oneline --decorate >expect.short &&
+ git log --color --oneline --decorate >expect.short &&
test_terminal git log --oneline >actual &&
test_cmp expect.short actual
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index b326d550f3..98be78b4a2 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -229,8 +229,7 @@ do
'
test_expect_success TTY "$desc respects --color=auto (stdout is tty)" '
- test_terminal env TERM=vt100 \
- git log --format=$color -1 --color=auto >actual &&
+ test_terminal git log --format=$color -1 --color=auto >actual &&
has_color actual
'
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index edc1bd8eab..d0ad902911 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -426,8 +426,7 @@ test_expect_success 'set up color tests' '
'
test_expect_success TTY '%(color) shows color with a tty' '
- test_terminal env TERM=vt100 \
- git for-each-ref --format="$color_format" >actual.raw &&
+ test_terminal git for-each-ref --format="$color_format" >actual.raw &&
test_decode_color <actual.raw >actual &&
test_cmp expected.color actual
'
@@ -437,12 +436,17 @@ test_expect_success '%(color) does not show color without tty' '
test_cmp expected.bare actual
'
-test_expect_success 'color.ui=always can override tty check' '
- git -c color.ui=always for-each-ref --format="$color_format" >actual.raw &&
+test_expect_success '--color can override tty check' '
+ git for-each-ref --color --format="$color_format" >actual.raw &&
test_decode_color <actual.raw >actual &&
test_cmp expected.color actual
'
+test_expect_success 'color.ui=always does not override tty check' '
+ git -c color.ui=always for-each-ref --format="$color_format" >actual &&
+ test_cmp expected.bare actual
+'
+
cat >expected <<\EOF
heads/master
tags/master
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index dbcd6f623c..62aa322846 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1914,7 +1914,13 @@ test_expect_success '%(color) omitted without tty' '
'
test_expect_success TTY '%(color) present with tty' '
- test_terminal env TERM=vt100 git tag $color_args >actual.raw &&
+ test_terminal git tag $color_args >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expect.color actual
+'
+
+test_expect_success '--color overrides auto-color' '
+ git tag --color $color_args >actual.raw &&
test_decode_color <actual.raw >actual &&
test_cmp expect.color actual
'
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index 9128ec5acd..f0f1abd1c2 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -239,7 +239,7 @@ test_expect_success 'no color when stdout is a regular file' '
test_expect_success TTY 'color when writing to a pager' '
rm -f paginated.out &&
test_config color.ui auto &&
- test_terminal env TERM=vt100 git log &&
+ test_terminal git log &&
colorful paginated.out
'
@@ -247,7 +247,7 @@ test_expect_success TTY 'colors are suppressed by color.pager' '
rm -f paginated.out &&
test_config color.ui auto &&
test_config color.pager false &&
- test_terminal env TERM=vt100 git log &&
+ test_terminal git log &&
! colorful paginated.out
'
@@ -266,7 +266,7 @@ test_expect_success 'color when writing to a file intended for a pager' '
test_expect_success TTY 'colors are sent to pager for external commands' '
test_config alias.externallog "!git log" &&
test_config color.ui auto &&
- test_terminal env TERM=vt100 git -p externallog &&
+ test_terminal git -p externallog &&
colorful paginated.out
'
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 725687d5d5..d33a3cb331 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -171,9 +171,9 @@ test_expect_success 'verbose' '
test_expect_success 'verbose respects diff config' '
- test_config color.diff always &&
+ test_config diff.noprefix true &&
git status -v >actual &&
- grep "\[1mdiff --git" actual
+ grep "diff --git negative negative" actual
'
mesg_with_comment_and_newlines='
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 43d19a9b22..a3d760e63a 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -6,6 +6,7 @@
test_description='git status'
. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
test_expect_success 'status -h in broken repository' '
git config --global advice.statusuoption false &&
@@ -667,7 +668,7 @@ test_expect_success 'setup unique colors' '
'
-test_expect_success 'status with color.ui' '
+test_expect_success TTY 'status with color.ui' '
cat >expect <<\EOF &&
On branch <GREEN>master<RESET>
Your branch and '\''upstream'\'' have diverged,
@@ -694,14 +695,14 @@ Untracked files:
<BLUE>untracked<RESET>
EOF
- test_config color.ui always &&
- git status | test_decode_color >output &&
+ test_config color.ui auto &&
+ test_terminal git status | test_decode_color >output &&
test_i18ncmp expect output
'
-test_expect_success 'status with color.status' '
- test_config color.status always &&
- git status | test_decode_color >output &&
+test_expect_success TTY 'status with color.status' '
+ test_config color.status auto &&
+ test_terminal git status | test_decode_color >output &&
test_i18ncmp expect output
'
@@ -714,19 +715,19 @@ cat >expect <<\EOF
<BLUE>??<RESET> untracked
EOF
-test_expect_success 'status -s with color.ui' '
+test_expect_success TTY 'status -s with color.ui' '
- git config color.ui always &&
- git status -s | test_decode_color >output &&
+ git config color.ui auto &&
+ test_terminal git status -s | test_decode_color >output &&
test_cmp expect output
'
-test_expect_success 'status -s with color.status' '
+test_expect_success TTY 'status -s with color.status' '
git config --unset color.ui &&
- git config color.status always &&
- git status -s | test_decode_color >output &&
+ git config color.status auto &&
+ test_terminal git status -s | test_decode_color >output &&
test_cmp expect output
'
@@ -741,9 +742,9 @@ cat >expect <<\EOF
<BLUE>??<RESET> untracked
EOF
-test_expect_success 'status -s -b with color.status' '
+test_expect_success TTY 'status -s -b with color.status' '
- git status -s -b | test_decode_color >output &&
+ test_terminal git status -s -b | test_decode_color >output &&
test_i18ncmp expect output
'
@@ -757,20 +758,20 @@ A dir2/added
?? untracked
EOF
-test_expect_success 'status --porcelain ignores color.ui' '
+test_expect_success TTY 'status --porcelain ignores color.ui' '
git config --unset color.status &&
- git config color.ui always &&
- git status --porcelain | test_decode_color >output &&
+ git config color.ui auto &&
+ test_terminal git status --porcelain | test_decode_color >output &&
test_cmp expect output
'
-test_expect_success 'status --porcelain ignores color.status' '
+test_expect_success TTY 'status --porcelain ignores color.status' '
git config --unset color.ui &&
- git config color.status always &&
- git status --porcelain | test_decode_color >output &&
+ git config color.status auto &&
+ test_terminal git status --porcelain | test_decode_color >output &&
test_cmp expect output
'
diff --git a/t/test-terminal.perl b/t/test-terminal.perl
index 96b6a03e1c..46bf618479 100755
--- a/t/test-terminal.perl
+++ b/t/test-terminal.perl
@@ -80,6 +80,7 @@ sub copy_stdio {
if ($#ARGV < 1) {
die "usage: test-terminal program args";
}
+$ENV{TERM} = 'vt100';
my $master_in = new IO::Pty;
my $master_out = new IO::Pty;
my $master_err = new IO::Pty;