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 (Process::Status)

    the status of the process

  • stdout (String)

    the output of the process

  • stderr (String)

    the error output of the process



26
27
28
29
30
31
# 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
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>)


44
45
46
# File 'lib/git/command_line_result.rb', line 44

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)


58
59
60
# File 'lib/git/command_line_result.rb', line 58

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)


84
85
86
# File 'lib/git/command_line_result.rb', line 84

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)


71
72
73
# File 'lib/git/command_line_result.rb', line 71

def stdout
  @stdout
end