Class: Git::Commands::UpdateRef::Update Private

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

Updates a ref to point to a new object via git update-ref

Stores <newvalue> in <ref>, optionally verifying that the current value matches <oldvalue> before performing the update. Follows symbolic refs by default unless no_deref: true is given.

Examples:

Update a branch ref

cmd = Git::Commands::UpdateRef::Update.new(execution_context)
cmd.call('refs/heads/main', 'abc1234')

Update with old-value verification

cmd = Git::Commands::UpdateRef::Update.new(execution_context)
cmd.call('refs/heads/main', 'newsha', 'oldsha')

Update with a reflog message

cmd = Git::Commands::UpdateRef::Update.new(execution_context)
cmd.call('refs/heads/main', 'abc1234', m: 'reset to upstream')

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, newvalue, oldvalue = nil, **options) ⇒ Git::CommandLineResult

Execute the git update-ref command

Parameters:

  • ref (String)

    the ref to update (e.g. refs/heads/main)

  • newvalue (String)

    the new object name to store

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

    (nil) expected current value of the ref

    When provided, the update is rejected unless the ref currently points to this object. Use 40 "0" characters or an empty string to assert the ref does not yet exist.

  • options (Hash)

    command options

Options Hash (**options):

  • :m (String) — default: nil

    a reflog message for the update

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

    overwrite the ref itself rather than following symbolic refs

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

    create a reflog even if one would not ordinarily be created

  • :timeout (Numeric) — default: nil

    abort the command after this many seconds

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (ArgumentError)

    if the ref or newvalue operand is missing

  • (Git::FailedError)

    if git exits with a non-zero exit status



# File 'lib/git/commands/update_ref/update.rb', line 63