Class: Git::Commands::SymbolicRef::Read Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/symbolic_ref/read.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-symbolic-ref/2.53.0

Reads the target of a symbolic ref via git symbolic-ref

Given one argument, reads which branch head the given symbolic ref refers to and outputs its path, relative to the .git/ directory.

Exits with status 0 if the contents were printed correctly, or status 1 if the requested name is not a symbolic ref (e.g. a detached HEAD). When quiet: true, exit status 1 is silent (no error message on stderr).

Examples:

Read current HEAD

cmd = Git::Commands::SymbolicRef::Read.new(execution_context)
result = cmd.call('HEAD')
result.stdout  # => "refs/heads/main"

Read HEAD with shortened output

cmd = Git::Commands::SymbolicRef::Read.new(execution_context)
result = cmd.call('HEAD', short: true)
result.stdout  # => "main"

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

Execute the git symbolic-ref command to read a symbolic ref

Parameters:

  • name (String)

    the symbolic ref name to read (e.g. HEAD)

  • options (Hash)

    command options

Options Hash (**options):

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

    suppress error message when the name is not a symbolic ref

    Alias: :q

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

    shorten the ref output (e.g. refs/heads/mainmain)

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

    follow chain of symbolic refs until result no longer points at a symbolic ref (--recurse)

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

    stop after a single level of dereferencing (--no-recurse)

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (ArgumentError)

    if the name operand is missing

  • (Git::FailedError)

    if git exits outside the allowed range (exit code > 1)



# File 'lib/git/commands/symbolic_ref/read.rb', line 59