Class: Git::Commands::LsRemote Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/ls_remote.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-ls-remote/2.53.0

Implements the git ls-remote command

Lists references available in a remote repository along with the associated commit IDs. Can be used to detect changes in a remote repository without cloning or fetching.

Examples:

List all refs in a remote

ls_remote = Git::Commands::LsRemote.new(execution_context)
ls_remote.call('origin')

List only branches and tags

ls_remote = Git::Commands::LsRemote.new(execution_context)
ls_remote.call('origin', branches: true, tags: true)

List only refs (no symbolic refs like HEAD)

ls_remote = Git::Commands::LsRemote.new(execution_context)
ls_remote.call('origin', refs: true)

Filter by pattern

ls_remote = Git::Commands::LsRemote.new(execution_context)
ls_remote.call('origin', 'refs/heads/main')

Detect the default branch of a remote

ls_remote = Git::Commands::LsRemote.new(execution_context)
ls_remote.call('origin', 'HEAD', symref: 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(repository = nil, *patterns, **options) ⇒ Git::CommandLineResult

Execute the git ls-remote command

Parameters:

  • repository (String, nil) (defaults to: nil)

    The remote name or URL to query

    When nil, git uses the remote inferred from the current branch's tracking configuration, or "origin" if no tracking remote is set.

  • patterns (Array<String>)

    One or more ref patterns to filter results

    When omitted, all references (after filtering via --branches, --tags, --refs) are shown. When specified, only refs matching one or more patterns are displayed.

  • options (Hash)

    command options

Options Hash (**options):

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

    limit output to refs under refs/heads/

    Alias: :b

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

    limit output to refs under refs/heads/

    Deprecated: use :branches instead. Kept for backward compatibility with older git versions where --heads is the only supported flag.

    Alias: :h

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

    limit output to refs under refs/tags/

    Alias: :t

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

    exclude peeled tags and pseudorefs like HEAD from the output

  • :upload_pack (String) — default: nil

    full path to git-upload-pack on the remote host

    Useful when accessing repositories via SSH where the daemon does not use the PATH configured by the user.

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

    do not print the remote URL to stderr

    Alias: :q

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

    exit with status 2 when no matching refs are found in the remote repository

    Without this option, the command exits 0 whenever it successfully communicates with the remote, even if no refs match.

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

    expand and print the remote URL (respecting url.<base>.insteadOf config) and exit without contacting the remote

  • :sort (String) — default: nil

    sort output by the given key

    Prefix - for descending order. Supports "version:refname" or "v:refname". See git for-each-ref for sort key documentation.

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

    show the underlying ref pointed to by symbolic refs

    The upload-pack protocol currently surfaces only the HEAD symref, so that is typically the only symref shown.

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

    transmit a string to the server when communicating using protocol version 2

    The string must not contain NUL or LF characters. Repeatable by passing an Array. Alias: :o

  • :timeout (Numeric) — default: nil

    execution timeout in seconds

Returns:

Raises:



# File 'lib/git/commands/ls_remote.rb', line 74