Class: Git::Commands::RevParse Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/rev_parse.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-rev-parse/2.53.0

Implements the git rev-parse command

Picks out and massages parameters for other git commands. Most commonly used to resolve a revision specifier (branch name, tag, abbreviated SHA) to its full object name. Also provides repository metadata queries and argument classification for porcelain scripts.

The --parseopt and --sq-quote operation modes are excluded because they require stdin interaction or provide no value in a Ruby library.

Examples:

Resolve HEAD to its full SHA

rev_parse = Git::Commands::RevParse.new(execution_context)
result = rev_parse.call('HEAD', verify: true)

Query the repository top-level directory

rev_parse = Git::Commands::RevParse.new(execution_context)
result = rev_parse.call(show_toplevel: true)

List all branch refs

rev_parse = Git::Commands::RevParse.new(execution_context)
result = rev_parse.call(branches: true)

See Also:

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(*args, **options) ⇒ Git::CommandLineResult

Execute the git rev-parse command

Parameters:

  • args (Array<String>)

    zero or more revision specifiers, object names, or file paths to parse. Include '--' to separate verified arguments from those echoed back without verification, e.g. call('HEAD', '--', 'file.txt').

  • options (Hash)

    command options

Options Hash (**options):

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

    do not output flags and parameters not meant for git rev-list

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

    do not output flags and parameters meant for git rev-list

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

    do not output non-flag parameters (--flags)

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

    do not output flag parameters (--no-flags)

  • :default (String) — default: nil

    use this value if no parameter is given by the user

  • :prefix (String) — default: nil

    behave as if invoked from this subdirectory of the working tree

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

    verify that exactly one parameter is provided and that it can be resolved to an object

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

    do not output an error message if the first argument is not a valid object name; exit with non-zero status silently

    Only meaningful with :verify.

    Alias: :q

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

    output a single line properly quoted for shell consumption

  • :short (Boolean, String, nil) — default: nil

    shorten the object name to a unique prefix

    When true, emits --short (git default length). When a String, emits --short=<length>.

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

    prefix object names with ^ and strip ^ from names that already have one

  • :abbrev_ref (Boolean, String, nil) — default: nil

    output a non-ambiguous short name of the object

    When true, emits --abbrev-ref. When a String ("strict" or "loose"), emits --abbrev-ref=<mode>.

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

    output object names in a form as close to the original input as possible

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

    like :symbolic but omit non-ref input and show full refnames

  • :output_object_format (String) — default: nil

    translate object identifiers to the specified format

    Accepted values are "sha1", "sha256", and "storage".

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

    show all refs found in refs/

  • :branches (Boolean, String, nil) — default: nil

    show all branches

    When true, emits --branches. When a String, emits --branches=<pattern>.

  • :tags (Boolean, String, nil) — default: nil

    show all tags

    When true, emits --tags. When a String, emits --tags=<pattern>.

  • :remotes (Boolean, String, nil) — default: nil

    show all remote-tracking branches

    When true, emits --remotes. When a String, emits --remotes=<pattern>.

  • :glob (String) — default: nil

    show all refs matching the shell glob pattern

  • :exclude (String, Array<String>) — default: nil

    exclude refs matching the glob pattern from the next --all, --branches, --tags, --remotes, or --glob

  • :disambiguate (String) — default: nil

    show every object whose name begins with the given prefix

  • :exclude_hidden (String) — default: nil

    do not include refs that would be hidden by the specified protocol

    Accepted values are "fetch", "receive", and "uploadpack". Affects the next --all or --glob and is cleared after processing them.

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

    list the GIT_* environment variables local to the repository

  • :path_format (String, Array<String>) — default: nil

    control whether paths output by subsequent path-related options are absolute or relative

    Accepted values are "absolute" and "relative". May be given multiple times; each instance affects the arguments that follow it on the command line.

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

    show $GIT_DIR if defined, otherwise show the path to the .git directory

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

    like :git_dir but always output the canonicalized absolute path

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

    show $GIT_COMMON_DIR if defined, else $GIT_DIR

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

    print "true" when the current working directory is below the repository directory, "false" otherwise

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

    print "true" when inside the work tree, "false" otherwise

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

    print "true" when the repository is bare, "false" otherwise

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

    print "true" when the repository is shallow, "false" otherwise

  • :resolve_git_dir (String) — default: nil

    check if the given path is a valid repository or a gitfile that points at one and print the location

  • :git_path (String) — default: nil

    resolve "$GIT_DIR/<path>" taking relocation variables into account

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

    show the path of the top-level directory relative to the current directory

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

    show the path of the current directory relative to the top-level directory

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

    show the absolute path of the top-level directory of the working tree

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

    show the absolute path of the root of the superproject's working tree if the current repository is a submodule

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

    show the path to the shared index file in split index mode

  • :show_object_format (Boolean, String, nil) — default: nil

    show the object format (hash algorithm) used for the repository

    When true, emits --show-object-format (defaults to "storage"). When a String ("storage", "input", or "output"), emits --show-object-format=<mode>.

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

    show the reference storage format used for the repository

  • :since (String) — default: nil

    parse the date string and output the corresponding --max-age= parameter

    Alias: :after

  • :until (String) — default: nil

    parse the date string and output the corresponding --min-age= parameter

    Alias: :before

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (Git::FailedError)

    if git exits with a non-zero status



# File 'lib/git/commands/rev_parse.rb', line 104