Skip to content

Commit 46e315c

Browse files
committed
grep: multiple path_limiters and extended_regexp
Signed-off-by: Bryce Lanham <blanham@gmail.com>
1 parent 8992701 commit 46e315c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/git/lib.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,12 @@ def grep(string, opts = {})
413413
grep_opts = ['-n']
414414
grep_opts << '-i' if opts[:ignore_case]
415415
grep_opts << '-v' if opts[:invert_match]
416+
grep_opts << '-E' if opts[:extended_regexp]
416417
grep_opts << '-e'
417418
grep_opts << string
418419
grep_opts << opts[:object] if opts[:object].is_a?(String)
419-
grep_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String
420+
grep_opts.push('--', opts[:path_limiter]) if opts[:path_limiter].is_a?(String)
421+
grep_opts.push('--', *opts[:path_limiter]) if opts[:path_limiter].is_a?(Array)
420422

421423
hsh = {}
422424
command_lines('grep', *grep_opts).each do |line|

tests/units/test_lib.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ def test_grep
291291
assert_equal("you can't search me!", match["gitsearch1:scott/newfile"].first[1])
292292
assert_equal(1, match.size)
293293

294+
match = @lib.grep('search', :object => 'gitsearch1', :path_limiter => ['scott/new*', 'scott/text.*'])
295+
assert_equal("you can't search me!", match["gitsearch1:scott/newfile"].first[1])
296+
assert_equal('to search one', match['gitsearch1:scott/text.txt'].assoc(6)[1])
297+
assert_equal(2, match['gitsearch1:scott/text.txt'].size)
298+
assert_equal(2, match.size)
299+
294300
match = @lib.grep('SEARCH', :object => 'gitsearch1')
295301
assert_equal(0, match.size)
296302

@@ -302,6 +308,11 @@ def test_grep
302308
assert_equal(6, match['gitsearch1:scott/text.txt'].size)
303309
assert_equal(2, match.size)
304310

311+
match = @lib.grep("you can't search me!|nothing!", :object => 'gitsearch1', :extended_regexp => true)
312+
assert_equal("you can't search me!", match["gitsearch1:scott/newfile"].first[1])
313+
assert_equal("nothing!", match["gitsearch1:scott/text.txt"].first[1])
314+
assert_equal(2, match.size)
315+
305316
match = @lib.grep('Grep', :object => 'grep_colon_numbers')
306317
assert_equal("Grep regex doesn't like this:4342: because it is bad", match['grep_colon_numbers:colon_numbers.txt'].first[1])
307318
assert_equal(1, match.size)

0 commit comments

Comments
 (0)