Class: Git::CommandLine
- Inherits:
-
Object
- Object
- Git::CommandLine
- Defined in:
- lib/git/command_line.rb
Overview
Runs a git command 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_opts ⇒ 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
-
#initialize(env, binary_path, global_opts, logger) ⇒ CommandLine
constructor
Create a Git::CommandLine object.
-
#run(*args, out:, err:, normalize:, chomp:, merge:, chdir: nil, timeout: nil) ⇒ Git::CommandLineResult
Execute a git command, wait for it to finish, and return the result.
Constructor Details
#initialize(env, binary_path, global_opts, logger) ⇒ CommandLine
Create a Git::CommandLine object
28 29 30 31 32 33 |
# File 'lib/git/command_line.rb', line 28 def initialize(env, binary_path, global_opts, logger) @env = env @binary_path = binary_path @global_opts = global_opts @logger = logger end |
Instance Attribute Details
#binary_path ⇒ String (readonly)
The path to the command line binary to run
62 63 64 |
# File 'lib/git/command_line.rb', line 62 def binary_path @binary_path end |
#env ⇒ Hash<String, String> (readonly)
Variables to set (or unset) in the git command's environment
49 50 51 |
# File 'lib/git/command_line.rb', line 49 def env @env end |
#global_opts ⇒ 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].
81 82 83 |
# File 'lib/git/command_line.rb', line 81 def global_opts @global_opts end |
#logger ⇒ Logger (readonly)
The logger to use for logging git commands and results
96 97 98 |
# File 'lib/git/command_line.rb', line 96 def logger @logger end |
Instance Method Details
#run(*args, out:, err:, normalize:, chomp:, merge:, chdir: nil, timeout: nil) ⇒ Git::CommandLineResult
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 Git::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.
192 193 194 195 196 197 198 199 |
# File 'lib/git/command_line.rb', line 192 def run(*args, out:, err:, normalize:, chomp:, merge:, chdir: nil, timeout: nil) git_cmd = build_git_cmd(args) out ||= StringIO.new err ||= (merge ? out : StringIO.new) status = execute(git_cmd, out, err, chdir: (chdir || :not_set), timeout: timeout) process_result(git_cmd, status, out, err, normalize, chomp, timeout) end |