Class: Git::CommandLineResult

Inherits:
Object
  • Object
show all
Defined in:
lib/git/command_line_result.rb

Overview

The result of running a git command

This object stores the Git command executed and its status, stdout, and stderr.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git_cmd, status, stdout, stderr) ⇒ CommandLineResult

Create a CommandLineResult object

Examples:

`true`
git_cmd = %w[git version]
status = $?
stdout = "git version 2.39.1\n"
stderr = ""
result = Git::CommandLineResult.new(git_cmd, status, stdout, stderr)

Parameters:

  • git_cmd (Array<String>)

    the git command that was executed

  • status (ProcessExecuter::ResultWithCapture)

    the status of the process

  • stdout (String)

    the processed stdout of the process

  • stderr (String)

    the processed stderr of the process



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/git/command_line_result.rb', line 26

def initialize(git_cmd, status, stdout, stderr)
  @git_cmd = git_cmd
  @status = status
  @stdout = stdout
  @stderr = stderr

  # ProcessExecuter::ResultWithCapture changed the timeout? method to timed_out?
  # in version 4.x. This is a compatibility layer to maintain the old method name
  # for backward compatibility.
  #
  status.define_singleton_method(:timeout?) { timed_out? }
end

Instance Attribute Details

#git_cmdArray<String> (readonly)

The git command that was executed

Examples:

git_cmd = %w[git version]
result = Git::CommandLineResult.new(git_cmd, $?, "", "")
result.git_cmd #=> ["git", "version"]

Returns:

  • (Array<String>)


50
51
52
# File 'lib/git/command_line_result.rb', line 50

def git_cmd
  @git_cmd
end

#statusProcess::Status (readonly)

The status of the process

Examples:

`true`
status = $?
result = Git::CommandLineResult.new(status, "", "")
result.status #=> #<Process::Status: pid 87859 exit 0>

Returns:

  • (Process::Status)


64
65
66
# File 'lib/git/command_line_result.rb', line 64

def status
  @status
end

#stderrString (readonly)

The error output of the process

Examples:

stderr = "Tag not found\n"
result = Git::CommandLineResult.new($?, "", stderr)
result.stderr #=> "Tag not found\n"

Returns:

  • (String)


90
91
92
# File 'lib/git/command_line_result.rb', line 90

def stderr
  @stderr
end

#stdoutString (readonly)

The output of the process

Examples:

stdout = "git version 2.39.1\n"
result = Git::CommandLineResult.new($?, stdout, "")
result.stdout #=> "git version 2.39.1\n"

Returns:

  • (String)


77
78
79
# File 'lib/git/command_line_result.rb', line 77

def stdout
  @stdout
end