Method: Git::Lib#cat_file_contents

Defined in:
lib/git/lib.rb

#cat_file_contents(object) ⇒ String Also known as: object_contents

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Output the contents or other properties of one or more objects.

Examples:

Get the contents of a file without a block

lib.cat_file_contents('README.md') # => "This is a README file\n"

Get the contents of a file with a block

lib.cat_file_contents('README.md') { |f| f.read } # => "This is a README file\n"

Parameters:

  • object (String)

    the object whose contents to return

Returns:

  • (String)

    the object contents

Raises:

  • (ArgumentError)

    if object is a string starting with a hyphen

See Also:



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/git/lib.rb', line 426

def cat_file_contents(object)
  assert_args_are_not_options('object', object)

  if block_given?
    Tempfile.create do |file|
      # If a block is given, write the output from the process to a temporary
      # file and then yield the file to the block
      #
      command('cat-file', '-p', object, out: file, err: file)
      file.rewind
      yield file
    end
  else
    # If a block is not given, return the file contents as a string
    command('cat-file', '-p', object)
  end
end