Class: RubyGit::CommandLine::Runner
- Inherits:
-
Object
- Object
- RubyGit::CommandLine::Runner
- Defined in:
- lib/ruby_git/command_line/runner.rb
Overview
Runs the git command line and returns the result
Instance Attribute Summary collapse
-
#binary_path ⇒ String
readonly
The path to the command line binary to run.
-
#env ⇒ Hash<String, String>
readonly
Variables to set (or unset) in the git command's environment.
-
#global_options ⇒ Array<String>
readonly
The global options to pass to git.
-
#logger ⇒ Logger
readonly
The logger to use for logging git commands and results.
Instance Method Summary collapse
-
#call(*args, **options_hash) ⇒ RubyGit::CommandLine::Result
Execute a git command, wait for it to finish, and return the result.
-
#initialize(env, binary_path, global_options, logger) ⇒ Runner
constructor
Create a an object to run git commands via the command line.
Constructor Details
#initialize(env, binary_path, global_options, logger) ⇒ Runner
Create a an object to run git commands via the command line
30 31 32 33 34 35 |
# File 'lib/ruby_git/command_line/runner.rb', line 30 def initialize(env, binary_path, , logger) @env = env @binary_path = binary_path = @logger = logger end |
Instance Attribute Details
#binary_path ⇒ String (readonly)
The path to the command line binary to run
64 65 66 |
# File 'lib/ruby_git/command_line/runner.rb', line 64 def binary_path @binary_path end |
#env ⇒ Hash<String, String> (readonly)
Variables to set (or unset) in the git command's environment
51 52 53 |
# File 'lib/ruby_git/command_line/runner.rb', line 51 def env @env end |
#global_options ⇒ Array<String> (readonly)
The global options to pass to git
These are options that are passed to git before the command name and
arguments. For example, in git --git-dir /path/to/git/dir version, the
global options are %w[--git-dir /path/to/git/dir].
83 84 85 |
# File 'lib/ruby_git/command_line/runner.rb', line 83 def end |
#logger ⇒ Logger (readonly)
The logger to use for logging git commands and results
98 99 100 |
# File 'lib/ruby_git/command_line/runner.rb', line 98 def logger @logger end |
Instance Method Details
#call(*args, **options_hash) ⇒ RubyGit::CommandLine::Result
Execute a git command, wait for it to finish, and return the result
NORMALIZATION
The command output is returned as a Unicde 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 trys 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 RubyGit::CommandLine#run
to enable it. Normalization will only be performed on stdout and only if the out:` option
is nil or is a StringIO object. If the out: option is set to a file or other IO object,
the normalize option will be ignored.
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/ruby_git/command_line/runner.rb', line 165 def call(*args, **) [:raise_errors] = false = RubyGit::CommandLine::Options.new(logger: logger, **) begin result = run_with_chdir([env, *build_git_cmd(args)], ) rescue ProcessExecuter::ProcessIOError => e raise RubyGit::ProcessIOError.new(e.), cause: e.exception.cause end process_result(result) end |