Class: Git::CommandLine::Result

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) ⇒ Result

Create a Result object

Examples:

git_cmd = %w[git version]
status = instance_double(ProcessExecuter::Result)
stdout = "git version 2.39.1\n"
stderr = ""
result = Git::CommandLine::Result.new(git_cmd, status, stdout, stderr)

Parameters:

  • git_cmd (Array<String>)

    the git command that was executed

  • status (ProcessExecuter::Result)

    the process result object returned by ProcessExecuter.run or ProcessExecuter.run_with_capture. Responds to timed_out?, signaled?, and success?.

  • stdout (String)

    the processed stdout of the process

  • stderr (String)

    the processed stderr of the process



31
32
33
34
35
36
# File 'lib/git/command_line/result.rb', line 31

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::CommandLine::Result.new(git_cmd, nil, '', '')
result.git_cmd #=> ["git", "version"]

Returns:

  • (Array<String>)


49
50
51
# File 'lib/git/command_line/result.rb', line 49

def git_cmd
  @git_cmd
end

#statusProcessExecuter::Result (readonly)

The process result object returned by ProcessExecuter

In practice this is a ProcessExecuter::ResultWithCapture (from Capturing) or a ProcessExecuter::Result (from Streaming). Both respond to success?, timed_out?, and signaled?.

Examples:

status = instance_double(ProcessExecuter::Result, success?: true)
result = Git::CommandLine::Result.new(%w[git version], status, '', '')
result.status == status #=> true

Returns:

  • (ProcessExecuter::Result)


67
68
69
# File 'lib/git/command_line/result.rb', line 67

def status
  @status
end

#stderrString (readonly)

The error output of the process

Examples:

stderr = "Tag not found\n"
result = Git::CommandLine::Result.new([], nil, '', stderr)
result.stderr #=> "Tag not found\n"

Returns:

  • (String)


93
94
95
# File 'lib/git/command_line/result.rb', line 93

def stderr
  @stderr
end

#stdoutString (readonly)

The output of the process

Examples:

stdout = "git version 2.39.1\n"
result = Git::CommandLine::Result.new([], nil, stdout, '')
result.stdout #=> "git version 2.39.1\n"

Returns:

  • (String)


80
81
82
# File 'lib/git/command_line/result.rb', line 80

def stdout
  @stdout
end