class Git::Commands::CatFile::Raw
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 {CatFile::Batch}. For filter-processed content, use {CatFile::Filtered}.
@note ‘arguments` block audited against git-scm.com/docs/git-cat-file/2.53.0
@see git-scm.com/docs/git-cat-file git-cat-file documentation
@api private
Public Instance Methods
Source
# File lib/git/commands/cat_file/raw.rb, line 230 def call(*, **) warn_allow_unknown_type_deprecated(**) bound = args_definition.bind(*, **) validate_version!(bound.execution_options) 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
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.
@overload call(object, e: true, **options)
Check whether an object exists @param object [String] object name (SHA, ref, `HEAD`, treeish path, etc.) @param e [Boolean] enable existence-check mode @param options [Hash] command options @option options [Boolean, nil] :allow_unknown_type (nil) pass `--allow-unknown-type` through to git, which rejects it in this mode on git 2.28-2.49 and accepts it as a no-op on git 2.50 and later Deprecated and removed in v6.0.0; passing it emits a deprecation warning. @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`) @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`) @return [Git::CommandLine::Result] the result of calling `git cat-file` Exit status 0 means the object exists; exit status 1 means it does not @raise [ArgumentError] if unsupported options are provided @raise [Git::FailedError] if git exits with a status other than 0 or 1
@overload call(object, t: true, **options)
Print the object type @param object [String] object name @param t [Boolean] enable type-query mode @param options [Hash] command options @option options [Boolean, nil] :allow_unknown_type (nil) allow querying broken or corrupt objects of unknown type on git 2.28-2.49 Deprecated and removed in v6.0.0; passing it emits a deprecation warning. Git 2.50 removed the unknown-type feature and accepts this flag as a no-op. @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`) @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`) @return [Git::CommandLine::Result] the result of calling `git cat-file` Stdout contains the object type string @raise [ArgumentError] if unsupported options are provided @raise [Git::FailedError] if the object does not exist
@overload call(object, s: true, **options)
Print the object size in bytes @param object [String] object name @param s [Boolean] enable size-query mode @param options [Hash] command options @option options [Boolean, nil] :allow_unknown_type (nil) allow querying broken or corrupt objects of unknown type on git 2.28-2.49 Deprecated and removed in v6.0.0; passing it emits a deprecation warning. Git 2.50 removed the unknown-type feature and accepts this flag as a no-op. @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`) @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`) @return [Git::CommandLine::Result] the result of calling `git cat-file` Stdout contains the object size as a decimal string @raise [ArgumentError] if unsupported options are provided @raise [Git::FailedError] if the object does not exist
@overload call(object, p: true, **options)
Pretty-print the object content @param object [String] object name @param p [Boolean] enable pretty-print mode @param options [Hash] command options @option options [Boolean, nil] :allow_unknown_type (nil) pass `--allow-unknown-type` through to git, which rejects it in this mode on git 2.28-2.49 and accepts it as a no-op on git 2.50 and later Deprecated and removed in v6.0.0; passing it emits a deprecation warning. @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`) @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`) @return [Git::CommandLine::Result] the result of calling `git cat-file` Stdout contains the formatted object content @raise [ArgumentError] if unsupported options are provided @raise [Git::FailedError] if the object does not exist
@overload call(type, object, **options)
Print the raw content, validating the object is of the given type @param type [String] expected object type — `commit`, `tree`, `blob`, or `tag` @param object [String] object name @param options [Hash] command options @option options [Boolean, nil] :allow_unknown_type (nil) pass `--allow-unknown-type` through to git, which rejects it in this mode on git 2.28-2.49 and accepts it as a no-op on git 2.50 and later Deprecated and removed in v6.0.0; passing it emits a deprecation warning. @option options [Boolean, nil] :use_mailmap (nil) remap identities via mailmap (`--use-mailmap`) @option options [Boolean, nil] :no_use_mailmap (nil) suppress mailmap remapping (`--no-use-mailmap`) @return [Git::CommandLine::Result] the result of calling `git cat-file` Stdout contains the raw object content @raise [ArgumentError] if unsupported options are provided @raise [Git::FailedError] if the object does not exist or is not of the given type @option options [Numeric, nil] :timeout (nil) abort the command after this many seconds
Private Instance Methods
Source
# File lib/git/commands/cat_file/raw.rb, line 259 def warn_allow_unknown_type_deprecated(**options) return unless options.key?(:allow_unknown_type) Git::Deprecation.warn( 'The allow_unknown_type option of Git::Commands::CatFile::Raw is deprecated ' \ 'and will be removed in v6.0.0. Git 2.50 removed the unknown-type feature ' \ 'and accepts --allow-unknown-type as a no-op.' ) end
Emit the deprecation warning when the ‘allow_unknown_type` keyword is passed
Keys on the keyword being present, whatever its value: ‘false` and `nil` suppress the flag but still name a deprecated option.
@param options [Hash] the keyword arguments passed to {#call}
@option options [Boolean, nil] :allow_unknown_type the deprecated option;
any value, including `false` and `nil`, triggers the warning
@return [void]