grep -O: Do not pass color sequences as filenames to pager
With a .gitconfig like this: [color] ui = auto [color "grep"] filename = magenta if stdout is a terminal, the grep machinery will output the color sequence \e[36m before each filename in its output. In the case of "git grep -O foo", output is argv for the pager. Disable color when calling the grep machinery in this case. Signed-off-by: Nazri Ramliy <ayiehere@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nazri Ramliy committed
Jul 2, 2010 at 21:55 UTC
e7b082a4118d15e901f4f44b067394b314a0ae6a
2 files changed
+16
builtin/grep.c
+1
@@ -997,6 +997,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
997
if (show_in_pager == default_pager)
998
show_in_pager = git_pager(1);
999
if (show_in_pager) {
1000
+ opt.color = 0;
1001
opt.name_only = 1;
1002
opt.null_following_name = 1;
1003
opt.output_priv = &path_list;
t/t7811-grep-open.sh
+15
@@ -125,6 +125,21 @@ test_expect_success 'modified file' '
125
test_cmp empty out
126
'
127
128
+test_config() {
129
+ git config "$1" "$2" &&
130
+ test_when_finished "git config --unset $1"
131
+}
132
+
133
+test_expect_success 'copes with color settings' '
134
+ rm -f actual &&
135
+ echo grep.h >expect &&
136
+ test_config color.grep always &&
137
+ test_config color.grep.filename yellow &&
138
+ test_config color.grep.separator green &&
139
+ git grep -O'\''printf "%s\n" >actual'\'' GREP_AND &&
140
+ test_cmp expect actual
141
+'
142
+
143
test_expect_success 'run from subdir' '
144
rm -f actual &&
145
echo grep.c >expect &&