Class: Git::CommandLine::Capturing
- Defined in:
- lib/git/command_line/capturing.rb
Overview
Executes a git command and captures both stdout and stderr in memory
Capturing is the buffering strategy: it calls
ProcessExecuter.run_with_capture, which reads all subprocess output into
String objects before returning. Use this class (via
Lib#command_capturing) for the vast majority of git subcommands whose
output fits comfortably in memory.
Streaming is the complementary strategy for commands
(such as cat-file -p <blob>) whose stdout may be too large to buffer.
Constant Summary collapse
- RUN_OPTION_DEFAULTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default options accepted by #run
{ in: nil, out: nil, err: nil, chdir: nil, timeout: nil, raise_on_failure: true, env: {}, normalize: false, chomp: false, merge: false }.freeze
Instance Attribute Summary
Attributes inherited from Base
#binary_path, #env, #global_opts, #logger
Instance Method Summary collapse
-
#run(**options_hash) ⇒ Git::CommandLineResult
Execute a git command, capture stdout and stderr, and return the result.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Git::CommandLine::Base
Instance Method Details
#run(**options_hash) ⇒ Git::CommandLineResult
Execute a git command, capture stdout and stderr, and return the result
Non-option command-line arguments to pass to git. If you collect the arguments in an array, splat the array into the parameter list.
NORMALIZATION
The command output is returned as a Unicode string containing the binary output from the command. If the binary output is not valid UTF-8, the output will cause problems because the encoding will be invalid.
Normalization is a process that tries to convert the binary output to a
valid UTF-8 string. It uses the rchardet gem to detect the encoding of
the binary output and then converts it to UTF-8.
Normalization is not enabled by default. Pass normalize: true to enable
it. When enabled, normalization is applied to both stdout and stderr in
the returned result object, regardless of the out: or err: options.
Only the captured in-memory strings are normalized; any external IO you
provide will receive the raw subprocess output.
156 157 158 159 160 161 |
# File 'lib/git/command_line/capturing.rb', line 156 def run(*, **) = (RUN_OPTION_DEFAULTS, ) result = execute(*, **) process_result(result, ) end |