Class: Git::Commands::CatFile::Raw Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/cat_file/raw.rb

Overview

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

Note:

arguments block audited against https://git-scm.com/docs/git-cat-file/2.53.0

Queries a single git object by name passed as a CLI argument

Runs git cat-file in non-batch mode. Exactly one mode flag or a <type> operand must be supplied:

  • -e — exit 0 if the object exists and is valid, exit 1 otherwise; no output is written to stdout
  • -t — print the object type (blob, tree, commit, or tag)
  • -s — print the object size in bytes
  • -p — pretty-print the object content (format varies by type)
  • <type> — print the raw content after validating the object is of the given type (or trivially dereferenceable to it)

For queries across multiple objects, use Batch. For filter-processed content, use Filtered.

Instance Method Summary collapse

Methods inherited from Base

allow_exit_status, arguments, #initialize, requires_git_version, skip_version_validation

Constructor Details

This class inherits a constructor from Git::Commands::Base

Instance Method Details

#call(object, e: true, **options) ⇒ Git::CommandLineResult #call(object, t: true, **options) ⇒ Git::CommandLineResult #call(object, s: true, **options) ⇒ Git::CommandLineResult #call(object, p: true, **options) ⇒ Git::CommandLineResult #call(type, object, **options) ⇒ Git::CommandLineResult

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.

Execute git cat-file for a single object.

Exactly one mode must be selected: pass one of e: true, p: true, t: true, s: true, or a positional type argument.

Overloads:

  • #call(object, e: true, **options) ⇒ Git::CommandLineResult

    Check whether an object exists

    Parameters:

    • object (String)

      object name (SHA, ref, HEAD, treeish path, etc.)

    • e (Boolean) (defaults to: true)

      enable existence-check mode

    • options (Hash)

      command options

    Options Hash (**options):

    • :use_mailmap (Boolean, nil) — default: nil

      remap identities via mailmap (--use-mailmap)

    • :no_use_mailmap (Boolean, nil) — default: nil

      suppress mailmap remapping (--no-use-mailmap)

    Returns:

    • (Git::CommandLineResult)

      the result of calling git cat-file

      Exit status 0 means the object exists; exit status 1 means it does not

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if git exits with a status other than 0 or 1

  • #call(object, t: true, **options) ⇒ Git::CommandLineResult

    Print the object type

    Parameters:

    • object (String)

      object name

    • t (Boolean) (defaults to: true)

      enable type-query mode

    • options (Hash)

      command options

    Options Hash (**options):

    • :allow_unknown_type (Boolean, nil) — default: nil

      allow querying broken or corrupt objects of unknown type

    • :use_mailmap (Boolean, nil) — default: nil

      remap identities via mailmap (--use-mailmap)

    • :no_use_mailmap (Boolean, nil) — default: nil

      suppress mailmap remapping (--no-use-mailmap)

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if the object does not exist

  • #call(object, s: true, **options) ⇒ Git::CommandLineResult

    Print the object size in bytes

    Parameters:

    • object (String)

      object name

    • s (Boolean) (defaults to: true)

      enable size-query mode

    • options (Hash)

      command options

    Options Hash (**options):

    • :allow_unknown_type (Boolean, nil) — default: nil

      allow querying broken or corrupt objects of unknown type

    • :use_mailmap (Boolean, nil) — default: nil

      remap identities via mailmap (--use-mailmap)

    • :no_use_mailmap (Boolean, nil) — default: nil

      suppress mailmap remapping (--no-use-mailmap)

    Returns:

    • (Git::CommandLineResult)

      the result of calling git cat-file

      Stdout contains the object size as a decimal string

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if the object does not exist

  • #call(object, p: true, **options) ⇒ Git::CommandLineResult

    Pretty-print the object content

    Parameters:

    • object (String)

      object name

    • p (Boolean) (defaults to: true)

      enable pretty-print mode

    • options (Hash)

      command options

    Options Hash (**options):

    • :use_mailmap (Boolean, nil) — default: nil

      remap identities via mailmap (--use-mailmap)

    • :no_use_mailmap (Boolean, nil) — default: nil

      suppress mailmap remapping (--no-use-mailmap)

    Returns:

    • (Git::CommandLineResult)

      the result of calling git cat-file

      Stdout contains the formatted object content

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if the object does not exist

  • #call(type, object, **options) ⇒ Git::CommandLineResult

    Print the raw content, validating the object is of the given type

    Parameters:

    • type (String)

      expected object type — commit, tree, blob, or tag

    • object (String)

      object name

    • options (Hash)

      command options

    Options Hash (**options):

    • :use_mailmap (Boolean, nil) — default: nil

      remap identities via mailmap (--use-mailmap)

    • :no_use_mailmap (Boolean, nil) — default: nil

      suppress mailmap remapping (--no-use-mailmap)

    Returns:

    Raises:

    • (ArgumentError)

      if unsupported options are provided

    • (Git::FailedError)

      if the object does not exist or is not of the given type

Raises:



194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/git/commands/cat_file/raw.rb', line 194

def call(*, **)
  bound = args_definition.bind(*, **)
  validate_version!
  result = execute_command(bound)

  # `-e` treats exit 1 as a meaningful result (object not found), but any other
  # non-zero exit (e.g. 128 for a corrupt object database) is still a failure.
  # All other modes treat every non-zero exit as a failure.
  allowed = result.status.success? || (bound.e? && result.status.exitstatus == 1)
  raise Git::FailedError, result unless allowed

  result
end