Class: Git::Commands::UpdateRef::Batch Private

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

Performs batch ref updates via the git update-ref --stdin protocol

Reads update/create/delete/verify instructions from stdin. By default all modifications are applied atomically — either all succeed or none do. Pass batch_updates: true to switch to non-atomic mode, where each instruction is applied independently and individual failures are reported without aborting the remaining updates (requires git 2.47+).

This is the batch counterpart to the single-ref Update and Delete commands.

Instructions are newline-delimited by default; pass z: true to switch to NUL-delimited format. See the git-update-ref documentation for the full instruction grammar.

Examples:

Atomically update two refs

cmd = Git::Commands::UpdateRef::Batch.new(execution_context)
cmd.call(
  'update refs/heads/main newsha oldsha',
  'delete refs/heads/old-branch'
)

NUL-delimited instructions

cmd = Git::Commands::UpdateRef::Batch.new(execution_context)
cmd.call("update refs/heads/main\0newsha\0oldsha", z: true)

Non-atomic batch (independent failures)

cmd = Git::Commands::UpdateRef::Batch.new(execution_context)
cmd.call(
  'update refs/heads/main newsha oldsha',
  'delete refs/heads/old-branch',
  batch_updates: 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(*instructions, **options) ⇒ Git::CommandLineResult

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute git update-ref --stdin with instructions fed via stdin

Parameters:

  • instructions (Array<String>)

    one or more instruction lines written to stdin of the git update-ref process

    Each element is written as a separate line (or NUL-terminated record when z: true). The instruction format is documented in the git-update-ref man page.

  • options (Hash)

    command options

Options Hash (**options):

  • :m (String) — default: nil

    a reflog message for each update

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

    overwrite refs themselves rather than following symbolic refs

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

    use NUL-delimited input instead of newline-delimited

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

    allow individual updates to fail

    When set, each instruction is applied independently; failed instructions are reported but do not abort the remaining updates. System-level failures (I/O, memory) still abort all updates.

  • :timeout (Numeric) — default: nil

    abort the command after this many seconds

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (ArgumentError)

    if no instructions are provided

  • (Git::FailedError)

    if git exits with a non-zero exit status



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/git/commands/update_ref/batch.rb', line 119

def call(*, **)
  bound = args_definition.bind(*, **)
  validate_version!
  with_stdin(build_stdin(bound)) do |reader|
    result = @execution_context.command_capturing(
      *bound, in: reader, **bound.execution_options, raise_on_failure: false
    )
    validate_exit_status!(result)
    result
  end
end