Skip to content

Commit a7d7853

Browse files
committed
Merge branch 'jn/grep-open'
* jn/grep-open: grep -O: Do not pass color sequences as filenames to pager
2 parents cb597ad + e7b082a commit a7d7853

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

builtin/grep.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
10011001
if (show_in_pager == default_pager)
10021002
show_in_pager = git_pager(1);
10031003
if (show_in_pager) {
1004+
opt.color = 0;
10041005
opt.name_only = 1;
10051006
opt.null_following_name = 1;
10061007
opt.output_priv = &path_list;

t/t7811-grep-open.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ test_expect_success 'modified file' '
125125
test_cmp empty out
126126
'
127127

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+
128143
test_expect_success 'run from subdir' '
129144
rm -f actual &&
130145
echo grep.c >expect &&

0 commit comments

Comments
 (0)