update-ref: add --batch-updates flag for stdin mode

When updating multiple references through stdin, Git's update-ref
command normally aborts the entire transaction if any single update
fails. This atomic behavior prevents partial updates. Introduce a new
batch update system, where the updates the performed together similar
but individual updates are allowed to fail.

Add a new `--batch-updates` flag that allows the transaction to continue
even when individual reference updates fail. This flag can only be used
in `--stdin` mode and builds upon the batch update support added to the
refs subsystem in the previous commits. When enabled, failed updates are
reported in the following format:

  rejected SP (<old-oid> | <old-target>) SP (<new-oid> | <new-target>) SP <rejection-reason> LF

Update the documentation to reflect this change and also tests to cover
different scenarios where an update could be rejected.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Acked-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Karthik Nayak
2025-04-08 10:51:12 +02:00
committed by Junio C Hamano
parent 31726bb90d
commit 221e8fcb7f
3 changed files with 306 additions and 7 deletions

View File

@@ -7,8 +7,10 @@ git-update-ref - Update the object name stored in a ref safely
SYNOPSIS
--------
[verse]
'git update-ref' [-m <reason>] [--no-deref] (-d <ref> [<old-oid>] | [--create-reflog] <ref> <new-oid> [<old-oid>] | --stdin [-z])
[synopsis]
git update-ref [-m <reason>] [--no-deref] -d <ref> [<old-oid>]
git update-ref [-m <reason>] [--no-deref] [--create-reflog] <ref> <new-oid> [<old-oid>]
git update-ref [-m <reason>] [--no-deref] --stdin [-z] [--batch-updates]
DESCRIPTION
-----------
@@ -57,6 +59,14 @@ performs all modifications together. Specify commands of the form:
With `--create-reflog`, update-ref will create a reflog for each ref
even if one would not ordinarily be created.
With `--batch-updates`, update-ref executes the updates in a batch but allows
individual updates to fail due to invalid or incorrect user input, applying only
the successful updates. However, system-related errors—such as I/O failures or
memory issues—will result in a full failure of all batched updates. Any failed
updates will be reported in the following format:
rejected SP (<old-oid> | <old-target>) SP (<new-oid> | <new-target>) SP <rejection-reason> LF
Quote fields containing whitespace as if they were strings in C source
code; i.e., surrounded by double-quotes and with backslash escapes.
Use 40 "0" characters or the empty string to specify a zero value. To