Module: Datadog::CI::Git::CLI

Defined in:
lib/datadog/ci/git/cli.rb

Defined Under Namespace

Classes: GitCommandExecutionError

Constant Summary collapse

UNSHALLOW_TIMEOUT =

Timeout constants for git commands (in seconds) These values were set based on internal telemetry

500
LONG_TIMEOUT =
30
SHORT_TIMEOUT =
3

Class Method Summary collapse

Class Method Details

.exec_git_command(cmd, stdin: nil, timeout: SHORT_TIMEOUT) ⇒ String?

Execute a git command with optional stdin input and timeout

Parameters:

  • cmd (Array<String>)

    The git command as an array of strings

  • stdin (String, nil) (defaults to: nil)

    Optional stdin data to pass to the command

  • timeout (Integer) (defaults to: SHORT_TIMEOUT)

    Timeout in seconds for the command execution

Returns:

  • (String, nil)

    The command output, or nil if the output is empty

Raises:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/datadog/ci/git/cli.rb', line 33

def self.exec_git_command(cmd, stdin: nil, timeout: SHORT_TIMEOUT)
  # @type var out: String
  # @type var status: Process::Status?
  out, status = Utils::Command.exec_command(["git"] + cmd, stdin_data: stdin, timeout: timeout)

  if status.nil? || !status.success?
    # Convert command to string representation for error message
    cmd_str = cmd.join(" ")
    raise GitCommandExecutionError.new(
      "Failed to run git command [#{cmd_str}] with input [#{stdin}] and output [#{out}]. Status: #{status}",
      output: out,
      command: cmd_str,
      status: status
    )
  end

  return nil if out.empty?

  out
end