Class: Git::Commands::Grep Private
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
arguments block audited against
https://git-scm.com/docs/git-grep/2.53.0
Implements the git grep command
Searches for a pattern in the contents of tracked files within a repository tree.
Examples:
Typical usage
Typical usage
grep = Git::Commands::Grep.new(execution_context)
grep.call('HEAD', pattern: 'search')
grep.call('HEAD', pattern: 'SEARCH', ignore_case: true)
grep.call('HEAD', pattern: 'search', invert_match: true)
grep.call('HEAD', pattern: 'foo|bar', extended_regexp: true)
grep.call('HEAD', pattern: 'search', pathspec: 'lib/**')
See Also:
Instance Method Summary collapse
-
#call(*tree, **options) ⇒ Git::CommandLineResult
Execute the
git grepcommand.
Methods inherited from Base
allow_exit_status, arguments, #initialize, requires_git_version, skip_version_validation
Constructor Details
This class inherits a constructor from Git::Commands::Base
Instance Method Details
#call(*tree, **options) ⇒ Git::CommandLineResult
Execute the git grep command
Parameters:
-
tree
(Array<String>)
—
zero or more tree-ish references to search (e.g. commit SHAs, tags, or branch names); when omitted, git searches the working tree
-
options
(Hash)
—
command options
Options Hash (**options):
-
:text
(Boolean, nil)
— default:
nil
—
process binary files as if they were text
Alias: :a
-
:I
(Boolean, nil)
— default:
nil
—
do not match the pattern in binary files
-
:textconv
(Boolean, nil)
— default:
nil
—
honor textconv filter settings (
--textconv) -
:no_textconv
(Boolean, nil)
— default:
nil
—
suppress textconv filter processing (
--no-textconv) -
:ignore_case
(Boolean, nil)
— default:
nil
—
ignore case distinctions in both the pattern and the file contents
Alias: :i
-
:word_regexp
(Boolean, nil)
— default:
nil
—
match the pattern only at word boundary
Alias: :w
-
:invert_match
(Boolean, nil)
— default:
nil
—
select non-matching lines
Alias: :v
-
:h
(Boolean, nil)
— default:
nil
—
suppress the filename prefix for each match
-
:H
(Boolean, nil)
— default:
nil
—
print the filename for each match; overrides
:hgiven earlier -
:full_name
(Boolean, nil)
— default:
nil
—
output paths relative to the project top directory rather than the current directory
-
:extended_regexp
(Boolean, nil)
— default:
nil
—
use POSIX extended regular expressions for the pattern
Alias: :E
-
:basic_regexp
(Boolean, nil)
— default:
nil
—
use POSIX basic regular expressions for the pattern (the default regexp flavour)
Alias: :G
-
:perl_regexp
(Boolean, nil)
— default:
nil
—
use Perl-compatible regular expressions for the pattern
Alias: :P
-
:fixed_strings
(Boolean, nil)
— default:
nil
—
treat the pattern as a fixed string rather than a regular expression
Alias: :F
-
:line_number
(Boolean, nil)
— default:
nil
—
prefix each matching line with its line number within the file
Alias: :n
-
:column
(Boolean, nil)
— default:
nil
—
prefix the 1-indexed byte-offset of the first match from the start of the matching line
-
:files_with_matches
(Boolean, nil)
— default:
nil
—
show only the names of files that contain matches, not the matching lines
Aliases: :name_only, :l
-
:files_without_match
(Boolean, nil)
— default:
nil
—
show only the names of files that do not contain matches
Alias: :L
-
:null
(Boolean, nil)
— default:
nil
—
use NUL as the delimiter for pathnames in the output, printing them verbatim
Alias: :z
-
:only_matching
(Boolean, nil)
— default:
nil
—
print only the matched (non-empty) parts of a matching line, each on a separate output line
Alias: :o
-
:count
(Boolean, nil)
— default:
nil
—
show the number of matching lines per file instead of the matching lines themselves
Alias: :c
-
:all_match
(Boolean, nil)
— default:
nil
—
when using multiple
--orpatterns, limit matches to files that have lines matching all of them -
:quiet
(Boolean, nil)
— default:
nil
—
do not output matching lines; exit 0 when there is a match and non-zero when there is not
Alias: :q
-
:max_depth
(Integer, String)
— default:
nil
—
descend at most this many directory levels for each pathspec argument
-
:recursive
(Boolean, nil)
— default:
nil
—
recurse into subdirectories (same as
--max-depth=-1; this is the default)Alias: :r
-
:no_recursive
(Boolean, nil)
— default:
nil
—
do not recurse into subdirectories (
--no-recursive, equivalent to--max-depth=0) -
:color
(Boolean, String, nil)
— default:
nil
—
show colored matches
When
true, emits bare--color. Pass a string to emit--color=<when>(values:'always','never','auto'). -
:no_color
(Boolean, nil)
— default:
nil
—
turn off match highlighting, even when the configuration file gives the default to color output
-
:break
(Boolean, nil)
— default:
nil
—
print an empty line between matches from different files
-
:heading
(Boolean, nil)
— default:
nil
—
show the filename above the matches in that file instead of at the start of each shown line
-
:show_function
(Boolean, nil)
— default:
nil
—
show the nearest function name preceding each match
Alias: :p
-
:after_context
(Integer, String)
— default:
nil
—
show this many trailing lines after each match
Alias: :A
-
:before_context
(Integer, String)
— default:
nil
—
show this many leading lines before each match
Alias: :B
-
:context
(Integer, String)
— default:
nil
—
show this many leading and trailing lines around each match
Alias: :C
-
:function_context
(Boolean, nil)
— default:
nil
—
show the surrounding text from the previous function name up to the next
Alias: :W
-
:max_count
(Integer, String)
— default:
nil
—
limit the number of matches per file
Alias: :m
-
:threads
(Integer, String)
— default:
nil
—
number of grep worker threads to use
-
:f
(String, Array<String>)
— default:
nil
—
read patterns from a file, one per line; may be passed as an Array to supply multiple pattern files
-
:pattern
(String, Array<String>)
— default:
nil
—
the search pattern (required; must not be nil)
Pass a String for a simple pattern (emitted as
-e <pattern>). Pass an Array of raw CLI arguments for compound boolean expressions (e.g.['-e', 'foo', '--and', '-e', 'bar']). -
:recurse_submodules
(Boolean, nil)
— default:
nil
—
recursively search in each active, checked-out submodule
-
:parent_basename
(String)
— default:
nil
—
override the name used as a prefix for submodule output when used with
:recurse_submodules -
:exclude_standard
(Boolean, nil)
— default:
nil
—
honor the
.gitignoremechanism when searching untracked files (--exclude-standard) -
:no_exclude_standard
(Boolean, nil)
— default:
nil
—
do not honor the
.gitignoremechanism; also search ignored files (--no-exclude-standard); only useful with:untrackedor:no_index -
:cached
(Boolean, nil)
— default:
nil
—
search blobs registered in the index instead of tracked files in the working tree
-
:untracked
(Boolean, nil)
— default:
nil
—
search untracked files in addition to tracked files in the working tree
-
:no_index
(Boolean, nil)
— default:
nil
—
search files in the current directory without regard to whether it is managed by Git
-
:pathspec
(String, Array<String>)
— default:
nil
—
limit the search to files matching the given pathspec(s)
Multiple pathspecs may be passed as an Array. Appended to the command after
--.
Returns:
-
(Git::CommandLineResult)
—
the result of calling
git grepExit status 0 means matches were found; exit status 1 means no lines were selected (not an error).
Raises:
-
(ArgumentError)
—
if
:patternis missing or nil -
(ArgumentError)
—
if unsupported options are provided
-
(Git::FailedError)
—
if git exits outside the allowed range (exit code > 1)
|
|
# File 'lib/git/commands/grep.rb', line 115
|