Module: Git::CommandLine

Defined in:
lib/git/command_line.rb,
lib/git/command_line/base.rb,
lib/git/command_line/result.rb,
lib/git/command_line/capturing.rb,
lib/git/command_line/streaming.rb

Overview

Namespace module for git command-line execution strategies

This module groups the classes responsible for invoking git subprocesses and handling their output. Choose a concrete class based on your buffering needs:

  • Capturing — buffers stdout and stderr in memory. Use this for the vast majority of git commands whose output fits in memory.

  • Streaming — streams stdout to a caller-supplied IO. Use this for commands (e.g. cat-file -p <blob>) whose output may be too large to buffer.

Both classes inherit from Base and are instantiated via factory helpers in Lib: Lib#command_capturing and Lib#command_streaming.

Results are returned as Result objects (also accessible as CommandLineResult for backward compatibility).

Examples:

Buffered command via Git::CommandLine::Capturing

cli = Git::CommandLine::Capturing.new(
  {}, '/usr/bin/git', [], Logger.new(nil)
)
result = cli.run('version')
result.stdout #=> "git version 2.39.1\n"

Streaming command via Git::CommandLine::Streaming

cli = Git::CommandLine::Streaming.new(
  {}, '/usr/bin/git', [], Logger.new(nil)
)
File.open('/tmp/blob', 'wb') do |f|
  cli.run('cat-file', 'blob', sha, out: f)
end

See Also:

Defined Under Namespace

Classes: Base, Capturing, Result, Streaming