Class: Git::Commands::ShowRef::Exists Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/show_ref/exists.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:

Requires git 2.43 or later

Earlier versions do not recognise the --exists flag and will exit non-zero with an "unknown option" error.

Note:

arguments block audited against https://git-scm.com/docs/git-show-ref/2.53.0

Checks whether a single ref exists via git show-ref --exists

Returns without raising for three exit-status outcomes:

  • exit 0 — the ref exists in the local repository
  • exit 2 — the ref does not exist (a normal result for an existence check)
  • exit 1 — a lookup error occurred (e.g. malformed ref name)

Callers inspect result.status.exitstatus to distinguish the three states. Unlike Verify, this mode never prints any output.

For standard ref listing, use List. For strict per-ref verification with output, use Verify. For stdin-based filtering, use ExcludeExisting.

Examples:

Check whether a branch exists

cmd = Git::Commands::ShowRef::Exists.new(execution_context)
result = cmd.call('refs/heads/main')
result.status.exitstatus  # => 0 (exists) or 2 (not found)

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

Execute git show-ref --exists to check whether a ref exists

Parameters:

  • ref (String)

    the fully-qualified ref name to check (e.g. "refs/heads/main")

  • options (Hash)

    command options

Options Hash (**options):

  • :timeout (Numeric) — default: nil

    abort the command after this many seconds

Returns:

Raises:

  • (ArgumentError)

    if no ref is provided

  • (Git::FailedError)

    if git exits with a status outside 0..2



# File 'lib/git/commands/show_ref/exists.rb', line 54