Skip to content

Commit 3e9e416

Browse files
committed
Merge branch 'tr/grep-l-with-decoration'
* tr/grep-l-with-decoration: grep: fix -l/-L interaction with decoration lines
2 parents fc75ad7 + 50dd0f2 commit 3e9e416

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

builtin/grep.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
10341034

10351035
#ifndef NO_PTHREADS
10361036
if (use_threads) {
1037-
if (opt.pre_context || opt.post_context || opt.file_break ||
1038-
opt.funcbody)
1037+
if (!(opt.name_only || opt.unmatch_name_only || opt.count)
1038+
&& (opt.pre_context || opt.post_context ||
1039+
opt.file_break || opt.funcbody))
10391040
skip_first_line = 1;
10401041
start_threads(&opt);
10411042
}

t/t7810-grep.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,28 @@ do
245245
'
246246
done
247247

248+
cat >expected <<EOF
249+
file
250+
EOF
251+
test_expect_success 'grep -l -C' '
252+
git grep -l -C1 foo >actual &&
253+
test_cmp expected actual
254+
'
255+
256+
cat >expected <<EOF
257+
file:5
258+
EOF
259+
test_expect_success 'grep -l -C' '
260+
git grep -c -C1 foo >actual &&
261+
test_cmp expected actual
262+
'
263+
264+
test_expect_success 'grep -L -C' '
265+
git ls-files >expected &&
266+
git grep -L -C1 nonexistent_string >actual &&
267+
test_cmp expected actual
268+
'
269+
248270
cat >expected <<EOF
249271
file:foo mmap bar_mmap
250272
EOF

0 commit comments

Comments
 (0)